]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/service.in
add fixed and notfixed commands
[debbugs.git] / scripts / service.in
index 3a7c07acc95890950d51b39cf695b7d3f693b385..d4e8e98ed6d066bab95db98f659567d0f40a6c1b 100755 (executable)
@@ -9,11 +9,11 @@ use MIME::Parser;
 use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
 use Debbugs::Mail qw(send_mail_message);
 use Debbugs::User;
+use HTML::Entities qw(encode_entities);
 
-$config_path = '/etc/debbugs';
-$lib_path = '/usr/lib/debbugs';
-
-require "$config_path/config";
+use Debbugs::Config qw(:globals :config);
+use Debbugs::CGI qw(html_escape);
+$lib_path = $gLibPath;
 require "$lib_path/errorlib";
 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
 
@@ -121,6 +121,8 @@ if ( defined($header{'reply-to'}) && $header{'reply-to'} ne "" ) {
     $replyto = $header{'from'};
 }
 
+# This is an error counter which should be incremented every time there is an error.
+my $errors = 0;
 $controlrequestaddr= $control ? "control\@$gEmailDomain" : "request\@$gEmailDomain";
 $transcript='';
 &transcript("Processing commands for $controlrequestaddr:\n\n");
@@ -168,7 +170,7 @@ for ($procline=0; $procline<=$#bodylines; $procline++) {
     &transcript("> $_\n");
     next if m/^\s*\#/;
     $action= '';
-    if (m/^stop/i || m/^quit/i || m/^--/ || m/^thank/i || m/^kthxbye/i) {
+    if (m/^stop\s*$/i || m/^quit\s*$/i || m/^--\s*$/ || m/^thank(?:s|\s*you)?\s*$/i || m/^kthxbye\s*$/i) {
        &transcript("Stopping processing here.\n\n");
         last;
     } elsif (m/^debug\s+(\d+)$/i && $1 >= 0 && $1 <= 1000) {
@@ -183,12 +185,15 @@ for ($procline=0; $procline<=$#bodylines; $procline++) {
                     "detailed logs for $gBug#$ref");
     } elsif (m/^index(\s+full)?$/i) {
        &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $errors++;
        $ok++; # well, it's not really ok, but it fixes #81224 :)
     } elsif (m/^index-summary\s+by-package$/i) {
        &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $errors++;
        $ok++; # well, it's not really ok, but it fixes #81224 :)
     } elsif (m/^index-summary(\s+by-number)?$/i) {
        &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $errors++;
        $ok++; # well, it's not really ok, but it fixes #81224 :)
     } elsif (m/^index(\s+|-)pack(age)?s?$/i) {
        &sendlynxdoc("pkgindex.cgi?indexon=pkg",'index of packages');
@@ -206,12 +211,15 @@ for ($procline=0; $procline<=$#bodylines; $procline++) {
         $ok++;
     } elsif (m/^send-unmatched(\s+this|\s+-?0)?$/i) {
        &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $errors++;
        $ok++; # well, it's not really ok, but it fixes #81224 :)
     } elsif (m/^send-unmatched\s+(last|-1)$/i) {
        &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $errors++;
        $ok++; # well, it's not really ok, but it fixes #81224 :)
     } elsif (m/^send-unmatched\s+(old|-2)$/i) {
        &transcript("This BTS function is currently disabled, sorry.\n\n");
+       $errors++;
        $ok++; # well, it's not really ok, but it fixes #81224 :)
     } elsif (m/^getinfo\s+([\w-.]+)$/i) {
         # the following is basically a Debian-specific kludge, but who cares
@@ -252,6 +260,7 @@ END
            $user = $newuser;
        } else {
            &transcript("Selected user id ($newuser) invalid, sorry\n");
+           $errors++;
            $user = "";
        }
     } elsif (m/^usercategory\s+(\S+)(\s+\[hidden\])?\s*$/i) {
@@ -273,6 +282,7 @@ END
             my ($o, $txt) = ($1, $2);
             if ($#cats == -1 && $o eq "+") {
                 &transcript("User defined category specification must start with a category name. Skipping.\n\n");
+               $errors++;
                 $bad = 1;
                 next;
             }
@@ -291,6 +301,7 @@ END
                     $desc = ""; $op = $1;
                 } else {
                     &transcript("Unrecognised syntax for category section. Skipping.\n\n");
+                   $errors++;
                     $bad = 1;
                     next;
                 }
@@ -332,9 +343,14 @@ END
     } elsif (m/^usertags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) {
        $ok++;
        $ref = $1; $addsubcode = $3 || "+"; $tags = $4;
+       if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+            $ref = $clonebugs{$ref};
+        }
        if ($user eq "") {
            &transcript("No valid user selected\n");
-       } else {
+           $errors++;
+        } elsif (&setbug) {
+           &nochangebug;
            my %ut;
            Debbugs::User::read_usertags(\%ut, $user);
             my @oldtags = (); my @newtags = (); my @badtags = ();
@@ -348,6 +364,7 @@ END
            }
            if (@badtags) {
                 &transcript("Ignoring illegal tag/s: ".join(', ', @badtags).".\nPlease use only alphanumerics, at, dot, plus and dash.\n");
+               $errors++;
            }
             for my $t (keys %chtags) {
                $ut{$t} = [] unless defined $ut{$t};
@@ -377,6 +394,7 @@ Unknown command or malformed arguments to command.
 (Use control\@$gEmailDomain to manipulate reports.)
 
 END
+       $errors++;
         if (++$unknowns >= 3) {
             &transcript("Too many unknown commands, stopping here.\n\n");
             last;
@@ -472,7 +490,7 @@ END
        $bug_affected{$ref}=1;
         if (&setbug) {
             if (@{$data->{fixed_versions}}) {
-                &transcript("'reopen' is deprecated when a bug has been closed with a version;\nuse 'found' or 'submitter' as appropriate instead.\n");
+                &transcript("'reopen' may be inappropriate when a bug has been closed with a version;\nyou may need to use 'found' to remove fixed versions.\n");
             }
             if (!length($data->{done})) {
                 &transcript("$gBug is already open, cannot reopen.\n\n");
@@ -489,13 +507,16 @@ END
                 } while (&getnextbug);
             }
         }
-    } elsif (m/^found\s+\#?(-?\d+)(?:\s+(\d.*))?$/i) {
+    } elsif (m{^found\s+\#?(-?\d+)
+              (?:\s+(?:$config{package_name_re}\/)?
+                   ($config{package_version_re}))?$}ix) {
         $ok++;
         $ref= $1;
         $version= $2;
         if (&setbug) {
             if (!length($data->{done}) and not defined($version)) {
                 &transcript("$gBug is already open, cannot reopen.\n\n");
+               $errors++;
                 &nochangebug;
             } else {
                 $action=
@@ -513,8 +534,7 @@ END
                     # equates to the most recent fixing of the bug, or when
                     # a versionless found command is received.
                     if (defined $version) {
-                        my $lastfixed =
-                            (reverse @{$data->{fixed_versions}})[0];
+                        my $lastfixed = $data->{fixed_versions}[-1];
                         # TODO: what if $data->{package} is a source package?
                         addfoundversions($data, $data->{package}, $version, 'binary');
                         if (defined $lastfixed and not grep { $_ eq $lastfixed } @{$data->{fixed_versions}}) {
@@ -542,8 +562,43 @@ END
                 &addmaintainers($data);
                 removefoundversions($data, $data->{package}, $version, 'binary');
             } while (&getnextbug);
-        }
-    } elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
+       }
+   }
+    elsif (m[^fixed\s+\#?(-?\d+)\s+
+            ((?:$config{package_name_re}\/)?
+                 $config{package_version_re})\s*$]ix) {
+        $ok++;
+        $ref= $1;
+        $version= $2;
+        if (&setbug) {
+            $action=
+                 defined($version) ?
+                      "$gBug marked as fixed in version $version." :
+                           "$gBug reopened.";
+                do {
+                    &addmaintainers($data);
+                    addfixedversions($data, $data->{package}, $version, 'binary');
+              } while (&getnextbug);
+       }
+   }
+    elsif (m[^notfixed\s+\#?(-?\d+)\s+
+            ((?:$config{package_name_re}\/)?
+                 $config{package_version_re})\s*$]ix) {
+        $ok++;
+        $ref= $1;
+        $version= $2;
+        if (&setbug) {
+            $action=
+                 defined($version) ?
+                      "$gBug marked as not fixed in version $version." :
+                           "$gBug reopened.";
+                do {
+                    &addmaintainers($data);
+                    removefixedversions($data, $data->{package}, $version, 'binary');
+              } while (&getnextbug);
+       }
+   }
+    elsif (m/^submitter\s+\#?(-?\d+)\s+\!$/i ? ($newsubmitter=$replyto, 1) :
              m/^submitter\s+\#?(-?\d+)\s+(\S.*\S)$/i ? ($newsubmitter=$2, 1) : 0) {
         $ok++;
         $ref= $1;
@@ -645,9 +700,11 @@ END
         if (!grep($_ eq $newseverity, @gSeverityList, "$gDefaultSeverity")) {
             &transcript("Severity level \`$newseverity' is not known.\n".
                        "Recognized are: $gShowSeverities.\n\n");
+           $errors++;
         } elsif (exists $gObsoleteSeverities{$newseverity}) {
             &transcript("Severity level \`$newseverity' is obsolete. " .
-                        "$gObsoleteSeverities{$newseverity}\n\n");
+                        "Use $gObsoleteSeverities{$newseverity} instead.\n\n");
+               $errors++;
         } elsif (&setbug) {
             $printseverity= $data->{severity};
             $printseverity= "$gDefaultSeverity" if $printseverity eq '';
@@ -682,6 +739,7 @@ END
        if (@badtags) {
             &transcript("Unknown tag/s: ".join(', ', @badtags).".\n".
                        "Recognized are: ".join(' ', @gTags).".\n\n");
+           $errors++;
        }
        if (&setbug) {
            if ($data->{keywords} eq '') {
@@ -720,15 +778,22 @@ END
        my $bugnum = $2; my $blockers = $4;
        $addsub = "add";
        $addsub = "sub" if ($1 eq "un");
-       
+       if ($bugnum =~ m/^-\d+$/ && defined $clonebugs{$bugnum}) {
+            $bugnum = $clonebugs{$bugnum};
+       }
+
        my @okayblockers;
        my @badblockers;
        foreach my $b (split /[\s,]+/, $blockers) {
            $b=~s/^\#//;
            if ($b=~/[0-9]+/) {
                $ref=$b;
+               if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+                    $ref = $clonebugs{$ref};
+               }
                if (&getbug) {
-                   push @okayblockers, $b;
+                   &foundbug;
+                   push @okayblockers, $ref;
 
                    # add to the list all bugs that are merged with $b,
                    # because all of their data must be kept in sync
@@ -744,7 +809,7 @@ END
                }
                else {
                    &notfoundbug;
-                    push @badblockers, $b;
+                    push @badblockers, $ref;
                }
            }
            else {
@@ -753,6 +818,7 @@ END
        }
        if (@badblockers) {
             &transcript("Unknown blocking bug/s: ".join(', ', @badblockers).".\n");
+           $errors++;
        }
        
        $ref=$bugnum;
@@ -763,11 +829,11 @@ END
                &transcript("Was blocked by: $data->{blockedby}\n");
            }
            if ($addsub eq "set") {
-               $action= "Blocking bugs set to: " . join(", ", @okayblockers);
+               $action= "Blocking bugs of $bugnum set to: " . join(", ", @okayblockers);
            } elsif ($addsub eq "add") {
-               $action= "Blocking bugs added: " . join(", ", @okayblockers);
+               $action= "Blocking bugs of $bugnum added: " . join(", ", @okayblockers);
            } elsif ($addsub eq "sub") {
-               $action= "Blocking bugs removed: " . join(", ", @okayblockers);
+               $action= "Blocking bugs of $bugnum removed: " . join(", ", @okayblockers);
            }
            my %removedblocks;
            my %addedblocks;
@@ -822,8 +888,9 @@ END
             if (&checkpkglimit) {
                 &foundbug;
                 &addmaintainers($data);
+               my $oldtitle = $data->{subject};
                 $data->{subject}= $newtitle;
-                $action= "Changed $gBug title.";
+                $action= "Changed $gBug title to $newtitle from $oldtitle.";
                 &savebug;
                 &transcript("$action\n");
                 if (length($data->{done})) {
@@ -877,20 +944,21 @@ END
             &foundbug;
             &transcript("D| adding $ref ($data->{mergedwith})\n") if $dl;
            $mismatch= '';
-           &checkmatch('package','m_package',$data->{package});
-           &checkmatch('forwarded addr','m_forwarded',$data->{forwarded});
+           &checkmatch('package','m_package',$data->{package},@newmergelist);
+           &checkmatch('forwarded addr','m_forwarded',$data->{forwarded},@newmergelist);
            $data->{severity} = '$gDefaultSeverity' if $data->{severity} eq '';
-           &checkmatch('severity','m_severity',$data->{severity});
-           &checkmatch('blocks','m_blocks',$data->{blocks});
-           &checkmatch('blocked-by','m_blockedby',$data->{blockedby});
-           &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open');
-           &checkmatch('owner','m_owner',$data->{owner});
+           &checkmatch('severity','m_severity',$data->{severity},@newmergelist);
+           &checkmatch('blocks','m_blocks',$data->{blocks},@newmergelist);
+           &checkmatch('blocked-by','m_blockedby',$data->{blockedby},@newmergelist);
+           &checkmatch('done mark','m_done',length($data->{done}) ? 'done' : 'open',@newmergelist);
+           &checkmatch('owner','m_owner',$data->{owner},@newmergelist);
            foreach my $t (split /\s+/, $data->{keywords}) { $tags{$t} = 1; }
            foreach my $f (@{$data->{found_versions}}) { $found{$f} = 1; }
            foreach my $f (@{$data->{fixed_versions}}) { $fixed{$f} = 1; }
            if (length($mismatch)) {
                &transcript("Mismatch - only $gBugs in same state can be merged:\n".
                             $mismatch."\n");
+               $errors++;
                &cancelbug; @newmergelist=(); last;
            }
             push(@newmergelist,$ref);
@@ -916,10 +984,11 @@ END
         &endmerge;
     } elsif (m/^forcemerge\s+\#?(-?\d+(?:\s+\#?-?\d+)+)\s*$/i) {
        $ok++;
-       my @tomerge = split /\s+\#?/,$1;
-       my $master_bug = shift @tomerge;
+       my @temp = split /\s+\#?/,$1;
+       my $master_bug = shift @temp;
        my $master_bug_data;
-       @tomerge = ($master_bug, sort { $a <=> $b } @tomerge);
+       my @tomerge = sort { $a <=> $b } @temp;
+        unshift @tomerge,$master_bug;
        &transcript("D| force merging ".join(',',@tomerge)."\n") if $dl;
        my @newmergelist= ();
        my %tags = ();
@@ -945,6 +1014,7 @@ END
            if ($data->{package} ne $master_bug_data->{package}) {
                &transcript("Mismatch - only $gBugs in the same package can be forcibly merged:\n".
                            "$gBug $ref is not in the same package as $master_bug\n");
+               $errors++;
                &cancelbug; @newmergelist=(); last;
            }
            for my $t (split /\s+/,$data->{keywords}) {
@@ -986,7 +1056,8 @@ END
        $bug_affected{$ref} = 1;
        if (&setbug) {
            if (length($data->{mergedwith})) {
-               &transcript("$gBug is marked as being merged with others.\n\n");
+               &transcript("$gBug is marked as being merged with others. Use an existing clone.\n\n");
+               $errors++;
                &nochangebug;
            } else {
                &filelock("nextnumber.lock");
@@ -1038,7 +1109,7 @@ END
                }
            }
        }
-    } elsif (m/^package\s+(\S.*\S)?\s*$/i) {
+    } elsif (m/^package\:?\s+(\S.*\S)?\s*$/i) {
         $ok++;
        my @pkgs = split /\s+/, $1;
        if (scalar(@pkgs) > 0) {
@@ -1088,6 +1159,7 @@ END
         }
     } else {
         &transcript("Unknown command or malformed arguments to command.\n\n");
+       $errors++;
         if (++$unknowns >= 5) {
             &transcript("Too many unknown commands, stopping here.\n\n");
             last;
@@ -1098,6 +1170,7 @@ if ($procline>$#bodylines) {
     &transcript(">\nEnd of message, stopping processing here.\n\n");
 }
 if (!$ok && !quickabort) {
+    $errors++;
     &transcript("No commands successfully parsed; sending the help text(s).\n");
     &sendhelp;
     &transcript("\n");
@@ -1138,10 +1211,13 @@ if (!defined $header{'subject'} || $header{'subject'} eq "") {
   $header{'subject'} = "your mail";
 }
 
+# Error text here advertises how many errors there were
+my $error_text = $errors > 0 ? " (with $errors errors)":'';
+
 $reply= <<END;
 From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $replyto
-${maintccs}Subject: Processed: $header{'subject'}
+${maintccs}Subject: Processed${error_text}: $header{'subject'}
 In-Reply-To: $header{'message-id'}
 References: $header{'message-id'}
 Message-ID: <handler.s.$nn.transcript\@$gEmailDomain>
@@ -1162,8 +1238,8 @@ print(AP
       "\2\n$repliedshow\n\5\n$reply\n\3\n".
       "\6\n".
       "<strong>Request received</strong> from <code>".
-      &sani($header{'from'})."</code>\n".
-      "to <code>".&sani($controlrequestaddr)."</code>\n".
+      html_escape($header{'from'})."</code>\n".
+      "to <code>".html_escape($controlrequestaddr)."</code>\n".
       "\3\n".
       "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/-1.log: $!");
 close(AP) || &quit("open db-h/-1.log: $!");
@@ -1194,7 +1270,7 @@ sub sendhelp {
 #}
 
 sub checkmatch {
-    local ($string,$mvarname,$svarvalue) = @_;
+    local ($string,$mvarname,$svarvalue,@newmergelist) = @_;
     local ($mvarvalue);
     if (@newmergelist) {
         eval "\$mvarvalue= \$$mvarname";
@@ -1215,6 +1291,7 @@ sub checkmatch {
 sub checkpkglimit {
     if (keys %limit_pkgs and not defined $limit_pkgs{$data->{package}}) {
         &transcript("$gBug number $ref belongs to package $data->{package}, skipping.\n\n");
+        $errors++;
         return 0;
     }
     return 1;
@@ -1343,7 +1420,7 @@ sub getnextbug {
 #    &transcript("$action\n\n")
 #    endmerge
 
-sub notfoundbug { &transcript("$gBug number $ref not found.\n\n"); }
+sub notfoundbug { &transcript("$gBug number $ref not found. (Is it archived?)\n\n"); }
 sub foundbug { &transcript("$gBug#$ref: $data->{subject}\n"); }
 
 sub getmerge {
@@ -1394,9 +1471,10 @@ sub savebug {
     open(L,">>db-h/$hash/$ref.log") || &quit("opening db-h/$hash/$ref.log: $!");
     print(L
           "\6\n".
-          "<strong>".&sani($action)."</strong>\n".
-          "Request was from <code>".&sani($header{'from'})."</code>\n".
-          "to <code>".&sani($controlrequestaddr)."</code>. \n".
+         "<!-- time:".time." -->\n".
+          "<strong>".html_escape($action)."</strong>\n".
+          "Request was from <code>".html_escape($header{'from'})."</code>\n".
+          "to <code>".html_escape($controlrequestaddr)."</code>. \n".
           "\3\n".
           "\7\n",@{escapelog(@log)},"\n\3\n") || &quit("writing db-h/$hash/$ref.log: $!");
     close(L) || &quit("closing db-h/$hash/$ref.log: $!");