/** * Helper service for defining the various kinds of build triggers and retrieving information * about them. */ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'KeyService', function(UtilService, $sanitize, KeyService) { var triggerService = {}; var triggerTypes = { 'github': { 'description': function(config) { var source = UtilService.textToSafeHtml(config['build_source']); var desc = ' Push to Github Repository '; desc += '' + source + ''; desc += '
Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']); return desc; }, 'run_parameters': [ { 'title': 'Branch', 'type': 'option', 'name': 'branch_name' } ], 'get_redirect_url': function(namespace, repository) { var redirect_uri = KeyService['githubRedirectUri'] + '/trigger/' + namespace + '/' + repository; var authorize_url = KeyService['githubTriggerAuthorizeUrl']; var client_id = KeyService['githubTriggerClientId']; return authorize_url + 'client_id=' + client_id + '&scope=repo,user:email&redirect_uri=' + redirect_uri; } } } triggerService.getRedirectUrl = function(name, namespace, repository) { var type = triggerTypes[name]; if (!type) { return ''; } return type['get_redirect_url'](namespace, repository); }; triggerService.getDescription = function(name, config) { var type = triggerTypes[name]; if (!type) { return 'Unknown'; } return type['description'](config); }; triggerService.getRunParameters = function(name, config) { var type = triggerTypes[name]; if (!type) { return []; } return type['run_parameters']; } return triggerService; }]);