Index: trunk/tools/wikibugs/wikibugs |
— | — | @@ -7,7 +7,8 @@ |
8 | 8 | # Original version by Brion Vibber, 2004-08-02, 2004-08-10 and 2004-08-15 |
9 | 9 | # Entirely rewritten by Timwi, 2004-09-06 |
10 | 10 | # Some cleanups and fixes by AzaToth, 2006-12-20 |
11 | | -# The source code was originally edited on the Wikitech wiki at: |
| 11 | +# |
| 12 | +# The source code was originally edited on the Wikitech wiki at: |
12 | 13 | # http://wikitech.wikimedia.org/view/Wikibugs and finally migrated to |
13 | 14 | # the subversion repository in 2007. |
14 | 15 | |
— | — | @@ -18,52 +19,58 @@ |
19 | 20 | my $contents = <STDIN>; |
20 | 21 | my $output; |
21 | 22 | |
| 23 | +# Map each bugzilla severity to an IRC message with colors |
22 | 24 | my $shash = { |
23 | | - 'enhancement' => "\00315enhancement\003", |
24 | | - 'trivial' => 'trivial', |
25 | | - 'minor' => "minor", |
26 | | - 'normal' => "normal", |
27 | | - 'major' => "major", |
| 25 | + 'enhancement' |
| 26 | + => "\00315enhancement\003", |
| 27 | + 'trivial' => 'trivial', |
| 28 | + 'minor' => "minor", |
| 29 | + 'normal' => "normal", |
| 30 | + 'major' => "major", |
28 | 31 | 'critical' => "\00304CRIT\003", |
29 | | - 'blocker' => "\00304\002BLOCKER\002\003" |
| 32 | + 'blocker' => "\00304\002BLOCKER\002\003" |
30 | 33 | }; |
31 | 34 | |
| 35 | +# Map each bugzilla resolution status to an IRC message with colors |
32 | 36 | my $rhash = { |
33 | 37 | 'WORKSFORME' => "\00314(WFM)\003", |
34 | | - 'INVALID' => "\00314(INVALID)\003", |
35 | | - 'DUPLICATE' => "\00314(DUP)\003", |
36 | | - 'FIXED' => "\00303(FIXED)\003", |
37 | | - 'WONTFIX' => "\00303(WONTFIX)\003", |
38 | | - 'LATER' => "\00306(LATER)\003", |
39 | | - 'REMIND' => "\00306(REMIND)\003" |
| 38 | + 'INVALID' => "\00314(INVALID)\003", |
| 39 | + 'DUPLICATE' => "\00314(DUP)\003", |
| 40 | + 'FIXED' => "\00303(FIXED)\003", |
| 41 | + 'WONTFIX' => "\00303(WONTFIX)\003", |
| 42 | + 'LATER' => "\00306(LATER)\003", |
| 43 | + 'REMIND' => "\00306(REMIND)\003" |
40 | 44 | }; |
41 | 45 | |
| 46 | +# Parse a received email |
42 | 47 | use Email::MIME; |
43 | | - |
44 | 48 | my $mail = Email::MIME->new( $contents ); |
45 | 49 | |
46 | | -my $from = $mail->header( 'From' ); |
47 | | -my $body = $mail->body; |
| 50 | +my $from = $mail->header( 'From' ); |
| 51 | +my $body = $mail->body; |
48 | 52 | my $subject = $mail->header( 'Subject' ); |
49 | 53 | |
50 | 54 | # Check that the e-mail is from MediaZilla. |
| 55 | +# TODO exit early to avoid a level of indentation |
51 | 56 | if ($from =~ /^bugzilla-daemon/) { |
52 | 57 | |
53 | 58 | $/ = ""; |
54 | 59 | # Extract and remove the comment section. |
55 | 60 | my ($haschanges, $user); |
56 | 61 | my $comment = undef; |
| 62 | + |
57 | 63 | for ($body) { |
58 | 64 | # Attempt to grab the "real name". |
59 | 65 | if ( m{^--- Comment #\d+ from (.*) <\S+\@.*}m ) { |
60 | 66 | $haschanges = 1; |
61 | | - $user = $1; |
62 | | - $comment = 1; |
| 67 | + $user = $1; |
| 68 | + $comment = 1; |
63 | 69 | } |
| 70 | + |
64 | 71 | # Re-attempt to grab the "real name". |
65 | 72 | if ( m{^(.*) <\S+\@\S+> changed:$}m ) { |
66 | 73 | $haschanges = 1; |
67 | | - $user = $1 if !$user; |
| 74 | + $user = $1 if !$user; |
68 | 75 | } else { |
69 | 76 | # If "real name" isn't available and we didn't get a user from the |
70 | 77 | # comment header, just use the "X-Bugzilla-Who" header. |
— | — | @@ -74,10 +81,10 @@ |
75 | 82 | |
76 | 83 | my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' ); |
77 | 84 | |
78 | | - |
79 | 85 | # Check if this is a dependency e-mail. If so, ignore it. |
80 | 86 | # We have removed the comment section to prevent people from using |
81 | 87 | # this by adding the right text to a comment. |
| 88 | + # TODO move that check to the top to avoid a level of indentation |
82 | 89 | if ($body !~ /^Bug \d+ depends on bug \d+, which changed state/m) { |
83 | 90 | |
84 | 91 | my ($bug, $summary, $st); |
— | — | @@ -87,7 +94,8 @@ |
88 | 95 | ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003"); |
89 | 96 | } |
90 | 97 | |
91 | | - ## Set the URL to the URL found in the message body if available, else construct our own URL |
| 98 | + ## Set the URL to the URL found in the message body if available, |
| 99 | + ## else construct our own URL |
92 | 100 | my $url = |
93 | 101 | $body =~ /^(http.*\/)show_bug\.cgi\?id=(.*)$/m |
94 | 102 | ? "$1$2" # short URL! |
— | — | @@ -100,9 +108,10 @@ |
101 | 109 | $output = ""; |
102 | 110 | |
103 | 111 | if ($st eq "\00303(NEW)\003") { |
104 | | - my $product = $mail->header( 'X-Bugzilla-Product' ); |
| 112 | + my $product = $mail->header( 'X-Bugzilla-Product' ); |
105 | 113 | my $component = $mail->header( 'X-Bugzilla-Component' ); |
106 | | - my $severity = $mail->header( 'X-Bugzilla-Severity' ); |
| 114 | + my $severity = $mail->header( 'X-Bugzilla-Severity' ); |
| 115 | + |
107 | 116 | ## Doesn't seem to be sent as a header. |
108 | 117 | my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m; |
109 | 118 | |
— | — | @@ -128,13 +137,15 @@ |
129 | 138 | push @outputs, "$shash->{$1}\->$shash->{$2}"; |
130 | 139 | } |
131 | 140 | if ($body =~ /Keywords\|.*$/s) { |
132 | | - my @lines = split (/\n/, $&); |
133 | | - my $added = ''; |
| 141 | + my @lines = split (/\n/, $&); |
| 142 | + |
| 143 | + my $added = ''; |
134 | 144 | my $removed = ''; |
| 145 | + |
135 | 146 | foreach my $a ( @lines ) { |
136 | 147 | last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/; |
137 | 148 | $removed .= $2; |
138 | | - $added .= $3; |
| 149 | + $added .= $3; |
139 | 150 | } |
140 | 151 | push @outputs, join ' ', ( |
141 | 152 | ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, $removed)) : ''), |