r113010 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113009‎ | r113010 | r113011 >
Date:10:09, 5 March 2012
Author:hashar
Status:ok
Tags:
Comment:
save some levels of indentation by early exiting
Modified paths:
  • /trunk/tools/wikibugs/wikibugs (modified) (history)

Diff [purge]

Index: trunk/tools/wikibugs/wikibugs
@@ -51,122 +51,122 @@
5252 my $subject = $mail->header( 'Subject' );
5353
5454 # 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+}
5758
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;
6263
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+ }
7071
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+}
8283
83 - my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' );
 84+my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' );
8485
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+}
9092
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+}
9799
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";
104106
105 - $summary =~ s/\s+/ /g;
 107+$summary =~ s/\s+/ /g;
106108
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 = "";
110112
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' );
115117
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;
118120
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+ }
133135
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/, $&);
142144
143 - my $added = '';
144 - my $removed = '';
 145+ my $added = '';
 146+ my $removed = '';
145147
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+ }
156158
157 - push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/;
 159+ push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/;
158160
159 - push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m;
 161+ push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m;
160162
161 - push @outputs, "+comment" if $comment;
 163+ push @outputs, "+comment" if $comment;
162164
163 - $output .= " " . join ('; ', @outputs) if @outputs;
 165+ $output .= " " . join ('; ', @outputs) if @outputs;
164166
165 - }
166 - $output .= " (\002\00310$user\003\002)\n";
167 - }
168 - $output = "$st $summary - \00310$url\003 " . $output;
169167 }
 168+ $output .= " (\002\00310$user\003\002)\n";
170169 }
 170+$output = "$st $summary - \00310$url\003 " . $output;
171171
172172 if ($output) {
173173 open (OUT, ">>/var/wikibugs/wikibugs.log");

Status & tagging log