From a2f0f574146d122a1b363ad7abbdbe51c174e0e6 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 29 Jul 2014 13:39:26 -0400 Subject: [PATCH] - Small title fix - Make sure sample event data uses the real event data generation code --- endpoints/notificationevent.py | 68 +++++++++------------------------ endpoints/notificationhelper.py | 17 +++++++-- static/js/app.js | 2 +- 3 files changed, 33 insertions(+), 54 deletions(-) diff --git a/endpoints/notificationevent.py b/endpoints/notificationevent.py index e453da669..0788a1a33 100644 --- a/endpoints/notificationevent.py +++ b/endpoints/notificationevent.py @@ -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 new build has been queued via a %s trigger to start on repository %s.

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']) diff --git a/endpoints/notificationhelper.py b/endpoints/notificationhelper.py index 214d2bf5e..003d52362 100644 --- a/endpoints/notificationhelper.py +++ b/endpoints/notificationhelper.py @@ -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: diff --git a/static/js/app.js b/static/js/app.js index b66f5c628..f46fea5a1 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -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': [ {