Bug 882670 - Part 5: Move the search-term sanity checking into a separate function; r=RyanVM
authorEd Morley <emorley@mozilla.com>
Sun, 16 Jun 2013 15:55:03 +0100
changeset 1236 bcd877b5c15182373fc2d858dca012e8bc6b7332
parent 1235 612c22f85fd0788c6152978b0b19a74655db2cb5
child 1237 0af2f5a0b555c032f51af805f5c53b88d30d4ec4
push id666
push useremorley@mozilla.com
push dateWed, 26 Jun 2013 21:32:24 +0000
reviewersRyanVM
bugs882670
Bug 882670 - Part 5: Move the search-term sanity checking into a separate function; r=RyanVM Part 6 needs to perform the search-term sanity checking independently of getBugsForFailure(), so let's break it out into a separate function.
php/inc/AnnotatedSummaryGenerator.php
--- a/php/inc/AnnotatedSummaryGenerator.php
+++ b/php/inc/AnnotatedSummaryGenerator.php
@@ -120,36 +120,32 @@ class AnnotatedSummaryGenerator implemen
       return;
     }
 
     foreach ($bugs as $bug) {
       $annotatedLines[] = $this->generateSuggestion($bug, $line);
     }
   }
 
-  // Search terms that will match too many bug summaries and so not result in useful suggestions.
-  static $blacklist = array('',
-    'automation.py',
-    'remoteautomation.py',
-    'Shutdown',
-    'Main app process exited normally',
-    'leakcheck'
-  );
+  protected function isHelpfulSearchTerm($searchTerm) {
+    // Search terms that will match too many bug summaries and so not result in useful suggestions.
+    $blacklist = array(
+      'automation.py',
+      'remoteautomation.py',
+      'Shutdown',
+      'Main app process exited normally',
+      'leakcheck'
+    );
+    return (strlen(trim($searchTerm)) > 4 && !in_array($searchTerm, $blacklist));
+  }
 
   protected function getBugsForFailure($searchTerm) {
-    // Don't search for things that will return too many (or irrelevant) results
-    if (strlen(trim($searchTerm)) < 5) {
-      Debug::output('Not fetching bugs for "'.$searchTerm.'" - string too short');
+    if (!$this->isHelpfulSearchTerm($searchTerm)) {
       return array();
     }
-    if (in_array($searchTerm, self::$blacklist)) {
-      Debug::output('Not fetching bugs for "'.$searchTerm.'" - matches ignore list');
-      return array();
-    }
-
     // Bugzilla's max summary length is 256 characters, so once "Intermittent "
     // and platform/suite information is prefixed, it often only leaves ~200
     // characters for the failure, so anything more will be truncated in the summary.
     // We limit the length here to (a) prevent crazy length bzapi requests, and (b)
     // in the hope that we might still match the truncated failure in the summary.
     $searchTerm = trim(substr($searchTerm, 0, 200));
 
     global $db;