Add support for the remaining events to the frontend and the backend

This commit is contained in:
Joseph Schorr 2014-07-18 15:58:18 -04:00
parent f7c154abb5
commit af31bde997
7 changed files with 269 additions and 40 deletions

View file

@ -13,13 +13,13 @@ class NotificationEvent(object):
def __init__(self):
pass
def get_summary(self, notification_data):
def get_summary(self, event_data, notification_data):
"""
Returns a human readable one-line summary for the given notification data.
"""
raise NotImplementedError
def get_message(self, notification_data):
def get_message(self, event_data, notification_data):
"""
Returns a human readable HTML message for the given notification data.
"""
@ -53,19 +53,27 @@ class RepoPushEvent(NotificationEvent):
def event_name(cls):
return 'repo_push'
def get_summary(self, notification_data):
return 'Repository %s updated' % (notification_data['event_data']['repository'])
def get_summary(self, event_data, notification_data):
return 'Repository %s updated' % (event_data['repository'])
def get_message(self, notification_data):
event_data = notification_data['event_data']
def get_message(self, event_data, notification_data):
if not event_data.get('updated_tags', []):
return '%s images pushed for repository %s (%s)' % (event_data['pushed_image_count'],
event_data['repository'], event_data['homepage'])
html = """
Repository <a href="%s">%s</a> has been updated via a push.
""" % (event_data['homepage'],
event_data['repository'])
else:
html = """
Repository <a href="%s">%s</a> has been updated via a push.
<br><br>
Tags Updated: %s
""" % (event_data['homepage'],
event_data['repository'],
event_data['updated_tags'])
return 'Tags %s updated for repository %s (%s)' % (event_data['updated_tags'],
event_data['repository'], event_data['homepage'])
return html
def get_sample_data(self, repository=None):
def get_sample_data(self, repository):
repo_string = '%s/%s' % (repository.namespace, repository.name)
event_data = {
'repository': repo_string,
@ -81,22 +89,117 @@ class RepoPushEvent(NotificationEvent):
return event_data
class BuildQueueEvent(NotificationEvent):
@classmethod
def event_name(cls):
return 'build_queued'
def get_sample_data(self, repository):
build_uuid = 'fake-build-id'
repo_string = '%s/%s' % (repository.namespace, repository.name)
event_data = {
'repository': repo_string,
'namespace': repository.namespace,
'name': repository.name,
'docker_url': 'quay.io/%s' % repo_string,
'homepage': 'https://quay.io/repository/%s/build/%s' % (repo_string, build_uuid),
'is_manual': False,
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub'
}
return event_data
def get_summary(self, event_data, notification_data):
return 'Build queued for repository %s' % (event_data['repository'])
def get_message(self, event_data, notification_data):
is_manual = event_data['is_manual']
if is_manual:
html = """
A <a href="%s">new build</a> has been manually queued to start on repository %s.
<br><br>
Build ID: %s
""" % (event_data['homepage'], event_data['repository'], event_data['build_id'])
else:
html = """
A <a href="%s">new build</a> has been queued via a %s trigger to start on repository %s.
<br><br>
Build ID: %s
""" % (event_data['homepage'], event_data['repository'],
event_data['trigger_kind'], event_data['build_id'])
return html
class BuildStartEvent(NotificationEvent):
@classmethod
def event_name(cls):
return 'build_start'
def get_sample_data(self, repository=None):
pass
def get_sample_data(self, repository):
build_uuid = 'fake-build-id'
repo_string = '%s/%s' % (repository.namespace, repository.name)
event_data = {
'repository': repo_string,
'namespace': repository.namespace,
'name': repository.name,
'docker_url': 'quay.io/%s' % repo_string,
'homepage': 'https://quay.io/repository/%s/build?current=%s' % (repo_string, build_uuid),
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub'
}
return event_data
def get_summary(self, event_data, notification_data):
return 'Build started for repository %s' % (event_data['repository'])
def get_message(self, event_data, notification_data):
html = """
A <a href="%s">new build</a> has started on repository %s.
<br><br>
Build ID: %s
""" % (event_data['homepage'], event_data['repository'], event_data['build_id'])
return html
class BuildSuccessEvent(NotificationEvent):
@classmethod
def event_name(cls):
return 'build_success'
def get_sample_data(self, repository=None):
pass
def get_sample_data(self, repository):
build_uuid = 'fake-build-id'
repo_string = '%s/%s' % (repository.namespace, repository.name)
event_data = {
'repository': repo_string,
'namespace': repository.namespace,
'name': repository.name,
'docker_url': 'quay.io/%s' % repo_string,
'homepage': 'https://quay.io/repository/%s/build?current=%s' % (repo_string, build_uuid),
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub'
}
return event_data
def get_summary(self, event_data, notification_data):
return 'Build succeeded for repository %s' % (event_data['repository'])
def get_message(self, event_data, notification_data):
html = """
A <a href="%s">build</a> has finished on repository %s.
<br><br>
Build ID: %s
""" % (event_data['homepage'], event_data['repository'], event_data['build_id'])
return html
class BuildFailureEvent(NotificationEvent):
@ -104,5 +207,33 @@ class BuildFailureEvent(NotificationEvent):
def event_name(cls):
return 'build_failure'
def get_sample_data(self, repository=None):
pass
def get_sample_data(self, repository):
build_uuid = 'fake-build-id'
repo_string = '%s/%s' % (repository.namespace, repository.name)
event_data = {
'repository': repo_string,
'namespace': repository.namespace,
'name': repository.name,
'docker_url': 'quay.io/%s' % repo_string,
'homepage': 'https://quay.io/repository/%s/build?current=%s' % (repo_string, build_uuid),
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub',
'error_message': 'This is a fake error message'
}
return event_data
def get_summary(self, event_data, notification_data):
return 'Build failure for repository %s' % (event_data['repository'])
def get_message(self, event_data, notification_data):
html = """
A <a href="%s">build</a> has failed on repository %s.
<br><br>
Reason: %s<br>
Build ID: %s<br>
""" % (event_data['homepage'], event_data['repository'],
event_data['error_message'], event_data['build_id'])
return html