Add --web and --tools to support other repo's.
[tools.git] / review-tools / gitaddrev
index f022326baa6028d0be0b173c3d2de84289d094d1..cf041d4bd78710520c4c15dab3c4bb4a1a49aa0b 100755 (executable)
@@ -21,6 +21,7 @@ my $num = 0;
 my $refuse = 0;
 my $prnum = 0;
 my $verbose = 0;
+my $WHAT = 'openssl';
 
 my $query = OpenSSL::Query->new();
 
@@ -30,14 +31,15 @@ my @unknown_reviewers;
 my $skip_reviewer;
 my $omccount = 0;
 sub try_add_reviewer {
-    my $id = shift;
+    my $id = lc(shift);
     my $rc = undef;
-    my $rev = $query->find_person_tag($id, 'rev');
+    my $id2 = $id =~ /^\@(.*)$/ ? { github => $1 } : $id;
+    my $rev = $query->find_person_tag($id2, 'rev');
     if ($rev) {
        my $cla = $query->has_cla($rev);
        if ($cla) {
            unless (grep {$_ eq $rev} @reviewers) {
-               $omccount++ if $query->is_member_of($id, 'omc');
+               $omccount++ if $query->is_member_of($id2, 'omc');
                push @reviewers, $rev;
            }
            $rc = $rev;
@@ -48,7 +50,7 @@ sub try_add_reviewer {
     } else {
        push @unknown_reviewers, $id
            unless grep {$_ eq $id} @unknown_reviewers;
-       unless ($query->has_cla($id)) {
+       unless ($id =~ m|^.+\@.*$| && $query->has_cla($id)) {
            push @nocla_reviewers, $id
                unless grep {$_ eq $id} @nocla_reviewers;
        }
@@ -56,9 +58,6 @@ sub try_add_reviewer {
     return $rc;
 }
 
-my @commit_message = map { (my $x = $_) =~ s|\R$||; $x } <STDIN>;
-my $trivial = !! grep(/^CLA:\s*Trivial\s*$/i, @commit_message);
-
 foreach (@ARGV) {
     if (/^--list$/) {
        my %list = ();
@@ -67,13 +66,17 @@ foreach (@ARGV) {
            my $rev = $query->find_person_tag($email_id, 'rev');
            my $omc = $query->is_member_of($email_id, 'omc');
            next unless $query->has_cla($rev);
-           my @ids = sort grep { $_ =~ m|^[a-z][-a-z]*$| } map {
-               if (ref($_) eq "HASH") {
-                   values %$_;
-               } else {
-                   $_;
-               }
-           } @$_;
+           next unless $query->is_member_of($email_id, 'commit') || $omc;
+           my @ids =
+               sort grep { $_ =~ /^[a-z]+$/ || $_ =~ /^\@(?:\w|\w-\w)+$/ }
+               map {
+                   if (ref($_) eq "HASH") {
+                       my %h = %$_;
+                       map { $_ eq "github" ? '@'.$h{$_} : $h{$_} } keys %h;
+                   } else {
+                       $_;
+                   }
+               } @$_;
            foreach (@ids) {
                $list{$_} = { tag => $rev, omc => $omc };
            }
@@ -97,9 +100,16 @@ foreach (@ARGV) {
        try_add_reviewer($1);
     } elsif (/^--verbose$/) {
        $verbose = 1;
+    } elsif (/^--web$/) {
+        $WHAT = 'web';
+    } elsif (/--tools$/) {
+        $WHAT = 'tools'
     }
 }
 
+my @commit_message = map { (my $x = $_) =~ s|\R$||; $x } <STDIN>;
+my $trivial = !! grep(/^CLA:\s*Trivial\s*$/i, @commit_message);
+
 # If the author is a registered committer, that identity passes as a reviewer
 # too.  There is a twist, though...  see next comment
 if (my $rev = try_add_reviewer($ENV{GIT_AUTHOR_EMAIL})) {
@@ -118,7 +128,7 @@ if (my $rev = try_add_reviewer($ENV{GIT_AUTHOR_EMAIL})) {
     # In case the author is unknown to our databases or is lacking a CLA,
     # we need to be extra careful to check if this is supposed to be a
     # trivial commit.
-    my $author = $ENV{GIT_AUTHOR_EMAIL};
+    my $author = lc($ENV{GIT_AUTHOR_EMAIL});
 
     # Note: it really should be enough to check if $author is unknown, since
     # the databases are supposed to be consistent with each other.  However,
@@ -184,13 +194,17 @@ my $last_is_rev = 0;
 foreach (@commit_message) {
     # Start each line with assuming it's not a reviewed-by line
     $last_is_rev = 0;
-    if (/^\(Merged from https:\/\/github\.com\/openssl\/openssl\/pull\//
-       || /^Reviewed-by:\s*(\S.*\S)\s*$/) {
+    if (/^\(Merged from https:\/\/github\.com\/openssl\/$WHAT\/pull\//) {
+        next if $rmrev == 1;
+        $last_is_rev = 1;
+        next;                  # Because we're rewriting it below
+                               # (unless --nopr was given in addrev)
+    } elsif (/^Reviewed-by:\s*(\S.*\S)\s*$/) {
         my $id = $1;
         next if $rmrev == 1;
         $last_is_rev = 1;
         # Remove reviewers that are already in the message from our reviewer list
-        @reviewers = grep { $_ ne $id } @reviewers if $id;
+        @reviewers = grep { $_ ne $id } @reviewers;
     }
     print $_,"\n";
 }
@@ -202,5 +216,5 @@ if ($rmrev == 0) {
     }
 }
 
-print "(Merged from https://github.com/openssl/openssl/pull/$prnum)\n"
+print "(Merged from https://github.com/openssl/$WHAT/pull/$prnum)\n"
     if $prnum;