2 # gerrvim -- Gerrit review's comments preparation helper
3 # Copyright (C) 2015-2024 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, version 3 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 [ -n "$PERL" ] || PERL=perl
18 [ -n "$CURL" ] || CURL=curl
19 [ -n "$GERRUSER" ] || GERRUSER=stargrave
20 [ -n "$GERRPASS" ] || GERRPASS=password
21 [ -n "$GERRADDR" ] || GERRADDR=http://gerrit.lan
28 echo Usage: $0 CHANGE REVISION
32 [ -n "$change" ] || usage
33 [ -n "$revision" ] || usage
35 $CURL --silent --user $GERRUSER:$GERRPASS \
36 $GERRADDR/changes/$change/revisions/$revision/comments |
37 $PERL -MEncode -MJSON -e '
38 <STDIN>; # Skip first Gerrit malformed JSON line
40 my $deser = decode_json join "", @ser;
41 foreach my $f (keys %{$deser}) {
42 foreach my $comment (@{$deser->{$f}}) {
43 print "-----BEGIN R$comment->{id} $f";
44 print " $comment->{range}->{start_line}";
45 print " $comment->{range}->{end_line}-----\n";
46 print "$comment->{author}->{name}:\n";
47 my $m = encode_utf8 $comment->{message};
49 print "$m\n-----END-----\n\n";