From 9b974f6b8035510f8e1f283154f471373a330810 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 16 Jun 2015 23:16:36 -0400 Subject: [PATCH] Add more build information to the events and have better messaging Fixes #79 --- buildman/jobutil/buildjob.py | 2 +- endpoints/building.py | 3 +- endpoints/notificationevent.py | 55 ++++++++++++++++++++++++++------- endpoints/notificationmethod.py | 3 +- events/build_event.html | 33 ++++++++++++++++++++ events/build_failure.html | 4 +-- events/build_queued.html | 11 ++----- events/build_start.html | 4 +-- events/build_success.html | 4 +-- 9 files changed, 89 insertions(+), 30 deletions(-) create mode 100644 events/build_event.html diff --git a/buildman/jobutil/buildjob.py b/buildman/jobutil/buildjob.py index a8a5e2b80..c39301a28 100644 --- a/buildman/jobutil/buildjob.py +++ b/buildman/jobutil/buildjob.py @@ -46,7 +46,7 @@ class BuildJob(object): event_data['error_message'] = error_message spawn_notification(self.repo_build.repository, kind, event_data, - subpage='build?current=%s' % self.repo_build.uuid, + subpage='build/%s' % self.repo_build.uuid, pathargs=['build', self.repo_build.uuid]) diff --git a/endpoints/building.py b/endpoints/building.py index 6dc010cc9..7af6fcd53 100644 --- a/endpoints/building.py +++ b/endpoints/building.py @@ -60,12 +60,13 @@ def start_build(repository, prepared_build, pull_robot_name=None): if prepared_build.trigger: event_log_metadata['trigger_id'] = prepared_build.trigger.uuid event_log_metadata['trigger_kind'] = prepared_build.trigger.service.name + event_log_metadata['trigger_metadata'] = prepared_build.metadata or {} model.log_action('build_dockerfile', repository.namespace_user.username, ip=request.remote_addr, metadata=event_log_metadata, repository=repository) spawn_notification(repository, 'build_queued', event_log_metadata, - subpage='build?current=%s' % build_request.uuid, + subpage='build/%s' % build_request.uuid, pathargs=['build', build_request.uuid]) return build_request diff --git a/endpoints/notificationevent.py b/endpoints/notificationevent.py index 8c38969cf..b1d319a1f 100644 --- a/endpoints/notificationevent.py +++ b/endpoints/notificationevent.py @@ -1,5 +1,7 @@ import logging +import time +from datetime import datetime from notificationhelper import build_event_data from util.jinjautil import get_template_env @@ -76,6 +78,12 @@ class RepoPushEvent(NotificationEvent): }) +def _build_summary(event_data): + """ Returns a summary string for the build data found in the event data block. """ + summary = 'for repository %s [%s]' % (event_data['repository'], event_data['build_id'][0:7]) + return summary + + class BuildQueueEvent(NotificationEvent): @classmethod def event_name(cls): @@ -92,16 +100,27 @@ class BuildQueueEvent(NotificationEvent): 'build_id': build_uuid, 'build_name': 'some-fake-build', 'docker_tags': ['latest', 'foo', 'bar'], + 'trigger_id': '1245634', 'trigger_kind': 'GitHub', 'trigger_metadata': { "default_branch": "master", "ref": "refs/heads/somebranch", - "commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d" + "commit": "42d4a62c53350993ea41069e9f2cfdefb0df097d", + "commit_info": { + 'url': 'http://path/to/the/commit', + 'message': 'Some commit message', + 'date': time.mktime(datetime.now().timetuple()), + 'author': { + 'username': 'fakeauthor', + 'url': 'http://path/to/fake/author/in/scm', + 'avatar_url': 'http://www.gravatar.com/avatar/fakehash' + } + } } - }, subpage='/build?current=%s' % build_uuid) + }, subpage='/build/%s' % build_uuid) def get_summary(self, event_data, notification_data): - return 'Build queued for repository %s' % (event_data['repository']) + return 'Build queued ' + _build_summary(event_data) class BuildStartEvent(NotificationEvent): @@ -119,16 +138,17 @@ class BuildStartEvent(NotificationEvent): 'build_id': build_uuid, 'build_name': 'some-fake-build', 'docker_tags': ['latest', 'foo', 'bar'], + 'trigger_id': '1245634', 'trigger_kind': 'GitHub', 'trigger_metadata': { "default_branch": "master", "ref": "refs/heads/somebranch", - "commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d" + "commit": "42d4a62c53350993ea41069e9f2cfdefb0df097d" } - }, subpage='/build?current=%s' % build_uuid) + }, subpage='/build/%s' % build_uuid) def get_summary(self, event_data, notification_data): - return 'Build started for repository %s' % (event_data['repository']) + return 'Build started ' + _build_summary(event_data) class BuildSuccessEvent(NotificationEvent): @@ -146,17 +166,18 @@ class BuildSuccessEvent(NotificationEvent): 'build_id': build_uuid, 'build_name': 'some-fake-build', 'docker_tags': ['latest', 'foo', 'bar'], + 'trigger_id': '1245634', 'trigger_kind': 'GitHub', 'trigger_metadata': { "default_branch": "master", "ref": "refs/heads/somebranch", - "commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d" + "commit": "42d4a62c53350993ea41069e9f2cfdefb0df097d" }, 'image_id': '1245657346' - }, subpage='/build?current=%s' % build_uuid) + }, subpage='/build/%s' % build_uuid) def get_summary(self, event_data, notification_data): - return 'Build succeeded for repository %s' % (event_data['repository']) + return 'Build succeeded ' + _build_summary(event_data) class BuildFailureEvent(NotificationEvent): @@ -176,13 +197,25 @@ class BuildFailureEvent(NotificationEvent): 'docker_tags': ['latest', 'foo', 'bar'], 'trigger_kind': 'GitHub', 'error_message': 'This is a fake error message', + 'trigger_id': '1245634', + 'trigger_kind': 'GitHub', 'trigger_metadata': { "default_branch": "master", "ref": "refs/heads/somebranch", - "commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d" + "commit": "42d4a62c53350993ea41069e9f2cfdefb0df097d", + "commit_info": { + 'url': 'http://path/to/the/commit', + 'message': 'Some commit message', + 'date': time.mktime(datetime.now().timetuple()), + 'author': { + 'username': 'fakeauthor', + 'url': 'http://path/to/fake/author/in/scm', + 'avatar_url': 'http://www.gravatar.com/avatar/fakehash' + } + } } }, subpage='/build?current=%s' % build_uuid) def get_summary(self, event_data, notification_data): - return 'Build failure for repository %s' % (event_data['repository']) + return 'Build failure ' + _build_summary(event_data) diff --git a/endpoints/notificationmethod.py b/endpoints/notificationmethod.py index 8626fd68f..a72107f0d 100644 --- a/endpoints/notificationmethod.py +++ b/endpoints/notificationmethod.py @@ -328,8 +328,7 @@ class SlackAdjuster(HTMLParser): self.result.append('*') if tag == 'img': - self.result.append(self.get_attr(attrs, 'alt')) - self.result.append(' ') + self.result.append('') def handle_endtag(self, tag): if tag == 'a': diff --git a/events/build_event.html b/events/build_event.html new file mode 100644 index 000000000..a60b38a4a --- /dev/null +++ b/events/build_event.html @@ -0,0 +1,33 @@ +Build {{ event_data.build_id[:7] }} {% block eventkind %}{% endblock %} for +{% if event_data.trigger_id %} + change + {% if event_data.trigger_metadata %} + {% if event_data.trigger_metadata.commit_info %} + + {{ event_data.trigger_metadata.commit[:7] }} + to + {% if event_data.trigger_metadata.ref.split('/')[1] == 'tags' %} + tag + {% else %} + branch + {% endif %} + {{ event_data.trigger_metadata.ref.split('/')[2] }} + {% if event_data.trigger_metadata.commit_info.author %} + by + {% if event_data.trigger_metadata.commit_info.author.avatar_url %} + {% endif %}{{ event_data.trigger_metadata.commit_info.author.username }} + + {% endif %} + {% else %} + {{ event_data.trigger_metadata.commit[:7] }} + {% endif %} + {% else %} + to {{ event_data.trigger_kind }} repository + {% endif %} +{% else %} + uploaded Dockerfile +{% endif %} + for repository {{ event_data.repository | repository_reference }} +{% if event_data.error_message %} +
{{ event_data.error_message }} +{% endif %} \ No newline at end of file diff --git a/events/build_failure.html b/events/build_failure.html index 7551a467a..c65ad9bf7 100644 --- a/events/build_failure.html +++ b/events/build_failure.html @@ -1,2 +1,2 @@ -Build failed for repository -{{ event_data.repository | repository_reference }} ({{ event_data.build_id }}): {{ event_data.error_message }} +{% extends "build_event.html" %} +{% block eventkind %}failure{% endblock %} \ No newline at end of file diff --git a/events/build_queued.html b/events/build_queued.html index a4ecf8e41..98d4cd750 100644 --- a/events/build_queued.html +++ b/events/build_queued.html @@ -1,9 +1,2 @@ -{% if event_data.is_manual and notification_data.performer_data.entity_name %} -{{ notification_data.performer_data.entity_name | user_reference }} queued a -build -{% elif event_data.trigger_kind %} -Build queued via a {{ event_data.trigger_kind }} trigger -{% else %} -Build queued -{% endif %} - for repository {{ event_data.repository | repository_reference }} ({{ event_data.build_id }}) +{% extends "build_event.html" %} +{% block eventkind %}queued{% endblock %} \ No newline at end of file diff --git a/events/build_start.html b/events/build_start.html index 19c9efbc8..6a658002d 100644 --- a/events/build_start.html +++ b/events/build_start.html @@ -1,2 +1,2 @@ -Build started for repository -{{ event_data.repository | repository_reference }} ({{ event_data.build_id }}) +{% extends "build_event.html" %} +{% block eventkind %}started{% endblock %} \ No newline at end of file diff --git a/events/build_success.html b/events/build_success.html index 6ecfa6a7b..c196d3044 100644 --- a/events/build_success.html +++ b/events/build_success.html @@ -1,2 +1,2 @@ -Build completed for repository -{{ event_data.repository | repository_reference }} ({{ event_data.build_id }}) +{% extends "build_event.html" %} +{% block eventkind %}completed{% endblock %} \ No newline at end of file