]> Sergey Matveev's repositories - gerrvim.git/blob - gerrcommget.sh
Raise copyright years
[gerrvim.git] / gerrcommget.sh
1 #!/bin/sh
2 # gerrvim -- Gerrit review's comments preparation helper
3 # Copyright (C) 2015-2024 Sergey Matveev <stargrave@stargrave.org>
4 #
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.
8 #
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.
13 #
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/>.
16
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
22
23 change=$1
24 revision=$2
25
26 usage()
27 {
28     echo Usage: $0 CHANGE REVISION
29     exit 1
30 }
31
32 [ -n "$change" ] || usage
33 [ -n "$revision" ] || usage
34
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
39 my @ser = <STDIN>;
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};
48         $m =~ s/\\n/\n/g;
49         print "$m\n-----END-----\n\n";
50     };
51 };
52 '