#!/bin/sh # gerrvim -- Gerrit review's comments preparation helper # Copyright (C) 2015-2024 Sergey Matveev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . [ -n "$PERL" ] || PERL=perl [ -n "$CURL" ] || CURL=curl [ -n "$GERRUSER" ] || GERRUSER=stargrave [ -n "$GERRPASS" ] || GERRPASS=password [ -n "$GERRADDR" ] || GERRADDR=http://gerrit.lan change=$1 revision=$2 usage() { echo Usage: $0 CHANGE REVISION exit 1 } [ -n "$change" ] || usage [ -n "$revision" ] || usage $CURL --silent --user $GERRUSER:$GERRPASS \ $GERRADDR/changes/$change/revisions/$revision/comments | $PERL -MEncode -MJSON -e ' ; # Skip first Gerrit malformed JSON line my @ser = ; my $deser = decode_json join "", @ser; foreach my $f (keys %{$deser}) { foreach my $comment (@{$deser->{$f}}) { print "-----BEGIN R$comment->{id} $f"; print " $comment->{range}->{start_line}"; print " $comment->{range}->{end_line}-----\n"; print "$comment->{author}->{name}:\n"; my $m = encode_utf8 $comment->{message}; $m =~ s/\\n/\n/g; print "$m\n-----END-----\n\n"; }; }; '