r112822 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112821‎ | r112822 | r112823 >
Date:17:49, 1 March 2012
Author:hashar
Status:ok
Tags:
Comment:
redo alignement + some comments/TODO

No code change
Modified paths:
  • /trunk/tools/wikibugs/wikibugs (modified) (history)

Diff [purge]

Index: trunk/tools/wikibugs/wikibugs
@@ -7,7 +7,8 @@
88 # Original version by Brion Vibber, 2004-08-02, 2004-08-10 and 2004-08-15
99 # Entirely rewritten by Timwi, 2004-09-06
1010 # 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:
1213 # http://wikitech.wikimedia.org/view/Wikibugs and finally migrated to
1314 # the subversion repository in 2007.
1415
@@ -18,52 +19,58 @@
1920 my $contents = <STDIN>;
2021 my $output;
2122
 23+# Map each bugzilla severity to an IRC message with colors
2224 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",
2831 'critical' => "\00304CRIT\003",
29 - 'blocker' => "\00304\002BLOCKER\002\003"
 32+ 'blocker' => "\00304\002BLOCKER\002\003"
3033 };
3134
 35+# Map each bugzilla resolution status to an IRC message with colors
3236 my $rhash = {
3337 '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"
4044 };
4145
 46+# Parse a received email
4247 use Email::MIME;
43 -
4448 my $mail = Email::MIME->new( $contents );
4549
46 -my $from = $mail->header( 'From' );
47 -my $body = $mail->body;
 50+my $from = $mail->header( 'From' );
 51+my $body = $mail->body;
4852 my $subject = $mail->header( 'Subject' );
4953
5054 # Check that the e-mail is from MediaZilla.
 55+# TODO exit early to avoid a level of indentation
5156 if ($from =~ /^bugzilla-daemon/) {
5257
5358 $/ = "";
5459 # Extract and remove the comment section.
5560 my ($haschanges, $user);
5661 my $comment = undef;
 62+
5763 for ($body) {
5864 # Attempt to grab the "real name".
5965 if ( m{^--- Comment #\d+ from (.*) <\S+\@.*}m ) {
6066 $haschanges = 1;
61 - $user = $1;
62 - $comment = 1;
 67+ $user = $1;
 68+ $comment = 1;
6369 }
 70+
6471 # Re-attempt to grab the "real name".
6572 if ( m{^(.*) <\S+\@\S+> changed:$}m ) {
6673 $haschanges = 1;
67 - $user = $1 if !$user;
 74+ $user = $1 if !$user;
6875 } else {
6976 # If "real name" isn't available and we didn't get a user from the
7077 # comment header, just use the "X-Bugzilla-Who" header.
@@ -74,10 +81,10 @@
7582
7683 my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' );
7784
78 -
7985 # Check if this is a dependency e-mail. If so, ignore it.
8086 # We have removed the comment section to prevent people from using
8187 # this by adding the right text to a comment.
 88+ # TODO move that check to the top to avoid a level of indentation
8289 if ($body !~ /^Bug \d+ depends on bug \d+, which changed state/m) {
8390
8491 my ($bug, $summary, $st);
@@ -87,7 +94,8 @@
8895 ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003");
8996 }
9097
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
92100 my $url =
93101 $body =~ /^(http.*\/)show_bug\.cgi\?id=(.*)$/m
94102 ? "$1$2" # short URL!
@@ -100,9 +108,10 @@
101109 $output = "";
102110
103111 if ($st eq "\00303(NEW)\003") {
104 - my $product = $mail->header( 'X-Bugzilla-Product' );
 112+ my $product = $mail->header( 'X-Bugzilla-Product' );
105113 my $component = $mail->header( 'X-Bugzilla-Component' );
106 - my $severity = $mail->header( 'X-Bugzilla-Severity' );
 114+ my $severity = $mail->header( 'X-Bugzilla-Severity' );
 115+
107116 ## Doesn't seem to be sent as a header.
108117 my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m;
109118
@@ -128,13 +137,15 @@
129138 push @outputs, "$shash->{$1}\->$shash->{$2}";
130139 }
131140 if ($body =~ /Keywords\|.*$/s) {
132 - my @lines = split (/\n/, $&);
133 - my $added = '';
 141+ my @lines = split (/\n/, $&);
 142+
 143+ my $added = '';
134144 my $removed = '';
 145+
135146 foreach my $a ( @lines ) {
136147 last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/;
137148 $removed .= $2;
138 - $added .= $3;
 149+ $added .= $3;
139150 }
140151 push @outputs, join ' ', (
141152 ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, $removed)) : ''),

Status & tagging log