2015-02-19 21:21:54 +00:00
|
|
|
/**
|
|
|
|
* Helper service for defining the various kinds of build triggers and retrieving information
|
|
|
|
* about them.
|
|
|
|
*/
|
2015-03-13 22:34:28 +00:00
|
|
|
angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'KeyService', 'Features', 'CookieService',
|
|
|
|
function(UtilService, $sanitize, KeyService, Features, CookieService) {
|
2015-02-19 21:21:54 +00:00
|
|
|
var triggerService = {};
|
|
|
|
|
|
|
|
var triggerTypes = {
|
|
|
|
'github': {
|
|
|
|
'description': function(config) {
|
|
|
|
var source = UtilService.textToSafeHtml(config['build_source']);
|
2015-03-19 16:06:58 +00:00
|
|
|
var desc = '<i class="fa fa-github fa-lg" style="margin-left: 2px; margin-right: 2px"></i> Push to Github Repository (Deprecated) ';
|
2015-02-19 21:21:54 +00:00
|
|
|
desc += '<a href="https://github.com/' + source + '" target="_blank">' + source + '</a>';
|
|
|
|
desc += '<br>Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']);
|
|
|
|
return desc;
|
|
|
|
},
|
|
|
|
'run_parameters': [
|
|
|
|
{
|
|
|
|
'title': 'Branch',
|
|
|
|
'type': 'option',
|
|
|
|
'name': 'branch_name'
|
|
|
|
}
|
|
|
|
],
|
2015-03-19 16:06:58 +00:00
|
|
|
'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;
|
|
|
|
}
|
|
|
|
},
|
2015-02-19 21:21:54 +00:00
|
|
|
|
2015-03-19 16:06:58 +00:00
|
|
|
'github-git': {
|
|
|
|
'description': function(config) {
|
|
|
|
var source = UtilService.textToSafeHtml(config['build_source']);
|
|
|
|
var desc = '<i class="fa fa-github fa-lg" style="margin-left: 2px; margin-right: 2px"></i> Push to Github Repository ';
|
|
|
|
desc += '<a href="https://github.com/' + source + '" target="_blank">' + source + '</a>';
|
|
|
|
desc += '<br>Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']);
|
|
|
|
return desc;
|
|
|
|
},
|
|
|
|
'run_parameters': [
|
|
|
|
{
|
|
|
|
'title': 'Branch',
|
|
|
|
'type': 'option',
|
|
|
|
'name': 'branch_name'
|
|
|
|
}
|
|
|
|
],
|
2015-02-19 21:21:54 +00:00
|
|
|
'get_redirect_url': function(namespace, repository) {
|
|
|
|
var redirect_uri = KeyService['githubRedirectUri'] + '/trigger/' +
|
|
|
|
namespace + '/' + repository;
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
// TODO(jschorr): Remove once the new layout is in place.
|
|
|
|
if (CookieService.get('quay.exp-new-layout') == 'true') {
|
|
|
|
redirect_uri += '/__new';
|
|
|
|
}
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
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;
|
2015-03-13 22:34:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'is_enabled': function() {
|
|
|
|
return Features.GITHUB_BUILD;
|
|
|
|
},
|
|
|
|
|
|
|
|
'icon': 'fa-github',
|
|
|
|
|
|
|
|
'title': function() {
|
|
|
|
var isEnterprise = KeyService.isEnterprise('github-trigger');
|
|
|
|
if (isEnterprise) {
|
|
|
|
return 'GitHub Enterprise Repository Push';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'GitHub Repository Push';
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
triggerService.getTypes = function() {
|
|
|
|
var types = [];
|
|
|
|
for (var key in triggerTypes) {
|
|
|
|
if (!triggerTypes.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
types.push(key);
|
|
|
|
}
|
|
|
|
return types;
|
|
|
|
};
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
triggerService.getRedirectUrl = function(name, namespace, repository) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return type['get_redirect_url'](namespace, repository);
|
|
|
|
};
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
triggerService.getTitle = function(name) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
|
|
|
return type['title']();
|
|
|
|
};
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
triggerService.getDescription = function(name, config) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
|
|
|
return type['description'](config);
|
|
|
|
};
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
triggerService.getMetadata = function(name) {
|
|
|
|
return triggerTypes[name];
|
|
|
|
};
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
triggerService.getRunParameters = function(name, config) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return type['run_parameters'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return triggerService;
|
|
|
|
}]);
|