- Small title fix
- Make sure sample event data uses the real event data generation code
This commit is contained in:
parent
7de1dd7dc0
commit
a2f0f57414
3 changed files with 33 additions and 54 deletions
|
@ -4,6 +4,8 @@ import os.path
|
|||
import tarfile
|
||||
import base64
|
||||
|
||||
from notificationhelper import build_event_data
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class InvalidNotificationEventException(Exception):
|
||||
|
@ -74,19 +76,11 @@ class RepoPushEvent(NotificationEvent):
|
|||
return html
|
||||
|
||||
def get_sample_data(self, repository):
|
||||
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' % repo_string,
|
||||
'visibility': repository.visibility.name,
|
||||
return build_event_data(repository, {
|
||||
'updated_tags': ['latest', 'foo', 'bar'],
|
||||
'pushed_image_count': 10,
|
||||
'pruned_image_count': 3
|
||||
}
|
||||
return event_data
|
||||
})
|
||||
|
||||
|
||||
class BuildQueueEvent(NotificationEvent):
|
||||
|
@ -96,20 +90,14 @@ class BuildQueueEvent(NotificationEvent):
|
|||
|
||||
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),
|
||||
|
||||
return build_event_data(repository, {
|
||||
'is_manual': False,
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
'trigger_kind': 'GitHub'
|
||||
}
|
||||
return event_data
|
||||
}, subpage='/build?current=%s' % build_uuid)
|
||||
|
||||
def get_summary(self, event_data, notification_data):
|
||||
return 'Build queued for repository %s' % (event_data['repository'])
|
||||
|
@ -127,8 +115,8 @@ class BuildQueueEvent(NotificationEvent):
|
|||
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'])
|
||||
""" % (event_data['homepage'], event_data['trigger_kind'],
|
||||
event_data['repository'], event_data['build_id'])
|
||||
|
||||
return html
|
||||
|
||||
|
@ -141,19 +129,13 @@ class BuildStartEvent(NotificationEvent):
|
|||
|
||||
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),
|
||||
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
'trigger_kind': 'GitHub'
|
||||
}
|
||||
return event_data
|
||||
}, subpage='/build?current=%s' % build_uuid)
|
||||
|
||||
def get_summary(self, event_data, notification_data):
|
||||
return 'Build started for repository %s' % (event_data['repository'])
|
||||
|
@ -175,20 +157,14 @@ class BuildSuccessEvent(NotificationEvent):
|
|||
|
||||
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),
|
||||
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
'trigger_kind': 'GitHub'
|
||||
}
|
||||
return event_data
|
||||
|
||||
}, subpage='/build?current=%s' % build_uuid)
|
||||
|
||||
def get_summary(self, event_data, notification_data):
|
||||
return 'Build succeeded for repository %s' % (event_data['repository'])
|
||||
|
||||
|
@ -208,21 +184,13 @@ class BuildFailureEvent(NotificationEvent):
|
|||
return 'build_failure'
|
||||
|
||||
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),
|
||||
return build_event_data(repository, {
|
||||
'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
|
||||
}, subpage='/build?current=%s' % build_uuid)
|
||||
|
||||
def get_summary(self, event_data, notification_data):
|
||||
return 'Build failure for repository %s' % (event_data['repository'])
|
||||
|
|
|
@ -3,22 +3,33 @@ from data import model
|
|||
|
||||
import json
|
||||
|
||||
def spawn_notification(repo, event_name, extra_data={}, subpage=None, pathargs=[]):
|
||||
def build_event_data(repo, extra_data={}, subpage=None):
|
||||
repo_string = '%s/%s' % (repo.namespace, repo.name)
|
||||
homepage = 'https://quay.io/repository/%s' % repo_string
|
||||
homepage = '%s://%s/repository/%s' % (app.config['PREFERRED_URL_SCHEME'],
|
||||
app.config['SERVER_HOSTNAME'],
|
||||
repo_string)
|
||||
|
||||
if subpage:
|
||||
if not subpage.startswith('/'):
|
||||
subpage = '/' + subpage
|
||||
|
||||
homepage = homepage + subpage
|
||||
|
||||
event_data = {
|
||||
'repository': repo_string,
|
||||
'namespace': repo.namespace,
|
||||
'name': repo.name,
|
||||
'docker_url': 'quay.io/%s' % repo_string,
|
||||
'docker_url': '%s/%s' % (app.config['SERVER_HOSTNAME'], repo_string),
|
||||
'homepage': homepage,
|
||||
'visibility': repo.visibility.name
|
||||
}
|
||||
|
||||
event_data.update(extra_data)
|
||||
return event_data
|
||||
|
||||
|
||||
def spawn_notification(repo, event_name, extra_data={}, subpage=None, pathargs=[]):
|
||||
event_data = build_event_data(repo, extra_data=extra_data, subpage=subpage)
|
||||
|
||||
notifications = model.list_repo_notifications(repo.namespace, repo.name, event_name=event_name)
|
||||
for notification in notifications:
|
||||
|
|
|
@ -1003,7 +1003,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
|||
var methods = [
|
||||
{
|
||||
'id': 'quay_notification',
|
||||
'title': 'Quay.io notification',
|
||||
'title': 'Quay.io Notification',
|
||||
'icon': 'quay-icon',
|
||||
'fields': [
|
||||
{
|
||||
|
|
Reference in a new issue