From: Sergey Matveev Date: Fri, 17 Jul 2015 20:47:26 +0000 (+0300) Subject: Comments getter and converter to Gerrvim format utility X-Git-Tag: 0.1~2 X-Git-Url: http://www.git.stargrave.org/?p=gerrvim.git;a=commitdiff_plain;h=d51e560d3e82ab7aa7d615e031ed01a9bae10775 Comments getter and converter to Gerrvim format utility --- diff --git a/gerrcommget.sh b/gerrcommget.sh new file mode 100755 index 0000000..2b96bd2 --- /dev/null +++ b/gerrcommget.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# gerrvim -- Gerrit review's comments preparation helper +# Copyright (C) 2015 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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"; + }; +}; +'