diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2018-01-08 16:03:29 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2018-01-09 12:15:36 +0000 |
commit | 21ec987901a927793d7baa9db3fd37d0216aef06 (patch) | |
tree | 7105508ae89d5f0961df36a62d03098c488af030 | |
parent | 07f8dbb095e4905d2d43e1527ce5616d047a3ae9 (diff) |
gerrit-bot: Validate change status on move
Change-Id: Ideca76f81632a4d886193b8a8529aa9682b84066
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
-rwxr-xr-x | git-hooks/gerrit-bot | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/git-hooks/gerrit-bot b/git-hooks/gerrit-bot index 8a78b7b..a659c73 100755 --- a/git-hooks/gerrit-bot +++ b/git-hooks/gerrit-bot @@ -247,19 +247,22 @@ sub do_move($$$) if ($target eq $branch) { return "The change already targets $branch"; } + my %allowed_status = ('NEW' => 1, 'DEFERRED' => 1, 'DRAFT' => 1, 'ABANDONED' => 1); + my $status = $$chg{'status'}; + return "$status changes cannot be moved" if (!$allowed_status[$status]); my $project = $$chg{'project'}; my $id = $$chg{'id'}; # First, check there's no such review on that branch already my $query = "project:$project change:$id branch:$target"; - open(my $status, "-|", @gerrit, "query", "--format", "JSON", $query) or die "cannot run ssh: ".$!; - while (<$status>) { + open(my $qry, "-|", @gerrit, "query", "--format", "JSON", $query) or die "cannot run ssh: ".$!; + while (<$qry>) { my $review = decode_json($_); defined($review) or die "cannot decode JSON string '".chomp($_)."'\n"; if (my $url = $$review{'url'}) { return "Cannot move: Conflicting change $url - please ask a Gerrit admin for help."; } } - close $status; + close $qry; # Only allow the change owner to execute move if ($$author{'username'} ne $$chg{'owner'}{'username'}) { return "Only the owner is allowed to move a change"; |