Index: branches/overlordq/wikibugs |
— | — | @@ -0,0 +1,157 @@ |
| 2 | +#!/usr/bin/perl -w |
| 3 | + |
| 4 | +# Script to pull bug info from SourceForce and MediaZilla mails and dump them |
| 5 | +# to a log to be used for IRC bot. |
| 6 | + |
| 7 | +# Original version by Brion Vibber, 2004-08-02, 2004-08-10 and 2004-08-15 |
| 8 | +# Entirely rewritten by Timwi, 2004-09-06 |
| 9 | +# Some cleanups and fixes by AzaToth, 2006-12-20 |
| 10 | + |
| 11 | +use strict; |
| 12 | +use utf8; |
| 13 | + |
| 14 | +$/ = undef; |
| 15 | +my $contents = <STDIN>; |
| 16 | +my $output; |
| 17 | + |
| 18 | +my $shash = { |
| 19 | + 'enhancement' => "\00315enhancement\003", |
| 20 | + 'trivial' => 'trivial', |
| 21 | + 'minor' => "minor", |
| 22 | + 'normal' => "normal", |
| 23 | + 'major' => "major", |
| 24 | + 'critical' => "\00304CRIT\003", |
| 25 | + 'blocker' => "\00304\002BLOCKER\002\003" |
| 26 | +}; |
| 27 | + |
| 28 | +my $rhash = { |
| 29 | + 'WORKSFORME' => "\00314(WFM)\003", |
| 30 | + 'INVALID' => "\00314(INVALID)\003", |
| 31 | + 'DUPLICATE' => "\00314(DUP)\003", |
| 32 | + 'FIXED' => "\00303(FIXED)\003", |
| 33 | + 'WONTFIX' => "\00303(WONTFIX)\003", |
| 34 | + 'LATER' => "\00306(LATER)\003", |
| 35 | + 'REMIND' => "\00306(REMIND)\003" |
| 36 | +}; |
| 37 | + |
| 38 | +use Email::MIME; |
| 39 | + |
| 40 | +my $mail = Email::MIME->new( $contents ); |
| 41 | + |
| 42 | +my $from = $mail->header( 'From' ); |
| 43 | +my $body = $mail->body; |
| 44 | +my $subject = $mail->header( 'Subject' ); |
| 45 | + |
| 46 | +if ($from =~ /^bugzilla-daemon/) |
| 47 | +{ |
| 48 | + # E-mail is from MediaZilla |
| 49 | + |
| 50 | + $/ = ""; |
| 51 | + # extract and remove the comment section |
| 52 | + my ($haschanges, $user); |
| 53 | + my $comment = $body =~ s/^--- Comment #\d+ from (?-s:.*?<)?(\S+)\@.*//ms; |
| 54 | + if($comment) { |
| 55 | + $user = $1; |
| 56 | + } else { |
| 57 | + $user = 'N/A' # shouldn't be possible' |
| 58 | + } |
| 59 | + |
| 60 | + my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' ); |
| 61 | + |
| 62 | + |
| 63 | + # Check if this is a dependency e-mail. If so, ignore it. |
| 64 | + # We have removed the comment section to prevent people from using |
| 65 | + # this by adding the right text to a comment. |
| 66 | + if ($body !~ /^Bug \d+ depends on bug \d+, which changed state/m) |
| 67 | + { |
| 68 | + |
| 69 | + my ($bug, $summary, $st); |
| 70 | + if ($subject =~ /\[Bug (\d+)\]\s+New:\s+(.*)/s) { |
| 71 | + ($bug, $summary, $st) = ($1, $2, "\00303(NEW)\003"); |
| 72 | + } elsif ($subject =~ /\[Bug (\d+)\]\s(.*)/s) { |
| 73 | + ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003"); |
| 74 | + } |
| 75 | + |
| 76 | + ## Set the URL to the URL found in the message body if available, else construct our own URL |
| 77 | + my $url = |
| 78 | + $body =~ /^http.*show_bug\.cgi.*$/m |
| 79 | + ? $& |
| 80 | + : "http://bugzilla.wikimedia.org/show_bug.cgi?id=$bug"; |
| 81 | + |
| 82 | + $summary =~ s/\s+/ /g; |
| 83 | + |
| 84 | + # We are going to append stuff to the beginning of $output later. |
| 85 | + # This stuff is going to contain $st. But we want a chance of changing it first. |
| 86 | + $output = ""; |
| 87 | + |
| 88 | + if ($st eq "\00303(NEW)\003") |
| 89 | + { |
| 90 | + my $product = $mail->header( 'X-Bugzilla-Product' ); |
| 91 | + my $component = $mail->header( 'X-Bugzilla-Component' ); |
| 92 | + my $severity = $mail->header( 'X-Bugzilla-Severity' ); |
| 93 | + ## Doesn't seem to be sent as a header. |
| 94 | + my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m; |
| 95 | + |
| 96 | + $output .= "$severity; \002$product\002\: $component; (\002$reporter\002)\n"; |
| 97 | + } |
| 98 | + else |
| 99 | + { |
| 100 | + ($haschanges, $user) = (1, $1) if $contents =~ /^(?:.*<)?(\S+)\@\S+>? changed:$/m; |
| 101 | + |
| 102 | + if ($haschanges) { |
| 103 | + my @outputs; |
| 104 | + my $status = $mail->header( 'X-Bugzilla-Status' ); |
| 105 | + if ($status eq 'NEW') { |
| 106 | + $st = "\00303(mod)\003"; |
| 107 | + } elsif ($status eq 'REOPENED' && grep {$_ eq 'Status'} @changed_fields) { |
| 108 | + $st = "\00304(REOPENED)\003"; |
| 109 | + } elsif ( grep {$_ eq 'Status'} @changed_fields ) { |
| 110 | + $st = "\00303($status)\003"; |
| 111 | + } else { |
| 112 | + $st = "\00303(mod)\003"; |
| 113 | + } |
| 114 | + |
| 115 | + if ($st eq "\00303(RESOLVED)\003" && $body =~ /Resolution\|\s+\|(\w+)/m) { |
| 116 | + $st = $rhash->{$1}; |
| 117 | + } |
| 118 | + if ($body =~ /Severity\|(\w+)\s+\|(\w+)/m) { |
| 119 | + push @outputs, "$shash->{$1}\->$shash->{$2}"; |
| 120 | + } |
| 121 | + if ($body =~ /Keywords\|.*$/s) { |
| 122 | + my @lines = split (/\n/, $&); |
| 123 | + my $added = ''; |
| 124 | + my $removed = ''; |
| 125 | + foreach my $a ( @lines ) |
| 126 | + { |
| 127 | + last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/; |
| 128 | + $removed .= $2; |
| 129 | + $added .= $3; |
| 130 | + } |
| 131 | + push @outputs, join ' ', ( |
| 132 | + ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, $removed)) : ''), |
| 133 | + ($added =~ /\S/ ? join (' ', map { "+$_" } split (/\s*,\s*/, $added )) : '') |
| 134 | + ); |
| 135 | + } |
| 136 | + |
| 137 | + push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/; |
| 138 | + |
| 139 | + push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m; |
| 140 | + |
| 141 | + push @outputs, "+comment" if $comment; |
| 142 | + |
| 143 | + $output .= " " . join ('; ', @outputs) if @outputs; |
| 144 | + |
| 145 | + } |
| 146 | + $output .= " (\002\00310$user\003\002)\n"; |
| 147 | + } |
| 148 | + $output = "$st $summary - \00310$url\003 " . $output; |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +if ($output) |
| 153 | +{ |
| 154 | + open (OUT, ">>/var/wikibugs/wikibugs.log"); |
| 155 | +# print $output; |
| 156 | + print OUT $output; |
| 157 | + close OUT; |
| 158 | +} |
Property changes on: branches/overlordq/wikibugs |
___________________________________________________________________ |
Added: svn:executable |
1 | 159 | + * |