Parse taglist.log for autorelease builds 63/70163/3
authorSam Hague <shague@redhat.com>
Wed, 28 Mar 2018 19:17:33 +0000 (12:17 -0700)
committerSam Hague <shague@redhat.com>
Mon, 2 Apr 2018 18:30:42 +0000 (18:30 +0000)
Change-Id: I86f24db2f0a39e194533fbc0f100dce833417ebe
Signed-off-by: Sam Hague <shague@redhat.com>
tools/distchanges/changes.py
tools/distchanges/tests/test_changes.py

index 2e1d78501fd5af700d1854b9544b3ff39146e5b0..297e4f3adcf2aa49bd2927ef1e9755d8b78b6432 100644 (file)
@@ -379,6 +379,43 @@ class Changes(object):
             logger.warn("Could not find a git.properties file for %s", project)
         return ChangeId(None, False)
 
+    def get_taglist(self):
+        """
+        Read a taglist.log file into memory
+
+        :return taglist: The taglist.log file read into memory
+        """
+        tagfile = os.path.join(self.distro_path, "taglist.log")
+        taglist = None
+        # Ensure the file exists and then read it
+        if os.path.isfile(tagfile):
+            with open(tagfile, 'r') as fp:
+                taglist = fp.read()
+        return taglist
+
+    def find_project_commit_changeid(self, taglist, project):
+        """
+        Find a commit id for the given project
+
+        :param str taglist: the taglist.log file read into memory
+        :param str project: The project to search
+        :return ChangeId: The Change-Id with a valid Change-Id or None if not found
+        """
+        # break the regex up since {} is a valid regex element but we need it for the format project
+        re1 = r'({0} '.format(project)
+        re1 = re1 + r'(\b[a-f0-9]{40})\b|\b([a-f0-9]{8})\b' + r')'
+        commitid = re.search(re1, taglist)
+        if commitid and commitid.group(2):
+            logger.info("trying commitid from taglist.log in %s: %s", project, commitid.group(2))
+
+            gerrits = self.gerritquery.get_gerrits(project, commitid=commitid.group(2))
+            if gerrits:
+                logger.info("found Change-Id from taglist.log as merged in %s", project)
+                return ChangeId(gerrits[0]["id"], True)
+
+        logger.warn("did not find Change-Id from commitid from taglist.log in %s", project)
+        return ChangeId(None, False)
+
     def init(self):
         self.gerritquery = gerritquery.GerritQuery(self.remote_url, self.branch, self.qlimit, self.verbose)
         self.set_projects(self.project_names)
@@ -409,6 +446,19 @@ class Changes(object):
         if self.distro_url is not None:
             self.download_distro()
 
+        logger.info("Checking if this is an autorelease build by looking for taglist.log")
+        taglist = self.get_taglist()
+        if taglist is not None:
+            for project in sorted(self.projects):
+                logger.info("Processing %s using taglist.log", project)
+                changeid = self.find_project_commit_changeid(taglist, project)
+                if changeid.changeid:
+                    self.projects[project]['commit'] = changeid.changeid
+                    self.projects[project]["includes"] = \
+                        self.get_includes(project, changeid.changeid, msg=None, merged=changeid.merged)
+            return self.projects
+
+        logger.info("This is not an autorelease build, continuing as integration distribution")
         for project in sorted(self.projects):
             logger.info("Processing %s", project)
             changeid = self.find_distro_changeid(project)
index 8628695f98591220ef242978a885f480299f0ca0..6d65e20cd8ec126a1b19cd6f61f851bc2e374d5c 100644 (file)
@@ -12,7 +12,7 @@ NETVIRT_PROJECTS = ["controller", "dlux", "dluxapps", "genius", "infrautils", "m
                     "neutron", "odlparent", "openflowplugin", "ovsdb", "sfc", "yangtools"]
 PROJECT_NAMES = NETVIRT_PROJECTS
 DISTRO_PATH = "/tmp/distribution-karaf"
-BRANCH = 'stable/nitrogen'
+BRANCH = 'master'
 LIMIT = 10
 QLIMIT = 50
 
@@ -29,7 +29,7 @@ class TestChanges(unittest.TestCase):
         changes.pretty_print_projects(projects)
 
     def test_run_cmd_single(self):
-        project_names = ['odlparent']
+        project_names = ['netvirt']
         branch = BRANCH
         self.run_cmd(branch, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL, logging.INFO)