Index: trunk/tools/wikibugs/wikibugs |
— | — | @@ -51,122 +51,122 @@ |
52 | 52 | my $subject = $mail->header( 'Subject' ); |
53 | 53 | |
54 | 54 | # Check that the e-mail is from MediaZilla. |
55 | | -# TODO exit early to avoid a level of indentation |
56 | | -if ($from =~ /^bugzilla-daemon/) { |
| 55 | +if ($from !~ /^bugzilla-daemon/) { |
| 56 | + exit 0; |
| 57 | +} |
57 | 58 | |
58 | | - $/ = ""; |
59 | | - # Extract and remove the comment section. |
60 | | - my ($haschanges, $user); |
61 | | - my $comment = undef; |
| 59 | +$/ = ""; |
| 60 | +# Extract and remove the comment section. |
| 61 | +my ($haschanges, $user); |
| 62 | +my $comment = undef; |
62 | 63 | |
63 | | - for ($body) { |
64 | | - # Attempt to grab the "real name". |
65 | | - if ( m{^--- Comment #\d+ from (.*) <\S+\@.*}m ) { |
66 | | - $haschanges = 1; |
67 | | - $user = $1; |
68 | | - $comment = 1; |
69 | | - } |
| 64 | +for ($body) { |
| 65 | + # Attempt to grab the "real name". |
| 66 | + if ( m{^--- Comment #\d+ from (.*) <\S+\@.*}m ) { |
| 67 | + $haschanges = 1; |
| 68 | + $user = $1; |
| 69 | + $comment = 1; |
| 70 | + } |
70 | 71 | |
71 | | - # Re-attempt to grab the "real name". |
72 | | - if ( m{^(.*) <\S+\@\S+> changed:$}m ) { |
73 | | - $haschanges = 1; |
74 | | - $user = $1 if !$user; |
75 | | - } else { |
76 | | - # If "real name" isn't available and we didn't get a user from the |
77 | | - # comment header, just use the "X-Bugzilla-Who" header. |
78 | | - my @who = split '@', $mail->header( 'X-Bugzilla-Who' ); |
79 | | - $user = $who[0]; |
80 | | - } |
81 | | - } |
| 72 | + # Re-attempt to grab the "real name". |
| 73 | + if ( m{^(.*) <\S+\@\S+> changed:$}m ) { |
| 74 | + $haschanges = 1; |
| 75 | + $user = $1 if !$user; |
| 76 | + } else { |
| 77 | + # If "real name" isn't available and we didn't get a user from the |
| 78 | + # comment header, just use the "X-Bugzilla-Who" header. |
| 79 | + my @who = split '@', $mail->header( 'X-Bugzilla-Who' ); |
| 80 | + $user = $who[0]; |
| 81 | + } |
| 82 | +} |
82 | 83 | |
83 | | - my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' ); |
| 84 | +my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' ); |
84 | 85 | |
85 | | - # Check if this is a dependency e-mail. If so, ignore it. |
86 | | - # We have removed the comment section to prevent people from using |
87 | | - # this by adding the right text to a comment. |
88 | | - # TODO move that check to the top to avoid a level of indentation |
89 | | - if ($body !~ /^Bug \d+ depends on bug \d+, which changed state/m) { |
| 86 | +# Check if this is a dependency e-mail. If so, ignore it. |
| 87 | +# We have removed the comment section to prevent people from using |
| 88 | +# this by adding the right text to a comment. |
| 89 | +if ($body =~ /^Bug \d+ depends on bug \d+, which changed state/m) { |
| 90 | + exit 0; |
| 91 | +} |
90 | 92 | |
91 | | - my ($bug, $summary, $st); |
92 | | - if ($subject =~ /\[Bug (\d+)\]\s+New:\s+(.*)/s) { |
93 | | - ($bug, $summary, $st) = ($1, $2, "\00303(NEW)\003"); |
94 | | - } elsif ($subject =~ /\[Bug (\d+)\]\s(.*)/s) { |
95 | | - ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003"); |
96 | | - } |
| 93 | +my ($bug, $summary, $st); |
| 94 | +if ($subject =~ /\[Bug (\d+)\]\s+New:\s+(.*)/s) { |
| 95 | + ($bug, $summary, $st) = ($1, $2, "\00303(NEW)\003"); |
| 96 | +} elsif ($subject =~ /\[Bug (\d+)\]\s(.*)/s) { |
| 97 | + ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003"); |
| 98 | +} |
97 | 99 | |
98 | | - ## Set the URL to the URL found in the message body if available, |
99 | | - ## else construct our own URL |
100 | | - my $url = |
101 | | - $body =~ /^(http.*\/)show_bug\.cgi\?id=(.*)$/m |
102 | | - ? "$1$2" # short URL! |
103 | | - : "http://bugzilla.wikimedia.org/show_bug.cgi?id=$bug"; |
| 100 | +## Set the URL to the URL found in the message body if available, |
| 101 | +## else construct our own URL |
| 102 | +my $url = |
| 103 | + $body =~ /^(http.*\/)show_bug\.cgi\?id=(.*)$/m |
| 104 | + ? "$1$2" # short URL! |
| 105 | + : "http://bugzilla.wikimedia.org/show_bug.cgi?id=$bug"; |
104 | 106 | |
105 | | - $summary =~ s/\s+/ /g; |
| 107 | +$summary =~ s/\s+/ /g; |
106 | 108 | |
107 | | - # We are going to append stuff to the beginning of $output later. |
108 | | - # This stuff is going to contain $st. But we want a chance of changing it first. |
109 | | - $output = ""; |
| 109 | +# We are going to append stuff to the beginning of $output later. |
| 110 | +# This stuff is going to contain $st. But we want a chance of changing it first. |
| 111 | +$output = ""; |
110 | 112 | |
111 | | - if ($st eq "\00303(NEW)\003") { |
112 | | - my $product = $mail->header( 'X-Bugzilla-Product' ); |
113 | | - my $component = $mail->header( 'X-Bugzilla-Component' ); |
114 | | - my $severity = $mail->header( 'X-Bugzilla-Severity' ); |
| 113 | +if ($st eq "\00303(NEW)\003") { |
| 114 | + my $product = $mail->header( 'X-Bugzilla-Product' ); |
| 115 | + my $component = $mail->header( 'X-Bugzilla-Component' ); |
| 116 | + my $severity = $mail->header( 'X-Bugzilla-Severity' ); |
115 | 117 | |
116 | | - ## Doesn't seem to be sent as a header. |
117 | | - my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m; |
| 118 | + ## Doesn't seem to be sent as a header. |
| 119 | + my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m; |
118 | 120 | |
119 | | - $output .= "$severity; \002$product\002\: $component; (\002$reporter\002)\n"; |
120 | | - } else { |
121 | | - if ($haschanges) { |
122 | | - my @outputs; |
123 | | - my $status = $mail->header( 'X-Bugzilla-Status' ); |
124 | | - if ($status eq 'NEW') { |
125 | | - $st = "\00303(mod)\003"; |
126 | | - } elsif ($status eq 'REOPENED' && grep {$_ eq 'Status'} @changed_fields) { |
127 | | - $st = "\00304(REOPENED)\003"; |
128 | | - } elsif ( grep {$_ eq 'Status'} @changed_fields ) { |
129 | | - $st = "\00303($status)\003"; |
130 | | - } else { |
131 | | - $st = "\00303(mod)\003"; |
132 | | - } |
| 121 | + $output .= "$severity; \002$product\002\: $component; (\002$reporter\002)\n"; |
| 122 | +} else { |
| 123 | + if ($haschanges) { |
| 124 | + my @outputs; |
| 125 | + my $status = $mail->header( 'X-Bugzilla-Status' ); |
| 126 | + if ($status eq 'NEW') { |
| 127 | + $st = "\00303(mod)\003"; |
| 128 | + } elsif ($status eq 'REOPENED' && grep {$_ eq 'Status'} @changed_fields) { |
| 129 | + $st = "\00304(REOPENED)\003"; |
| 130 | + } elsif ( grep {$_ eq 'Status'} @changed_fields ) { |
| 131 | + $st = "\00303($status)\003"; |
| 132 | + } else { |
| 133 | + $st = "\00303(mod)\003"; |
| 134 | + } |
133 | 135 | |
134 | | - if ($st eq "\00303(RESOLVED)\003" && $body =~ /Resolution\|\s+\|(\w+)/m) { |
135 | | - $st = $rhash->{$1}; |
136 | | - } |
137 | | - if ($body =~ /Severity\|(\w+)\s+\|(\w+)/m) { |
138 | | - push @outputs, "$shash->{$1}\->$shash->{$2}"; |
139 | | - } |
140 | | - if ($body =~ /Keywords\|.*$/s) { |
141 | | - my @lines = split (/\n/, $&); |
| 136 | + if ($st eq "\00303(RESOLVED)\003" && $body =~ /Resolution\|\s+\|(\w+)/m) { |
| 137 | + $st = $rhash->{$1}; |
| 138 | + } |
| 139 | + if ($body =~ /Severity\|(\w+)\s+\|(\w+)/m) { |
| 140 | + push @outputs, "$shash->{$1}\->$shash->{$2}"; |
| 141 | + } |
| 142 | + if ($body =~ /Keywords\|.*$/s) { |
| 143 | + my @lines = split (/\n/, $&); |
142 | 144 | |
143 | | - my $added = ''; |
144 | | - my $removed = ''; |
| 145 | + my $added = ''; |
| 146 | + my $removed = ''; |
145 | 147 | |
146 | | - foreach my $a ( @lines ) { |
147 | | - last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/; |
148 | | - $removed .= $2; |
149 | | - $added .= $3; |
150 | | - } |
151 | | - push @outputs, join ' ', ( |
152 | | - ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, $removed)) : ''), |
153 | | - ($added =~ /\S/ ? join (' ', map { "+$_" } split (/\s*,\s*/, $added )) : '') |
154 | | - ); |
155 | | - } |
| 148 | + foreach my $a ( @lines ) { |
| 149 | + last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/; |
| 150 | + $removed .= $2; |
| 151 | + $added .= $3; |
| 152 | + } |
| 153 | + push @outputs, join ' ', ( |
| 154 | + ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, $removed)) : ''), |
| 155 | + ($added =~ /\S/ ? join (' ', map { "+$_" } split (/\s*,\s*/, $added )) : '') |
| 156 | + ); |
| 157 | + } |
156 | 158 | |
157 | | - push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/; |
| 159 | + push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/; |
158 | 160 | |
159 | | - push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m; |
| 161 | + push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m; |
160 | 162 | |
161 | | - push @outputs, "+comment" if $comment; |
| 163 | + push @outputs, "+comment" if $comment; |
162 | 164 | |
163 | | - $output .= " " . join ('; ', @outputs) if @outputs; |
| 165 | + $output .= " " . join ('; ', @outputs) if @outputs; |
164 | 166 | |
165 | | - } |
166 | | - $output .= " (\002\00310$user\003\002)\n"; |
167 | | - } |
168 | | - $output = "$st $summary - \00310$url\003 " . $output; |
169 | 167 | } |
| 168 | + $output .= " (\002\00310$user\003\002)\n"; |
170 | 169 | } |
| 170 | +$output = "$st $summary - \00310$url\003 " . $output; |
171 | 171 | |
172 | 172 | if ($output) { |
173 | 173 | open (OUT, ">>/var/wikibugs/wikibugs.log"); |