]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Add the summary feature
authorDon Armstrong <don@donarmstrong.com>
Sat, 9 Aug 2008 21:02:03 +0000 (14:02 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sat, 9 Aug 2008 21:02:03 +0000 (14:02 -0700)
Debbugs/Control.pm
Debbugs/Status.pm
scripts/service
t/06_mail_handling.t

index 30a642b0bff22214fed508fa0423095e2a0f5dcf..81dd6219e6e501d8c3782161d6bbc2ab5bfdf45f 100644 (file)
@@ -78,7 +78,8 @@ BEGIN{
      $DEBUG = 0 unless defined $DEBUG;
 
      @EXPORT = ();
-     %EXPORT_TAGS = (owner   => [qw(owner)],
+     %EXPORT_TAGS = (summary => [qw(summary)],
+                    owner   => [qw(owner)],
                     archive => [qw(bug_archive bug_unarchive),
                                ],
                     log     => [qw(append_action_to_log),
@@ -184,6 +185,168 @@ my %append_action_options =
 #                  );
 # }
 
+=head1 SUMMARY FUNCTIONS
+
+=head2 summary
+
+     eval {
+           summary(bug          => $ref,
+                   transcript   => $transcript,
+                   ($dl > 0 ? (debug => $transcript):()),
+                   requester    => $header{from},
+                   request_addr => $controlrequestaddr,
+                   message      => \@log,
+                    affected_packages => \%affected_packages,
+                   recipients   => \%recipients,
+                   summary      => undef,
+                   );
+       };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to mark $ref with summary foo: $@";
+       }
+
+Handles all setting of summary fields
+
+If summary is undef, unsets the summary
+
+If summary is 0, sets the summary to the first paragraph contained in
+the message passed.
+
+If summary is numeric, sets the summary to the message specified.
+
+
+=cut
+
+
+sub summary {
+    my %param = validate_with(params => \@_,
+                             spec   => {bug => {type   => SCALAR,
+                                                regex  => qr/^\d+$/,
+                                               },
+                                        # specific options here
+                                        summary => {type => SCALAR|UNDEF,
+                                                    default => 0,
+                                                   },
+                                        %common_options,
+                                        %append_action_options,
+                                       },
+                            );
+    croak "summary must be numeric or undef" if
+        defined $param{summary} and not $param{summary} =~ /^\d+$/;
+    our $locks = 0;
+    $locks = 0;
+    local $SIG{__DIE__} = sub {
+       if ($locks) {
+           for (1..$locks) { unfilelock(); }
+           $locks = 0;
+       }
+    };
+    my ($debug,$transcript) = __handle_debug_transcript(%param);
+    my (@data);
+    ($locks, @data) = lock_read_all_merged_bugs($param{bug});
+    __handle_affected_packages(data => \@data,%param);
+    add_recipients(data => \@data,
+                  recipients => $param{recipients}
+                 );
+    # figure out the log that we're going to use
+    my $summary = '';
+    my $summary_msg = '';
+    my $action = '';
+    if (not defined $param{summary}) {
+        # do nothing
+        print {$debug} "Removing summary fields";
+        $action = 'Removed summary';
+    }
+    else {
+        my $log = [];
+        my @records = Debbugs::Log::read_log_records(bug_num => $param{bug});
+        if ($param{summary} == 0) {
+             $log = $param{log};
+             $summary_msg = @records + 1;
+        }
+        else {
+             if (($param{summary} - 1 ) > $#records) {
+                  die "Message number '$param{summary}' exceeds the maximum message '$#records'";
+             }
+             my $record = $records[($param{summary} - 1 )];
+             if ($record->{type} !~ /incoming-recv|recips/) {
+                  die "Message number '$param{summary}' is a invalid message type '$record->{type}'";
+             }
+             $summary_msg = $param{summary};
+             $log = [$record->{text}];
+        }
+        my $p_o = Debbugs::MIME::parse(join('',@{$log}));
+        my $body = $p_o->{body};
+        my $in_pseudoheaders = 0;
+        my $paragraph = '';
+        # walk through body until we get non-blank lines
+        for my $line (@{$body}) {
+             if ($line =~ /^\s*$/) {
+                  if (length $paragraph) {
+                       last;
+                  }
+                  $in_pseudoheaders = 0;
+                  next;
+             }
+             # skip a paragraph if it looks like it's control or
+             # pseudo-headers
+             if ($line =~ m{^\s*(?:(?:Package|Source|Version)\:| #pseudo headers
+                                (?:package|(?:no|)owner|severity|tag|summary| #control
+                                     reopen|close|(?:not|)(?:fixed|found)|clone|
+                                     (?:force|)merge|user(?:category|tag|)
+                                )
+                           )\s+\S}x) {
+                  if (not length $paragraph) {
+                       print {$debug} "Found control/pseudo-headers and skiping them\n";
+                       $in_pseudoheaders = 1;
+                       next;
+                  }
+             }
+             next if $in_pseudoheaders;
+             $paragraph .= $line;
+        }
+        print {$debug} "Summary is going to be '$paragraph'\n";
+        $summary = $paragraph;
+        $summary =~ s/[\n\r]//g;
+        if (not length $summary) {
+             die "Unable to find summary message to use";
+        }
+    }
+    for my $data (@data) {
+        print {$debug} "Going to change summary";
+        if (length $summary) {
+             if (length $data->{summary}) {
+                  $action = "Summary replaced with message bug $param{bug} message $summary_msg";
+             }
+             else {
+                  $action = "Summary recorded from message bug $param{bug} message $summary_msg";
+             }
+        }
+        $data->{summary} = $summary;
+        append_action_to_log(bug => $data->{bug_num},
+                             get_lock => 0,
+                             __return_append_to_log_options(
+                                                            %param,
+                                                            action => $action,
+                                                           ),
+                            )
+              if not exists $param{append_log} or $param{append_log};
+         writebug($data->{bug_num},$data);
+         print {$transcript} "$action\n";
+         add_recipients(data => $data,
+                        recipients => $param{recipients},
+                       );
+     }
+     if ($locks) {
+         for (1..$locks) { unfilelock(); }
+     }
+
+}
+
+
+
+
 =head1 OWNER FUNCTIONS
 
 =head2 owner
index 3b3961f90667ec7cbf654a371f49aa8d9399ad6d..0030a7ccda131d9f348816e51e3b4f34ff4049b2 100644 (file)
@@ -100,6 +100,8 @@ my %fields = (originator     => 'submitter',
               blocks         => 'blocks',
               blockedby      => 'blocked-by',
              unarchived     => 'unarchived',
+             summary        => 'summary',
+             affects        => 'affects',
              );
 
 # Fields which need to be RFC1522-decoded in format versions earlier than 3.
index df289c9c40406fa20a2df0c83547891c143693b8..da0819ac6e69da721b4f23487c4fd6b71506cbcf 100755 (executable)
@@ -29,7 +29,7 @@ use Debbugs::Versions::Dpkg;
 use Debbugs::Status qw(splitpackages);
 
 use Debbugs::CGI qw(html_escape);
-use Debbugs::Control qw(:archive :log :owner);
+use Debbugs::Control qw(:all);
 use Debbugs::Log qw(:misc);
 use Debbugs::Text qw(:templates);
 
@@ -1184,9 +1184,32 @@ END
                %limit_pkgs = ();
                print {$transcript} "Not ignoring any bugs.\n\n";
        }
+    } elsif (m/^summary\s+\#?(-?\d+)\s*(\d+|)\s*$/i) {
+       $ok++;
+        $ref = $1;
+       my $summary_msg = length($2)?$2:undef;
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
+       $bug_affected{$ref} = 1;
+       eval {
+           summary(bug          => $ref,
+                   transcript   => $transcript,
+                   ($dl > 0 ? (debug => $transcript):()),
+                   requester    => $header{from},
+                   request_addr => $controlrequestaddr,
+                   message      => \@log,
+                   recipients   => \%recipients,
+                   summary      => $summary_msg,
+                  );
+       };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to give $ref a summary: $@";
+       }
+
     } elsif (m/^owner\s+\#?(-?\d+)\s+((?:\S.*\S)|\!)\s*$/i) {
        $ok++;
         $ref = $1;
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
        my $newowner = $2;
        if ($newowner eq '!') {
            $newowner = $replyto;
@@ -1203,9 +1226,14 @@ END
                  owner        => $newowner,
                 );
        };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to mark $ref as having an owner: $@";
+       }
     } elsif (m/^noowner\s+\#?(-?\d+)\s*$/i) {
         $ok++;
         $ref = $1;
+       $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
        $bug_affected{$ref} = 1;
        eval {
            owner(bug          => $ref,
@@ -1225,6 +1253,7 @@ END
     } elsif (m/^unarchive\s+#?(\d+)$/i) {
         $ok++;
         $ref = $1;
+        $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
         $bug_affected{$ref} = 1;
         eval {
              bug_unarchive(bug        => $ref,
@@ -1243,6 +1272,7 @@ END
     } elsif (m/^archive\s+#?(\d+)$/i) {
         $ok++;
         $ref = $1;
+        $ref = $clonebugs{$ref} if exists $clonebugs{$ref};
         $bug_affected{$ref} = 1;
         eval {
              bug_archive(bug => $ref,
index ccf1ee7924e8abdfd0450bbe802b61431caf0855..b188a99e407a616c29075f96f4197be287d03430 100644 (file)
@@ -1,7 +1,7 @@
 # -*- mode: cperl;-*-
 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
 
-use Test::More tests => 66;
+use Test::More tests => 72;
 
 use warnings;
 use strict;
@@ -196,6 +196,16 @@ my @control_commands =
                       status_key => 'owner',
                       status_value => '',
                      },
+      summary      => {command => 'summary',
+                      value   => '5',
+                      status_key => 'summary',
+                      status_value => 'This is a silly bug',
+                     },
+      nosummary    => {command => 'summary',
+                      value   => '',
+                      status_key => 'summary',
+                      status_value => '',
+                     },
       close        => {command => 'close',
                       value   => '',
                       status_key => 'done',