https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113010

Revision: 113010
Author:   hashar
Date:     2012-03-05 10:09:28 +0000 (Mon, 05 Mar 2012)
Log Message:
-----------
save some levels of indentation by early exiting

Modified Paths:
--------------
    trunk/tools/wikibugs/wikibugs

Modified: trunk/tools/wikibugs/wikibugs
===================================================================
--- trunk/tools/wikibugs/wikibugs       2012-03-05 10:02:59 UTC (rev 113009)
+++ trunk/tools/wikibugs/wikibugs       2012-03-05 10:09:28 UTC (rev 113010)
@@ -51,122 +51,122 @@
 my $subject = $mail->header( 'Subject' );
 
 # Check that the e-mail is from MediaZilla.
-# TODO exit early to avoid a level of indentation
-if ($from =~ /^bugzilla-daemon/) {
+if ($from !~ /^bugzilla-daemon/) {
+       exit 0;
+}
 
-  $/ = "";
-  # Extract and remove the comment section.
-  my ($haschanges, $user);
-  my $comment = undef;
+$/ = "";
+# Extract and remove the comment section.
+my ($haschanges, $user);
+my $comment = undef;
 
-  for ($body) {
-    # Attempt to grab the "real name".
-    if ( m{^--- Comment #\d+ from (.*) <\S+\@.*}m ) {
-      $haschanges = 1;
-      $user       = $1;
-      $comment    = 1;
-    }
+for ($body) {
+       # Attempt to grab the "real name".
+       if ( m{^--- Comment #\d+ from (.*) <\S+\@.*}m ) {
+         $haschanges = 1;
+         $user       = $1;
+         $comment    = 1;
+       }
 
-    # Re-attempt to grab the "real name".
-    if ( m{^(.*) <\S+\@\S+> changed:$}m ) {
-      $haschanges = 1;
-      $user       = $1 if !$user;
-    } else {
-      # If "real name" isn't available and we didn't get a user from the
-      # comment header, just use the "X-Bugzilla-Who" header.
-      my @who = split '@', $mail->header( 'X-Bugzilla-Who' );
-      $user = $who[0];
-    }
-  }
+       # Re-attempt to grab the "real name".
+       if ( m{^(.*) <\S+\@\S+> changed:$}m ) {
+         $haschanges = 1;
+         $user       = $1 if !$user;
+       } else {
+         # If "real name" isn't available and we didn't get a user from the
+         # comment header, just use the "X-Bugzilla-Who" header.
+         my @who = split '@', $mail->header( 'X-Bugzilla-Who' );
+         $user = $who[0];
+       }
+}
 
-  my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' 
);
+my @changed_fields = split /\s+/, $mail->header( 'X-Bugzilla-Changed-Fields' );
 
-  # Check if this is a dependency e-mail. If so, ignore it.
-  # We have removed the comment section to prevent people from using
-  # this by adding the right text to a comment.
-  # TODO move that check to the top to avoid a level of indentation
-  if ($body !~ /^Bug \d+ depends on bug \d+, which changed state/m) {
+# Check if this is a dependency e-mail. If so, ignore it.
+# We have removed the comment section to prevent people from using
+# this by adding the right text to a comment.
+if ($body =~ /^Bug \d+ depends on bug \d+, which changed state/m) {
+       exit 0;
+}
 
-    my ($bug, $summary, $st);
-    if ($subject =~ /\[Bug (\d+)\]\s+New:\s+(.*)/s) {
-      ($bug, $summary, $st) = ($1, $2, "\00303(NEW)\003");
-    } elsif ($subject =~ /\[Bug (\d+)\]\s(.*)/s) {
-      ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003");
-    }
+my ($bug, $summary, $st);
+if ($subject =~ /\[Bug (\d+)\]\s+New:\s+(.*)/s) {
+  ($bug, $summary, $st) = ($1, $2, "\00303(NEW)\003");
+} elsif ($subject =~ /\[Bug (\d+)\]\s(.*)/s) {
+  ($bug, $summary, $st) = ($1, $2, "\00303(mod)\003");
+}
 
-    ## Set the URL to the URL found in the message body if available,
-       ## else construct our own URL
-    my $url =
-      $body =~ /^(http.*\/)show_bug\.cgi\?id=(.*)$/m
-        ? "$1$2"                # short URL!
-          : "http://bugzilla.wikimedia.org/show_bug.cgi?id=$bug";;
+## Set the URL to the URL found in the message body if available,
+## else construct our own URL
+my $url =
+  $body =~ /^(http.*\/)show_bug\.cgi\?id=(.*)$/m
+       ? "$1$2"                # short URL!
+         : "http://bugzilla.wikimedia.org/show_bug.cgi?id=$bug";;
 
-    $summary =~ s/\s+/ /g;
+$summary =~ s/\s+/ /g;
 
-    # We are going to append stuff to the beginning of $output later.
-    # This stuff is going to contain $st. But we want a chance of changing it 
first.
-    $output = "";
+# We are going to append stuff to the beginning of $output later.
+# This stuff is going to contain $st. But we want a chance of changing it 
first.
+$output = "";
 
-    if ($st eq "\00303(NEW)\003") {
-      my $product   = $mail->header( 'X-Bugzilla-Product' );
-      my $component = $mail->header( 'X-Bugzilla-Component' );
-      my $severity  = $mail->header( 'X-Bugzilla-Severity' );
+if ($st eq "\00303(NEW)\003") {
+  my $product   = $mail->header( 'X-Bugzilla-Product' );
+  my $component = $mail->header( 'X-Bugzilla-Component' );
+  my $severity  = $mail->header( 'X-Bugzilla-Severity' );
 
-      ## Doesn't seem to be sent as a header.
-      my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m;
+  ## Doesn't seem to be sent as a header.
+  my $reporter = $1 if $body =~ /ReportedBy: (.*)\@.*$/m;
 
-      $output .= "$severity; \002$product\002\: $component; 
(\002$reporter\002)\n";
-    } else {
-      if ($haschanges) {
-        my @outputs;
-        my $status = $mail->header( 'X-Bugzilla-Status' );
-        if ($status eq 'NEW') {
-          $st = "\00303(mod)\003";
-        } elsif ($status eq 'REOPENED' && grep {$_ eq 'Status'} 
@changed_fields) {
-          $st = "\00304(REOPENED)\003";
-        } elsif ( grep {$_ eq 'Status'} @changed_fields ) {
-          $st = "\00303($status)\003";
-        } else {
-          $st = "\00303(mod)\003";
-        }
+  $output .= "$severity; \002$product\002\: $component; (\002$reporter\002)\n";
+} else {
+  if ($haschanges) {
+       my @outputs;
+       my $status = $mail->header( 'X-Bugzilla-Status' );
+       if ($status eq 'NEW') {
+         $st = "\00303(mod)\003";
+       } elsif ($status eq 'REOPENED' && grep {$_ eq 'Status'} 
@changed_fields) {
+         $st = "\00304(REOPENED)\003";
+       } elsif ( grep {$_ eq 'Status'} @changed_fields ) {
+         $st = "\00303($status)\003";
+       } else {
+         $st = "\00303(mod)\003";
+       }
 
-        if ($st eq "\00303(RESOLVED)\003" && $body =~ 
/Resolution\|\s+\|(\w+)/m) {
-          $st = $rhash->{$1};
-        }
-        if ($body =~ /Severity\|(\w+)\s+\|(\w+)/m) {
-          push @outputs, "$shash->{$1}\->$shash->{$2}";
-        }
-        if ($body =~ /Keywords\|.*$/s) {
-          my @lines  = split (/\n/, $&);
+       if ($st eq "\00303(RESOLVED)\003" && $body =~ 
/Resolution\|\s+\|(\w+)/m) {
+         $st = $rhash->{$1};
+       }
+       if ($body =~ /Severity\|(\w+)\s+\|(\w+)/m) {
+         push @outputs, "$shash->{$1}\->$shash->{$2}";
+       }
+       if ($body =~ /Keywords\|.*$/s) {
+         my @lines  = split (/\n/, $&);
 
-          my $added   = '';
-          my $removed = '';
+         my $added   = '';
+         my $removed = '';
 
-          foreach my $a ( @lines ) {
-            last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/;
-            $removed .= $2;
-            $added   .= $3;
-          }
-          push @outputs, join ' ', (
-            ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, 
$removed)) : ''),
-            ($added   =~ /\S/ ? join (' ', map { "+$_" } split (/\s*,\s*/, 
$added  )) : '')
-          );
-        }
+         foreach my $a ( @lines ) {
+               last unless $a =~ /^(Keywords|\s+)\|(.*?)\s*\|(.*?)\s*$/;
+               $removed .= $2;
+               $added   .= $3;
+         }
+         push @outputs, join ' ', (
+               ($removed =~ /\S/ ? join (' ', map { "-$_" } split (/\s*,\s*/, 
$removed)) : ''),
+               ($added   =~ /\S/ ? join (' ', map { "+$_" } split (/\s*,\s*/, 
$added  )) : '')
+         );
+       }
 
-        push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/;
+       push @outputs, 'summary' if $body =~ /Summary\|.*?\|.*?/;
 
-        push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m;
+       push @outputs, 'deps' if $body =~ /OtherBugs\w+\|.*?\|.*?$/m;
 
-        push @outputs, "+comment" if $comment;
+       push @outputs, "+comment" if $comment;
 
-        $output .= " " . join ('; ', @outputs) if @outputs;
+       $output .= " " . join ('; ', @outputs) if @outputs;
 
-      }
-      $output .= " (\002\00310$user\003\002)\n";
-    }
-    $output = "$st $summary - \00310$url\003 " . $output;
   }
+  $output .= " (\002\00310$user\003\002)\n";
 }
+$output = "$st $summary - \00310$url\003 " . $output;
 
 if ($output) {
   open (OUT, ">>/var/wikibugs/wikibugs.log");


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to