- 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 tarfile
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
from notificationhelper import build_event_data
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class InvalidNotificationEventException(Exception):
|
class InvalidNotificationEventException(Exception):
|
||||||
|
@ -74,19 +76,11 @@ class RepoPushEvent(NotificationEvent):
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def get_sample_data(self, repository):
|
def get_sample_data(self, repository):
|
||||||
repo_string = '%s/%s' % (repository.namespace, repository.name)
|
return build_event_data(repository, {
|
||||||
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,
|
|
||||||
'updated_tags': ['latest', 'foo', 'bar'],
|
'updated_tags': ['latest', 'foo', 'bar'],
|
||||||
'pushed_image_count': 10,
|
'pushed_image_count': 10,
|
||||||
'pruned_image_count': 3
|
'pruned_image_count': 3
|
||||||
}
|
})
|
||||||
return event_data
|
|
||||||
|
|
||||||
|
|
||||||
class BuildQueueEvent(NotificationEvent):
|
class BuildQueueEvent(NotificationEvent):
|
||||||
|
@ -96,20 +90,14 @@ class BuildQueueEvent(NotificationEvent):
|
||||||
|
|
||||||
def get_sample_data(self, repository):
|
def get_sample_data(self, repository):
|
||||||
build_uuid = 'fake-build-id'
|
build_uuid = 'fake-build-id'
|
||||||
repo_string = '%s/%s' % (repository.namespace, repository.name)
|
|
||||||
event_data = {
|
return build_event_data(repository, {
|
||||||
'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,
|
'is_manual': False,
|
||||||
'build_id': build_uuid,
|
'build_id': build_uuid,
|
||||||
'build_name': 'some-fake-build',
|
'build_name': 'some-fake-build',
|
||||||
'docker_tags': ['latest', 'foo', 'bar'],
|
'docker_tags': ['latest', 'foo', 'bar'],
|
||||||
'trigger_kind': 'GitHub'
|
'trigger_kind': 'GitHub'
|
||||||
}
|
}, subpage='/build?current=%s' % build_uuid)
|
||||||
return event_data
|
|
||||||
|
|
||||||
def get_summary(self, event_data, notification_data):
|
def get_summary(self, event_data, notification_data):
|
||||||
return 'Build queued for repository %s' % (event_data['repository'])
|
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.
|
A <a href="%s">new build</a> has been queued via a %s trigger to start on repository %s.
|
||||||
<br><br>
|
<br><br>
|
||||||
Build ID: %s
|
Build ID: %s
|
||||||
""" % (event_data['homepage'], event_data['repository'],
|
""" % (event_data['homepage'], event_data['trigger_kind'],
|
||||||
event_data['trigger_kind'], event_data['build_id'])
|
event_data['repository'], event_data['build_id'])
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
@ -141,19 +129,13 @@ class BuildStartEvent(NotificationEvent):
|
||||||
|
|
||||||
def get_sample_data(self, repository):
|
def get_sample_data(self, repository):
|
||||||
build_uuid = 'fake-build-id'
|
build_uuid = 'fake-build-id'
|
||||||
repo_string = '%s/%s' % (repository.namespace, repository.name)
|
|
||||||
event_data = {
|
return build_event_data(repository, {
|
||||||
'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_id': build_uuid,
|
||||||
'build_name': 'some-fake-build',
|
'build_name': 'some-fake-build',
|
||||||
'docker_tags': ['latest', 'foo', 'bar'],
|
'docker_tags': ['latest', 'foo', 'bar'],
|
||||||
'trigger_kind': 'GitHub'
|
'trigger_kind': 'GitHub'
|
||||||
}
|
}, subpage='/build?current=%s' % build_uuid)
|
||||||
return event_data
|
|
||||||
|
|
||||||
def get_summary(self, event_data, notification_data):
|
def get_summary(self, event_data, notification_data):
|
||||||
return 'Build started for repository %s' % (event_data['repository'])
|
return 'Build started for repository %s' % (event_data['repository'])
|
||||||
|
@ -175,19 +157,13 @@ class BuildSuccessEvent(NotificationEvent):
|
||||||
|
|
||||||
def get_sample_data(self, repository):
|
def get_sample_data(self, repository):
|
||||||
build_uuid = 'fake-build-id'
|
build_uuid = 'fake-build-id'
|
||||||
repo_string = '%s/%s' % (repository.namespace, repository.name)
|
|
||||||
event_data = {
|
return build_event_data(repository, {
|
||||||
'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_id': build_uuid,
|
||||||
'build_name': 'some-fake-build',
|
'build_name': 'some-fake-build',
|
||||||
'docker_tags': ['latest', 'foo', 'bar'],
|
'docker_tags': ['latest', 'foo', 'bar'],
|
||||||
'trigger_kind': 'GitHub'
|
'trigger_kind': 'GitHub'
|
||||||
}
|
}, subpage='/build?current=%s' % build_uuid)
|
||||||
return event_data
|
|
||||||
|
|
||||||
def get_summary(self, event_data, notification_data):
|
def get_summary(self, event_data, notification_data):
|
||||||
return 'Build succeeded for repository %s' % (event_data['repository'])
|
return 'Build succeeded for repository %s' % (event_data['repository'])
|
||||||
|
@ -208,21 +184,13 @@ class BuildFailureEvent(NotificationEvent):
|
||||||
return 'build_failure'
|
return 'build_failure'
|
||||||
|
|
||||||
def get_sample_data(self, repository):
|
def get_sample_data(self, repository):
|
||||||
build_uuid = 'fake-build-id'
|
return build_event_data(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/build?current=%s' % (repo_string, build_uuid),
|
|
||||||
'build_id': build_uuid,
|
'build_id': build_uuid,
|
||||||
'build_name': 'some-fake-build',
|
'build_name': 'some-fake-build',
|
||||||
'docker_tags': ['latest', 'foo', 'bar'],
|
'docker_tags': ['latest', 'foo', 'bar'],
|
||||||
'trigger_kind': 'GitHub',
|
'trigger_kind': 'GitHub',
|
||||||
'error_message': 'This is a fake error message'
|
'error_message': 'This is a fake error message'
|
||||||
}
|
}, subpage='/build?current=%s' % build_uuid)
|
||||||
return event_data
|
|
||||||
|
|
||||||
def get_summary(self, event_data, notification_data):
|
def get_summary(self, event_data, notification_data):
|
||||||
return 'Build failure for repository %s' % (event_data['repository'])
|
return 'Build failure for repository %s' % (event_data['repository'])
|
||||||
|
|
|
@ -3,22 +3,33 @@ from data import model
|
||||||
|
|
||||||
import json
|
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)
|
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 subpage:
|
||||||
|
if not subpage.startswith('/'):
|
||||||
|
subpage = '/' + subpage
|
||||||
|
|
||||||
homepage = homepage + subpage
|
homepage = homepage + subpage
|
||||||
|
|
||||||
event_data = {
|
event_data = {
|
||||||
'repository': repo_string,
|
'repository': repo_string,
|
||||||
'namespace': repo.namespace,
|
'namespace': repo.namespace,
|
||||||
'name': repo.name,
|
'name': repo.name,
|
||||||
'docker_url': 'quay.io/%s' % repo_string,
|
'docker_url': '%s/%s' % (app.config['SERVER_HOSTNAME'], repo_string),
|
||||||
'homepage': homepage,
|
'homepage': homepage,
|
||||||
'visibility': repo.visibility.name
|
'visibility': repo.visibility.name
|
||||||
}
|
}
|
||||||
|
|
||||||
event_data.update(extra_data)
|
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)
|
notifications = model.list_repo_notifications(repo.namespace, repo.name, event_name=event_name)
|
||||||
for notification in notifications:
|
for notification in notifications:
|
||||||
|
|
|
@ -1003,7 +1003,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
||||||
var methods = [
|
var methods = [
|
||||||
{
|
{
|
||||||
'id': 'quay_notification',
|
'id': 'quay_notification',
|
||||||
'title': 'Quay.io notification',
|
'title': 'Quay.io Notification',
|
||||||
'icon': 'quay-icon',
|
'icon': 'quay-icon',
|
||||||
'fields': [
|
'fields': [
|
||||||
{
|
{
|
||||||
|
|
Reference in a new issue