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" : {
}
}
+ 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
%(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):
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"
# 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):
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")