- Change updated_tags into the expected dict, not a list
- Update the event code on both sides to expect the dict - Add filter support to the string builder
This commit is contained in:
parent
420d02cd71
commit
7e8713171e
3 changed files with 35 additions and 7 deletions
|
@ -59,7 +59,7 @@ class RepoPushEvent(NotificationEvent):
|
|||
return 'Repository %s updated' % (event_data['repository'])
|
||||
|
||||
def get_message(self, event_data, notification_data):
|
||||
if not event_data.get('updated_tags', []):
|
||||
if not event_data.get('updated_tags', {}).keys():
|
||||
html = """
|
||||
Repository <a href="%s">%s</a> has been updated via a push.
|
||||
""" % (event_data['homepage'],
|
||||
|
@ -71,13 +71,13 @@ class RepoPushEvent(NotificationEvent):
|
|||
Tags Updated: %s
|
||||
""" % (event_data['homepage'],
|
||||
event_data['repository'],
|
||||
', '.join(event_data['updated_tags']))
|
||||
', '.join(event_data['updated_tags'].keys()))
|
||||
|
||||
return html
|
||||
|
||||
def get_sample_data(self, repository):
|
||||
return build_event_data(repository, {
|
||||
'updated_tags': ['latest', 'foo', 'bar'],
|
||||
'updated_tags': {'latest': 'someimageid', 'foo': 'anotherimage'},
|
||||
'pushed_image_count': 10,
|
||||
'pruned_image_count': 3
|
||||
})
|
||||
|
|
|
@ -313,7 +313,7 @@ def populate_database():
|
|||
outside_org.verified = True
|
||||
outside_org.save()
|
||||
|
||||
model.create_notification('test_notification', new_user_1, metadata={'some': 'value'})
|
||||
model.create_notification('test_notification', new_user_1, metadata={'some': 'value', 'arr': [1,2,3], 'obj': {'a': 1, 'b': 2}})
|
||||
|
||||
from_date = datetime.utcnow()
|
||||
to_date = from_date + timedelta(hours=1)
|
||||
|
|
|
@ -548,6 +548,18 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
|||
'client_id': 'chain'
|
||||
};
|
||||
|
||||
var filters = {
|
||||
'obj': function(value) {
|
||||
if (!value) { return []; }
|
||||
return Object.getOwnPropertyNames(value);
|
||||
},
|
||||
|
||||
'updated_tags': function(value) {
|
||||
if (!value) { return []; }
|
||||
return Object.getOwnPropertyNames(value);
|
||||
}
|
||||
};
|
||||
|
||||
var description = value_or_func;
|
||||
if (typeof description != 'string') {
|
||||
description = description(metadata);
|
||||
|
@ -555,7 +567,17 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
|||
|
||||
for (var key in metadata) {
|
||||
if (metadata.hasOwnProperty(key)) {
|
||||
var value = metadata[key] != null ? metadata[key].toString() : '(Unknown)';
|
||||
var value = metadata[key] != null ? metadata[key] : '(Unknown)';
|
||||
if (filters[key]) {
|
||||
value = filters[key](value);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value = value.join(', ');
|
||||
}
|
||||
|
||||
value = value.toString();
|
||||
|
||||
if (key.indexOf('image') >= 0) {
|
||||
value = value.substr(0, 12);
|
||||
}
|
||||
|
@ -1083,7 +1105,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
|||
var notificationKinds = {
|
||||
'test_notification': {
|
||||
'level': 'primary',
|
||||
'message': 'This notification is a long message for testing',
|
||||
'message': 'This notification is a long message for testing: {obj}',
|
||||
'page': '/about/',
|
||||
'dismissable': true
|
||||
},
|
||||
|
@ -1119,7 +1141,13 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
|||
},
|
||||
'repo_push': {
|
||||
'level': 'info',
|
||||
'message': 'Repository {repository} has been pushed with the following tags updated: {updated_tags}',
|
||||
'message': function(metadata) {
|
||||
if (metadata.updated_tags && Object.getOwnPropertyNames(metadata.updated_tags).length) {
|
||||
return 'Repository {repository} has been pushed with the following tags updated: {updated_tags}';
|
||||
} else {
|
||||
return 'Repository {repository} has been pushed';
|
||||
}
|
||||
},
|
||||
'page': function(metadata) {
|
||||
return '/repository/' + metadata.repository;
|
||||
},
|
||||
|
|
Reference in a new issue