2 # gerrvim -- Gerrit review's comments preparation helper
3 # Copyright (C) 2015 Sergey Matveev <stargrave@stargrave.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 [ -n "$PERL" ] || PERL=perl
19 [ -n "$CURL" ] || CURL=curl
20 [ -n "$GERRUSER" ] || GERRUSER=stargrave
21 [ -n "$GERRPASS" ] || GERRPASS=password
22 [ -n "$GERRADDR" ] || GERRADDR=http://gerrit.lan
29 echo Usage: $0 CHANGE REVISION
33 [ -n "$change" ] || usage
34 [ -n "$revision" ] || usage
36 $CURL --silent --user $GERRUSER:$GERRPASS \
37 $GERRADDR/changes/$change/revisions/$revision/comments |
38 $PERL -MEncode -MJSON -e '
39 <STDIN>; # Skip first Gerrit malformed JSON line
41 my $deser = decode_json join "", @ser;
42 foreach my $f (keys %{$deser}) {
43 foreach my $comment (@{$deser->{$f}}) {
44 print "-----BEGIN R$comment->{id} $f";
45 print " $comment->{range}->{start_line}";
46 print " $comment->{range}->{end_line}-----\n";
47 print "$comment->{author}->{name}:\n";
48 my $m = encode_utf8 $comment->{message};
50 print "$m\n-----END-----\n\n";