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-27 21:07:06 +00:00
|
|
|
angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'KeyService', 'Features', 'CookieService', 'Config',
|
|
|
|
function(UtilService, $sanitize, KeyService, Features, CookieService, Config) {
|
2015-02-19 21:21:54 +00:00
|
|
|
var triggerService = {};
|
|
|
|
|
|
|
|
var triggerTypes = {
|
|
|
|
'github': {
|
2015-03-19 16:06:58 +00:00
|
|
|
'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/' +
|
2015-03-19 21:12:27 +00:00
|
|
|
namespace + '/' + repository;
|
2015-02-19 21:21:54 +00:00
|
|
|
|
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
|
|
|
},
|
2015-04-21 22:04:25 +00:00
|
|
|
'is_external': true,
|
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) {
|
2015-03-19 21:12:27 +00:00
|
|
|
return 'GitHub Enterprise Repository Push';
|
2015-03-13 22:34:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:12:27 +00:00
|
|
|
return 'GitHub Repository Push';
|
2015-04-28 22:15:12 +00:00
|
|
|
},
|
2015-04-29 23:50:13 +00:00
|
|
|
'supports_full_directory_listing': true,
|
|
|
|
'templates': {
|
|
|
|
'credentials': '/static/directives/trigger/githost/credentials.html',
|
|
|
|
'trigger-description': '/static/directives/trigger/github/trigger-description.html'
|
2015-04-30 19:33:19 +00:00
|
|
|
},
|
|
|
|
'link_templates': {
|
|
|
|
'commit': '/commit/{sha}',
|
|
|
|
'branch': '/tree/{branch}',
|
|
|
|
'tag': '/releases/tag/{tag}',
|
2015-04-29 23:50:13 +00:00
|
|
|
}
|
2015-03-26 20:20:53 +00:00
|
|
|
},
|
|
|
|
|
2015-04-24 19:13:08 +00:00
|
|
|
'bitbucket': {
|
|
|
|
'run_parameters': [
|
|
|
|
{
|
|
|
|
'title': 'Branch',
|
|
|
|
'type': 'option',
|
|
|
|
'name': 'branch_name'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'get_redirect_url': function(namespace, repository) {
|
|
|
|
return Config.getUrl('/bitbucket/setup/' + namespace + '/' + repository);
|
|
|
|
},
|
|
|
|
'is_external': false,
|
|
|
|
'is_enabled': function() {
|
|
|
|
return Features.BITBUCKET_BUILD;
|
|
|
|
},
|
|
|
|
'icon': 'fa-bitbucket',
|
2015-04-28 22:15:12 +00:00
|
|
|
'title': function() { return 'Bitbucket Repository Push'; },
|
2015-04-29 23:50:13 +00:00
|
|
|
'supports_full_directory_listing': false,
|
|
|
|
'templates': {
|
|
|
|
'credentials': '/static/directives/trigger/githost/credentials.html',
|
|
|
|
'trigger-description': '/static/directives/trigger/bitbucket/trigger-description.html'
|
2015-04-30 19:33:19 +00:00
|
|
|
},
|
|
|
|
'link_templates': {
|
|
|
|
'commit': '/commits/{sha}',
|
|
|
|
'branch': '/branch/{branch}',
|
|
|
|
'tag': '/commits/tag/{tag}',
|
2015-04-29 23:50:13 +00:00
|
|
|
}
|
2015-04-24 19:13:08 +00:00
|
|
|
},
|
|
|
|
|
2015-05-02 17:31:54 +00:00
|
|
|
'gitlab': {
|
|
|
|
'run_parameters': [
|
|
|
|
{
|
|
|
|
'title': 'Branch',
|
|
|
|
'type': 'option',
|
|
|
|
'name': 'branch_name'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'get_redirect_url': function(namespace, repository) {
|
2015-05-02 21:54:48 +00:00
|
|
|
var redirect_uri = KeyService['gitlabRedirectUri'] + '/trigger';
|
2015-05-02 17:31:54 +00:00
|
|
|
var authorize_url = KeyService['gitlabTriggerAuthorizeUrl'];
|
|
|
|
var client_id = KeyService['gitlabTriggerClientId'];
|
|
|
|
|
2015-05-02 21:54:48 +00:00
|
|
|
return authorize_url + '?client_id=' + client_id + '&redirect_uri=' + redirect_uri + '&response_type=code&state=repo:' + namespace + '/' + repository;
|
2015-05-02 17:31:54 +00:00
|
|
|
},
|
|
|
|
'is_external': false,
|
|
|
|
'is_enabled': function() {
|
|
|
|
return Features.GITLAB_BUILD;
|
|
|
|
},
|
|
|
|
'icon': 'fa-git-square',
|
|
|
|
'title': function() { return 'GitLab Repository Push'; },
|
|
|
|
'supports_full_directory_listing': false,
|
|
|
|
'templates': {
|
|
|
|
'credentials': '/static/directives/trigger/githost/credentials.html',
|
|
|
|
'trigger-description': '/static/directives/trigger/gitlab/trigger-description.html'
|
2015-05-03 16:58:48 +00:00
|
|
|
},
|
|
|
|
'link_templates': {
|
|
|
|
'commit': '/commit/{sha}',
|
|
|
|
'branch': '/tree/{branch}',
|
|
|
|
'tag': '/commits/{tag}',
|
2015-05-02 17:31:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-04-21 22:04:25 +00:00
|
|
|
'custom-git': {
|
2015-03-26 20:20:53 +00:00
|
|
|
'run_parameters': [
|
|
|
|
{
|
2015-04-01 18:33:21 +00:00
|
|
|
'title': 'Commit',
|
2015-04-22 17:22:04 +00:00
|
|
|
'type': 'regex',
|
|
|
|
'name': 'commit_sha',
|
|
|
|
'regex': '^([A-Fa-f0-9]{7})$',
|
|
|
|
'placeholder': '1c002dd'
|
2015-03-26 20:20:53 +00:00
|
|
|
}
|
|
|
|
],
|
2015-03-27 15:22:07 +00:00
|
|
|
'get_redirect_url': function(namespace, repository) {
|
2015-03-27 21:07:06 +00:00
|
|
|
return Config.getUrl('/customtrigger/setup/' + namespace + '/' + repository);
|
2015-03-27 15:22:07 +00:00
|
|
|
},
|
2015-04-21 22:04:25 +00:00
|
|
|
'is_external': false,
|
2015-03-26 20:20:53 +00:00
|
|
|
'is_enabled': function() { return true; },
|
|
|
|
'icon': 'fa-git',
|
2015-04-29 23:50:13 +00:00
|
|
|
'title': function() { return 'Custom Git Repository Push'; },
|
|
|
|
'templates': {
|
|
|
|
'credentials': '/static/directives/trigger/custom-git/credentials.html',
|
|
|
|
'trigger-description': '/static/directives/trigger/custom-git/trigger-description.html'
|
|
|
|
}
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
2015-04-29 23:50:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
triggerService.populateTemplate = function(scope, name) {
|
|
|
|
scope.$watch('trigger', function(trigger) {
|
|
|
|
if (!trigger) { return; }
|
|
|
|
scope.triggerTemplate = triggerService.getTemplate(trigger.service, name);
|
|
|
|
});
|
|
|
|
};
|
2015-02-19 21:21:54 +00:00
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
triggerService.getFullLinkTemplate = function(build, templateName) {
|
|
|
|
var name = build.trigger.service;
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-05-03 17:38:11 +00:00
|
|
|
var repositoryUrl = build.trigger.repository_url;
|
|
|
|
if (!repositoryUrl) {
|
2015-04-30 19:33:19 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var linkTemplate = type.link_templates;
|
|
|
|
if (!linkTemplate || !linkTemplate[templateName]) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-05-03 17:38:11 +00:00
|
|
|
return repositoryUrl + linkTemplate[templateName];
|
2015-04-30 19:33:19 +00:00
|
|
|
};
|
|
|
|
|
2015-04-28 22:15:12 +00:00
|
|
|
triggerService.supportsFullListing = function(name) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!type['supports_full_directory_listing'];
|
|
|
|
};
|
|
|
|
|
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-04-29 23:50:13 +00:00
|
|
|
triggerService.getTemplate = function(name, template) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return type['templates'][template];
|
|
|
|
};
|
|
|
|
|
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-04-21 22:04:25 +00:00
|
|
|
triggerService.getDockerfileLocation = function(trigger) {
|
2015-05-03 18:02:05 +00:00
|
|
|
var subdirectory = trigger.config.subdir;
|
|
|
|
if (!subdirectory) {
|
2015-04-21 22:04:25 +00:00
|
|
|
return '//Dockerfile';
|
|
|
|
}
|
2015-05-03 18:02:05 +00:00
|
|
|
|
|
|
|
if (subdirectory[subdirectory.length - 1] != '/') {
|
|
|
|
subdirectory = subdirectory + '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '//' + subdirectory.replace(new RegExp('(^\/+|\/+$)'), '') + 'Dockerfile';
|
2015-04-06 19:10:03 +00:00
|
|
|
};
|
|
|
|
|
2015-04-24 19:13:08 +00:00
|
|
|
triggerService.isEnabled = function(name) {
|
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return type['is_enabled']();
|
|
|
|
};
|
|
|
|
|
2015-05-03 18:02:05 +00:00
|
|
|
triggerService.getIcon = function(name) {
|
2015-03-13 22:34:28 +00:00
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
2015-05-03 18:02:05 +00:00
|
|
|
return type['icon'];
|
2015-03-13 22:34:28 +00:00
|
|
|
};
|
|
|
|
|
2015-05-03 18:02:05 +00:00
|
|
|
triggerService.getTitle = function(name) {
|
2015-02-19 21:21:54 +00:00
|
|
|
var type = triggerTypes[name];
|
|
|
|
if (!type) {
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
2015-05-03 18:02:05 +00:00
|
|
|
return type['title']();
|
|
|
|
};
|
|
|
|
|
|
|
|
triggerService.getDescription = function(name, config) {
|
|
|
|
var icon = triggerService.getIcon(config['service']);
|
|
|
|
var title = triggerService.getTitle(config['service']);
|
|
|
|
var source = UtilService.textToSafeHtml(config['build_source']);
|
|
|
|
var desc = '<i class"fa ' + icon + ' fa-lg" style="margin-left:2px; margin-right: 2px"></i> Push to ' + title + ' ' + source;
|
|
|
|
return desc;
|
2015-02-19 21:21:54 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}]);
|