Add more build information to the events and have better messaging
Fixes #79
This commit is contained in:
parent
7315736c1f
commit
9b974f6b80
9 changed files with 89 additions and 30 deletions
|
@ -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])
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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':
|
||||
|
|
33
events/build_event.html
Normal file
33
events/build_event.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<a href="{{ event_data.homepage }}">Build {{ event_data.build_id[:7] }}</a> {% block eventkind %}{% endblock %} for
|
||||
{% if event_data.trigger_id %}
|
||||
change
|
||||
{% if event_data.trigger_metadata %}
|
||||
{% if event_data.trigger_metadata.commit_info %}
|
||||
<a href="{{ event_data.trigger_metadata.commit_info.url }}">
|
||||
{{ event_data.trigger_metadata.commit[:7] }}
|
||||
</a> 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 <a href="{{ event_data.trigger_metadata.commit_info.author.url }}">
|
||||
{% if event_data.trigger_metadata.commit_info.author.avatar_url %}
|
||||
<img src="{{ event_data.trigger_metadata.commit_info.author.avatar_url }}" width="16" height="16">{% endif %}{{ event_data.trigger_metadata.commit_info.author.username }}
|
||||
</a>
|
||||
{% 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 %}
|
||||
<br>{{ event_data.error_message }}
|
||||
{% endif %}
|
|
@ -1,2 +1,2 @@
|
|||
<a href="{{ event_data.homepage }}">Build</a> failed for repository
|
||||
{{ event_data.repository | repository_reference }} ({{ event_data.build_id }}): {{ event_data.error_message }}
|
||||
{% extends "build_event.html" %}
|
||||
{% block eventkind %}failure{% endblock %}
|
|
@ -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
|
||||
<a href="{{ event_data.homepage }}">build</a>
|
||||
{% elif event_data.trigger_kind %}
|
||||
<a href="{{ event_data.homepage }}">Build</a> queued via a {{ event_data.trigger_kind }} trigger
|
||||
{% else %}
|
||||
<a href="{{ event_data.homepage }}">Build</a> queued
|
||||
{% endif %}
|
||||
for repository {{ event_data.repository | repository_reference }} ({{ event_data.build_id }})
|
||||
{% extends "build_event.html" %}
|
||||
{% block eventkind %}queued{% endblock %}
|
|
@ -1,2 +1,2 @@
|
|||
<a href="{{ event_data.homepage }}">Build</a> started for repository
|
||||
{{ event_data.repository | repository_reference }} ({{ event_data.build_id }})
|
||||
{% extends "build_event.html" %}
|
||||
{% block eventkind %}started{% endblock %}
|
|
@ -1,2 +1,2 @@
|
|||
<a href="{{ event_data.homepage }}">Build</a> completed for repository
|
||||
{{ event_data.repository | repository_reference }} ({{ event_data.build_id }})
|
||||
{% extends "build_event.html" %}
|
||||
{% block eventkind %}completed{% endblock %}
|
Reference in a new issue