From cbddd3a5a6c9022b456c0df0ae8cf30eddb8cde6 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Date: Thu, 12 Feb 2015 16:47:32 +0100 Subject: [PATCH] move the work-in-progress detection to the bot itself it obviously makes no sense when the sanitizer is executed locally. additionally, this allows us a different treatment of WIP reports: instead of giving a -2 sanity review, give a -2 code review. that way the change owner is not spammed by useless notifications (because the sanity review itself is positive, so the message is suppressed by the gerrit configuration). Change-Id: I10bc8f8f61673e75983dcb91310836d59c434483 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> --- git-hooks/gerrit-bot | 19 +++++++++++++++++-- git-hooks/git_post_commit_hook | 2 -- git-hooks/sanitize-commit | 5 +---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/git-hooks/gerrit-bot b/git-hooks/gerrit-bot index ef66fd1..6b4bb82 100755 --- a/git-hooks/gerrit-bot +++ b/git-hooks/gerrit-bot @@ -145,6 +145,7 @@ sub process_commit($$$$$) $project =~ s,/$,,; # XXX Workaround QTQAINFRA-381 my ($score, $verdict); my $message = ""; + my $iswip = 0; my @invite; my $use_rest = 0; if (defined($EXCLUDED_PROJECTS{$project}) || defined($EXCLUDED_PROJECTS{$project.":".$branch})) { @@ -184,14 +185,18 @@ sub process_commit($$$$$) $verbose and print "===== ".strftime("%c", localtime(time()))." ===== fetched change\n"; } + my $subject; + my @watches; for my $w (@WATCHES) { my $wp = $watch_projects{$w}; push @watches, $w if (!defined($wp) || $project =~ $wp); } if (@watches) { - my @touched = `git diff-tree --name-only --no-commit-id --ignore-submodules -r -C --root $rev`; + my @touched = `git show --pretty=\%s --name-only --ignore-submodules -C $rev`; chop(@touched); + $subject = shift @touched; + shift @touched; # empty line for my $w (@watches) { for my $file (@touched) { if ($file =~ $watch_files{$w}) { @@ -203,6 +208,15 @@ sub process_commit($$$$$) } } + if (!defined($subject)) { + $subject = `git show --pretty=\%s -s $rev`; + chop($subject); + } + if ($subject =~ /\b(?:WIP|Wip|wip(?!\/))\b|\*{3}|^(?:squash|fixup)! |^(.)\1*$/) { + $iswip = 1; + $message = "Apparently pushing a Work In Progress\n\n".$message; + } + my $worker = $WORKER; $worker =~ s/\@SHA1\@/$rev/g; open VERDICT, $worker." 2>&1 |" or die "cannot run worker: ".$!; @@ -223,7 +237,7 @@ sub process_commit($$$$$) $use_rest = 1; $verdict = decode_json($verdict); defined($verdict) or die "cannot decode verdict as JSON\n"; - $$verdict{labels} = { 'Sanity-Review' => $score }; + $$verdict{labels} = { 'Sanity-Review' => $score, 'Code-Review' => ($iswip ? -2 : 0) }; } } else { if (length($verdict) > 20000) { @@ -249,6 +263,7 @@ sub process_commit($$$$$) # push @args, ("--project", $project); push @args, ("--project", $orig_project); # XXX Workaround QTQAINFRA-381 push @args, ("--sanity-review", ($score > 0) ? "+".$score : $score); + push @args, ("--code-review", $iswip ? -2 : 0); if (length($verdict)) { $verdict =~ s/([\"\\\$\`])/\\$1/g; # ssh doesn`t properly quote the arguments for sh $verdict =~ s/^\s+|\s+$//g; diff --git a/git-hooks/git_post_commit_hook b/git-hooks/git_post_commit_hook index f4bd82a..6550d92 100755 --- a/git-hooks/git_post_commit_hook +++ b/git-hooks/git_post_commit_hook @@ -39,6 +39,4 @@ if test -L "$me"; then fi sha1=${1-HEAD} # just for debugging -GIT_PUSH=${GIT_PUSH+$GIT_PUSH,}wip # this check makes totally no sense locally -export GIT_PUSH exec `dirname "$me"`/sanitize-commit $sha1 strict >&2 diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit index a8fb5db..f27903f 100755 --- a/git-hooks/sanitize-commit +++ b/git-hooks/sanitize-commit @@ -106,7 +106,6 @@ use constant { my $clike = 0; my $qmake = 0; -my $iswip = defined($cfg{wip}); my $badrev = 0; my $badsign = 0; my $badid = defined($cfg{changeid}); @@ -287,9 +286,7 @@ while (<MSG>) { if (/\bQT[A-Z]+-\d+\b/) { complain_cln("Bug reference in summary", "log"); } - if (!$iswip && $parents < 2 && /\b(?:WIP|Wip|wip(?!\/))\b|\*{3}|^(?:squash|fixup)! |^(.)\1*$/) { - complain_cln("Apparently pushing a Work In Progress", "wip", 1); - } elsif (!$iswip && !$badlog && length($_) < 7) { + if (!$badlog && length($_) < 7) { complain_cln("Summary is too short", "log"); } elsif (!$badlog && !$revert1 && length($_) > 120) { complain_cln("Summary is excessively long", "log"); -- GitLab