Bug 1131862 - mcMerge: Return early if 'products' missing from bzapi config
authorEd Morley <emorley@mozilla.com>
Tue, 24 Feb 2015 09:30:44 +0000
changeset 1506 3b92d0e89f8f
parent 1505 322347863a53
child 1507 51aa56262fc0
push id872
push useremorley@mozilla.com
push dateTue, 24 Feb 2015 23:11:31 +0000
bugs1131862
Bug 1131862 - mcMerge: Return early if 'products' missing from bzapi config Check for the 'product' property up-front, rather than having conditionals on it throughout. Also create a variable for products, to clean up the references.
mcmerge/js/ConfigurationData.js
--- a/mcmerge/js/ConfigurationData.js
+++ b/mcmerge/js/ConfigurationData.js
@@ -36,51 +36,54 @@ var ConfigurationData = {
     };
 
     var bugzilla = bz.createClient({timeout: 30000});
     bugzilla.getConfiguration(callback);
   },
 
 
   parseData: function CD_parseData(data, loadCallback) {
+    if (!('product' in data)) {
+        loadCallback();
+        return;
+    }
+    var products = data.product;
     // Parse Milestones 
     var productMilestones = {}
-    if ('product' in data) {
-      for (var product in data['product']) {
-        var values = data.product[product].target_milestone;
-        productMilestones[product] = {}
-        productMilestones[product].values = values.map(UI.htmlEncode);
-        var dashIndex = values.indexOf('---');
-        if (dashIndex != -1) {
-          if (dashIndex + 1 < values.length && this.useNext.indexOf(product) != -1)
-            productMilestones[product].defaultIndex = dashIndex + 1;
-          else
-            productMilestones[product].defaultIndex = dashIndex;
-        } else
-          productMilestones[product].defaultIndex = 0;
+    for (var product in products) {
+      var values = products[product].target_milestone;
+      productMilestones[product] = {}
+      productMilestones[product].values = values.map(UI.htmlEncode);
+      var dashIndex = values.indexOf('---');
+      if (dashIndex != -1) {
+        if (dashIndex + 1 < values.length && this.useNext.indexOf(product) != -1)
+          productMilestones[product].defaultIndex = dashIndex + 1;
+        else
+          productMilestones[product].defaultIndex = dashIndex;
+      } else
+        productMilestones[product].defaultIndex = 0;
       }
-    }
     this.milestones = productMilestones;
 
     // Find the flag number for in-testsuite 
     if ('flag_type' in data) {
       for (var flagNumber in data['flag_type']) {
         if (data['flag_type'][flagNumber].name == 'in-testsuite') {
           this.testsuiteFlagID = parseInt(flagNumber);
           break;
         }
       }
     }
 
     // Find which products/components can have intestsuite set
-    if ('product' in data && this.testsuiteFlagID != -1) {
-      for (var product in data.product) {
+    if (this.testsuiteFlagID != -1) {
+      for (var product in products) {
         this.hasTestsuiteFlag[product] = {};
-        for (var component in data.product[product].component) {
-          var hasTestsuite = data.product[product].component[component].flag_type.indexOf(this.testsuiteFlagID) != -1;
+        for (var component in products[product].component) {
+          var hasTestsuite = products[product].component[component].flag_type.indexOf(this.testsuiteFlagID) != -1;
           this.hasTestsuiteFlag[product][component] = hasTestsuite;
         }
       }
     }
 
     loadCallback();
   }
 };