From: Michael Tremer Date: Mon, 29 May 2023 14:14:12 +0000 (+0000) Subject: monitorings: Update bug report after the build has finished X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52fe3fbc3a7ed8741eb2c9691361a87935aa787b;p=pbs.git monitorings: Update bug report after the build has finished Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/bugtracker.py b/src/buildservice/bugtracker.py index ea6c5ba0..c64e7fa9 100644 --- a/src/buildservice/bugtracker.py +++ b/src/buildservice/bugtracker.py @@ -330,21 +330,17 @@ class Bug(base.Object): async def _update(self, data): """ - Updates this bug + Low-level updater """ response = await self.bugzilla._request("PUT", "/rest/bug/%s" % self.id, data=data) # XXX Update data from response - # Close - - async def close(self, resolution, comment=None): - data = { - "status" : "CLOSED", - "resolution" : resolution, - } - - # Add the comment + async def update(self, comment=None, **data): + """ + Updates the bug + """ + # Comment if comment: data |= { "comment" : { @@ -352,10 +348,21 @@ class Bug(base.Object): } } + return await self._update(data) + + # Close + + async def close(self, resolution, comment=None): + args = { + "status" : "CLOSED", + "resolution" : resolution, + "comment" : comment, + } + log.debug("Closing bug #%s" % self.id) # Send the request - await self._update(data) + await self.update(**args) # Attachments diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index c0794445..0cf4823c 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -718,6 +718,10 @@ class Build(base.DataObject): if self.group: await self.group._build_finished(self) + # Notify release monitoring that this build has finished + if self.monitoring_release: + await self.monitoring_release._build_finished() + return builds def has_finished(self): @@ -856,6 +860,26 @@ class Build(base.DataObject): """ return await self.backend.bugzilla.get_bugs(self.bug_ids) + # Monitoring Release + + @lazy_property + def monitoring_release(self): + """ + Returns the Monitoring Release + """ + return self.backend.monitorings._get_release(""" + SELECT + * + FROM + release_monitoring_releases + WHERE + build_id = %s + """, self.id, + + # Populate cache + build=self, + ) + # Deprecation def _deprecate_others(self): diff --git a/src/buildservice/releasemonitoring.py b/src/buildservice/releasemonitoring.py index 22daa5c8..a85d2710 100644 --- a/src/buildservice/releasemonitoring.py +++ b/src/buildservice/releasemonitoring.py @@ -50,8 +50,14 @@ A build has been created to test this release: %(url)s """ -BUG_DESCRIPTION_WITH_BUILD = BUG_DESCRIPTION + """\n -XXX PUT STUFF ABOUT THE BUILD HERE +# This comment is being added to the bug report when the build has been successful +BUG_BUILD_SUCCESSFUL = "The build has been successful." + +# This command is being added to the bug report when the build has failed. +BUG_BUILD_FAILED = """\ +The build has failed. + +Log files of the failed jobs have been attached for you to investigate why. """ class ReleaseExistsError(Exception): @@ -218,6 +224,14 @@ class Monitorings(base.Object): for monitoring in monitorings: tg.create_task(monitoring.check()) + # Releases + + def _get_releases(self, query, *args, **kwargs): + return self.db.fetch_many(Release, query, *args, **kwargs) + + def _get_release(self, query, *args, **kwargs): + return self.db.fetch_one(Release, query, *args, **kwargs) + class Monitoring(base.DataObject): table = "release_monitorings" @@ -341,11 +355,13 @@ class Monitoring(base.DataObject): # Releases - def _get_releases(self, query, *args): - return self.db.fetch_many(Release, query, *args, monitoring=self) + def _get_releases(self, query, *args, **kwargs): + return self.backend.monitorings._get_releases(query, *args, + monitoring=self, **kwargs) - def _get_release(self, query, *args): - return self.db.fetch_one(Release, query, *args, monitoring=self) + def _get_release(self, query, *args, **kwargs): + return self.backend.monitorings._get_release(query, *args, + monitoring=self, **kwargs) @property def latest_release(self): @@ -747,3 +763,35 @@ class Release(base.DataObject): result.append(line) return result + + async def _build_finished(self): + """ + Called when the build has finished + """ + # Fetch the bug report + bug = await self.get_bug() + + # If the build has been successful, ... + if self.build.is_successful(): + await bug.update(comment=BUG_BUILD_SUCCESSFUL) + + # If the build failed, ... + elif self.build.has_failed(): + # Say that the build has failed + await bug.update(comment=BUG_BUILD_FAILED) + + # Append any logfiles from failed jobs + for job in self.build.jobs: + if not job.has_failed(): + continue + + # Open the logfile + try: + log = await job.open_log() + except FileNotFoundError as e: + log.warning("Could not open log file for %s" % job) + continue + + # Attach it to the bug + await bug.attach(summary="Log file for %s" % job, filename="%s.log" % job, + data=log, content_type="text/plain")