Bug 1363048 - Fix failure by adding current version to list manually r=rail
authorConnor Sheehan <csheehan@mozilla.com>
Thu, 18 May 2017 10:58:06 -0400
changeset 7531 b27e683ce53f
parent 7530 8d56e2c873e1
child 7532 ebcc6f211435
push id5602
push userraliiev@mozilla.com
push dateThu, 18 May 2017 15:01:04 +0000
reviewersrail
bugs1363048
Bug 1363048 - Fix failure by adding current version to list manually r=rail MozReview-Commit-ID: 1IFoiYNnVAC
lib/python/kickoff/buglist_creator.py
lib/python/kickoff/test/test_buglist_creator.py
--- a/lib/python/kickoff/buglist_creator.py
+++ b/lib/python/kickoff/buglist_creator.py
@@ -39,17 +39,17 @@ def create_bugs_url(release):
         current_revision = release['mozillaRevision']
 
         # Get the tag version, for display purposes
         current_version_tag = dot_version_to_tag_version(product, current_version_dot)
 
         # Get all Hg tags for this branch, determine the previous version
         tag_url = MERCURIAL_TAGS_URL_TEMPLATE.format(release_branch=branch)
         mercurial_tags_json = requests.get(tag_url).json()
-        previous_version_tag = get_previous_tag_version(product, current_version_dot, mercurial_tags_json)
+        previous_version_tag = get_previous_tag_version(product, current_version_dot, current_version_tag, mercurial_tags_json)
 
         # Get the changeset between these versions, parse for all unique bugs and backout bugs
         resp = requests.get(CHANGESET_URL_TEMPLATE.format(release_branch=branch,
                                                           from_version=previous_version_tag,
                                                           to_version=current_revision,
                                                           logtype='json-pushes'))
         changeset_data = resp.json()
         unique_bugs, unique_backout_bugs = get_bugs_in_changeset(changeset_data)
@@ -112,17 +112,17 @@ def create_short_url_with_prefix(buglist
     for set_of_bugs, prefix in ((buglist, 'Bugs since previous changeset: ',),
                                (backout_buglist, 'Backouts since previous changeset: ',)):
         if set_of_bugs and len(set_of_bugs) < MAX_BUGS_IN_BUGLIST:
             try:
                 long_bugzilla_link = BUGZILLA_BUGLIST_TEMPLATE.format(bugs='%2C'.join(set_of_bugs))
                 url = requests.get(URL_SHORTENER_TEMPLATE.format(url=long_bugzilla_link)).json()['url']
                 url = prefix + url + '\n'
 
-            except KeyError:
+            except (KeyError, JSONDecodeError,):
                 # If the Bugzilla link fails despite limiting the number of bugs, don't make the url and continue
                 url = ''
         else:
             url = ''
 
         urls.append(url)
 
     return urls[0], urls[1]
@@ -133,17 +133,17 @@ def dot_version_to_tag_version(product, 
     return CHANGELOG_TO_FROM_STRING.format(product=product.upper(), version=underscore_version)
 
 
 def tag_version_to_dot_version_parse(tag):
     dot_version = '.'.join(tag.split('_')[1:-1])
     return parse_version(dot_version)
 
 
-def get_previous_tag_version(product, current_version_dot, mercurial_tags_json):
+def get_previous_tag_version(product, current_version_dot, current_version_tag, mercurial_tags_json):
     """Gets the previous hg version tag for the product and branch, given the current version tag"""
 
     def _invalid_tag_filter(tag):
         """Filters by product and removes incorrect major version + base, end releases"""
         major_version = current_version_dot.split('.')[0]
         prod_major_version_re = r'^{product}_{major_version}'.format(product=product.upper(),
                                                                      major_version=major_version)
 
@@ -151,18 +151,22 @@ def get_previous_tag_version(product, cu
                'END' not in tag and \
                'RELEASE' in tag and \
                re.match(prod_major_version_re, tag)
 
     # Get rid of irrelevant tags, sort by date and extract the tag string
     tags = set(map(itemgetter('tag'), mercurial_tags_json['tags']))
     tags = filter(_invalid_tag_filter, tags)
     dot_tag_version_mapping = zip(map(tag_version_to_dot_version_parse, tags), tags)
+    dot_tag_version_mapping.append(  # Add the current version to the list
+        (parse_version(current_version_dot), current_version_tag)
+    )
     dot_tag_version_mapping = sorted(dot_tag_version_mapping, key=itemgetter(0))
 
+    # Find where the current version is and go back one to get the previous version
     next_version_index = map(itemgetter(0), dot_tag_version_mapping).index(parse_version(current_version_dot)) - 1
 
     return dot_tag_version_mapping[next_version_index][1]
 
 
 def format_return_value(description, unique_bugs, unique_backout_bugs, changeset_html):
     reg_bugs_link, backout_bugs_link = create_short_url_with_prefix(unique_bugs, unique_backout_bugs)
     changeset_full = FULL_CHANGESET_PREFIX + changeset_html
--- a/lib/python/kickoff/test/test_buglist_creator.py
+++ b/lib/python/kickoff/test/test_buglist_creator.py
@@ -93,24 +93,24 @@ class TestBuglistCreator(unittest.TestCa
 
         mock_hg_json = {
             'tags': [
                 {'tag': tag} for tag in ff_48_tags
             ]
         }
 
         test_tuples = [
-            ('48.0b4', 'FIREFOX_48_0b3_RELEASE'),
-            ('48.0b9', 'FIREFOX_48_0b7_RELEASE'),
-            ('48.0.2', 'FIREFOX_48_0_1_RELEASE'),
-            ('48.0.1', 'FIREFOX_48_0_RELEASE'),
+            ('48.0b4', 'FIREFOX_48_0b4_RELEASE', 'FIREFOX_48_0b3_RELEASE'),
+            ('48.0b9', 'FIREFOX_48_0b9_RELEASE', 'FIREFOX_48_0b7_RELEASE'),
+            ('48.0.2', 'FIREFOX_48_0_2_RELEASE', 'FIREFOX_48_0_1_RELEASE'),
+            ('48.0.1', 'FIREFOX_48_0_1_RELEASE', 'FIREFOX_48_0_RELEASE'),
         ]
 
-        assert all(get_previous_tag_version(product, version, mock_hg_json) == expected
-                   for version, expected in test_tuples)
+        assert all(get_previous_tag_version(product, dot_version, tag_version, mock_hg_json) == expected
+                   for dot_version, tag_version, expected in test_tuples)
 
     def test_get_bugs_in_changeset(self):
         changeset_data = {
             0: {'changesets': [{'desc': u'Bug 1354038 - [push-apk] taskgraph: Use rollout and deactivate dry-run on release p=jlorenzo r=aki a=release DONTBUILD'}]},
             1: {'changesets': [{'desc': u'Bug 1356563 - Only set global ready state on native widget loading; r=snorp a=sylvestre\n\nOur "chrome-document-loaded" observer may detect several different types\nof widgets that can exist in the parent process, including the Android\nnsWindow, PuppetWidget, etc. We should only set the global state to\nready when the first top-level nsWindow has loaded, and not just any\nwindow.'}]},
             2: {'changesets': [{'desc': u'No bug, Automated blocklist update from host bld-linux64-spot-305 - a=blocklist-update'}]},
             3: {'changesets': [{'desc': u'Automatic version bump. CLOSED TREE NO BUG a=release'},
                                {'desc': u'No bug - Tagging d345b657d381ade5195f1521313ac651618f54a2 with FIREFOX_53_0_BUILD6, FIREFOX_53_0_RELEASE a=release CLOSED TREE'}]},