templates_buildsdir = $(templatesdir)/builds
dist_templates_builds_messages_DATA = \
- src/templates/builds/messages/comment.txt
+ src/templates/builds/messages/comment.txt \
+ src/templates/builds/messages/failed.txt \
+ src/templates/builds/messages/finished.txt
templates_builds_messagesdir = $(templates_buildsdir)/messages
# If all jobs have finished, the build has finished
elif all((j.has_finished() for j in self.jobs)):
- return await self.finished()
+ return await self.finished(success=True)
# If there are any failed jobs, the build has failed
elif any((j.has_failed() for j in self.jobs)):
- return await self.failed()
+ return await self.finished(success=False)
## Comment stuff
# Actions
- async def finished(self):
+ async def finished(self, success):
"""
Called when this build has successfully finished
"""
- pass # XXX TODO
+ # Mark as finished
+ self._set_attribute_now("finished_at")
+
+ # Mark as failed if the build was not successful
+ if not success:
+ self._set_attribute("failed", True)
+
+ # Notify everyone this build has finished...
+ if success:
+ self._send_email("builds/messages/finished.txt")
+ # ... or that it has failed
+ else:
+ self._send_email("builds/messages/failed.txt")
def has_finished(self):
"""
return False
- async def failed(self):
+ def _send_email(self, *args, exclude=None, **kwargs):
"""
- Called when the build has failed
+ Convenience function which sends an email to everybody who would care
"""
- pass # XXX TODO
+ for user in self.watchers:
+ # Skip some people
+ if exclude and user in exclude:
+ continue
+
+ # Send an email to the user
+ user.send_email(*args, build=self, **kwargs)
@lazy_property
def repo(self):
def notify(self):
"""
- Notifies all watchers about this comment
+ Notifies all watchers about this comment (except the user who posted it)
"""
- for user in self.build.watchers:
- # Skip the user who posted it
- if user == self.user:
- continue
-
- # Send an email
- user.send_email("builds/messages/comment.txt",
- build=self.build, comment=self)
+ self.build._send_email("builds/messages/comment.txt",
+ exclude=[self.user], build=self.build, comment=self)