Get basic support for GitLab working in the UI
This commit is contained in:
parent
e3aededcbc
commit
f091aaa07e
4 changed files with 33 additions and 7 deletions
|
@ -34,7 +34,12 @@ def attach_gitlab_build_trigger():
|
||||||
permission = AdministerRepositoryPermission(namespace, repository)
|
permission = AdministerRepositoryPermission(namespace, repository)
|
||||||
if permission.can():
|
if permission.can():
|
||||||
code = request.args.get('code')
|
code = request.args.get('code')
|
||||||
token = gitlab_trigger.exchange_code_for_token(app.config, client, code)
|
token = gitlab_trigger.exchange_code_for_token(app.config, client, code,
|
||||||
|
redirect_suffix='/trigger')
|
||||||
|
if not token:
|
||||||
|
msg = 'Could not exchange token. It may have expired.'
|
||||||
|
abort(404, message=msg)
|
||||||
|
|
||||||
repo = model.get_repository(namespace, repository)
|
repo = model.get_repository(namespace, repository)
|
||||||
if not repo:
|
if not repo:
|
||||||
msg = 'Invalid repository: %s/%s' % (namespace, repository)
|
msg = 'Invalid repository: %s/%s' % (namespace, repository)
|
||||||
|
|
|
@ -1168,6 +1168,8 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
def list_build_sources(self):
|
def list_build_sources(self):
|
||||||
gl_client = self._get_authorized_client()
|
gl_client = self._get_authorized_client()
|
||||||
current_user = gl_client.currentuser()
|
current_user = gl_client.currentuser()
|
||||||
|
if current_user is False:
|
||||||
|
raise RepositoryReadException('Unable to get current user')
|
||||||
|
|
||||||
repositories = gl_client.getprojects()
|
repositories = gl_client.getprojects()
|
||||||
if repositories is False:
|
if repositories is False:
|
||||||
|
@ -1178,7 +1180,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
owner = repo['namespace']['name']
|
owner = repo['namespace']['name']
|
||||||
if not owner in namespaces:
|
if not owner in namespaces:
|
||||||
namespaces[owner] = {
|
namespaces[owner] = {
|
||||||
'personal': owner == current_user.username,
|
'personal': owner == current_user['username'],
|
||||||
'repos': [],
|
'repos': [],
|
||||||
'info': {
|
'info': {
|
||||||
'name': owner,
|
'name': owner,
|
||||||
|
@ -1244,7 +1246,10 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
def load_dockerfile_contents(self):
|
def load_dockerfile_contents(self):
|
||||||
gl_client = self._get_authorized_client()
|
gl_client = self._get_authorized_client()
|
||||||
subdir = self.config.get('subdir', '')
|
subdir = self.config.get('subdir', '')
|
||||||
path = subdir + '/Dockerfile' if subdir else 'Dockerfile'
|
if subdir == '/':
|
||||||
|
subdir = ''
|
||||||
|
|
||||||
|
path = subdir + 'Dockerfile' if subdir else 'Dockerfile'
|
||||||
|
|
||||||
repository = gl_client.getproject(self.config['build_source'])
|
repository = gl_client.getproject(self.config['build_source'])
|
||||||
if repository is False:
|
if repository is False:
|
||||||
|
@ -1254,6 +1259,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
branches = find_matching_branches(self.config, branches)
|
branches = find_matching_branches(self.config, branches)
|
||||||
if branches == []:
|
if branches == []:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
branch_name = branches[0]
|
branch_name = branches[0]
|
||||||
if repository['default_branch'] in branches:
|
if repository['default_branch'] in branches:
|
||||||
branch_name = repository['default_branch']
|
branch_name = repository['default_branch']
|
||||||
|
@ -1261,6 +1267,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
contents = gl_client.getrawfile(repository['id'], branch_name, path)
|
contents = gl_client.getrawfile(repository['id'], branch_name, path)
|
||||||
if contents is False:
|
if contents is False:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
def list_field_values(self, field_name):
|
def list_field_values(self, field_name):
|
||||||
|
@ -1277,7 +1284,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if field_name == 'tag_name':
|
if field_name == 'tag_name':
|
||||||
tags = gl_client.getall(gl_client.getrepositorytags(repo['id']))
|
tags = gl_client.getrepositorytags(repo['id'])
|
||||||
if tags is False:
|
if tags is False:
|
||||||
return []
|
return []
|
||||||
return [tag['name'] for tag in tags]
|
return [tag['name'] for tag in tags]
|
||||||
|
@ -1324,14 +1331,14 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
metadata['commit_info']['committer'] = {
|
metadata['commit_info']['committer'] = {
|
||||||
'username': committer['username'],
|
'username': committer['username'],
|
||||||
'avatar_url': committer['avatar_url'],
|
'avatar_url': committer['avatar_url'],
|
||||||
'url': client.host + '/' + committer['username'],
|
'url': gl_client.host + '/' + committer['username'],
|
||||||
}
|
}
|
||||||
|
|
||||||
if author is not None:
|
if author is not None:
|
||||||
metadata['commit_info']['author'] = {
|
metadata['commit_info']['author'] = {
|
||||||
'username': author['username'],
|
'username': author['username'],
|
||||||
'avatar_url': author['avatar_url'],
|
'avatar_url': author['avatar_url'],
|
||||||
'url': client.host + '/' + author['username']
|
'url': gl_client.host + '/' + author['username']
|
||||||
}
|
}
|
||||||
|
|
||||||
prepared = PreparedBuild(self.trigger)
|
prepared = PreparedBuild(self.trigger)
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"
|
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"
|
||||||
analyze="checkAnalyze(isValid)"></div>
|
analyze="checkAnalyze(isValid)"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div ng-switch-when="gitlab">
|
||||||
|
<div class="trigger-setup-githost" repository="repository" trigger="trigger"
|
||||||
|
kind="gitlab"
|
||||||
|
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"
|
||||||
|
analyze="checkAnalyze(isValid)"></div>
|
||||||
|
</div>
|
||||||
<div ng-switch-when="custom-git">
|
<div ng-switch-when="custom-git">
|
||||||
<div class="trigger-setup-custom" repository="repository" trigger="trigger"
|
<div class="trigger-setup-custom" repository="repository" trigger="trigger"
|
||||||
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"
|
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"
|
||||||
|
|
|
@ -136,6 +136,14 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
|
||||||
'templates': {
|
'templates': {
|
||||||
'credentials': '/static/directives/trigger/githost/credentials.html',
|
'credentials': '/static/directives/trigger/githost/credentials.html',
|
||||||
'trigger-description': '/static/directives/trigger/gitlab/trigger-description.html'
|
'trigger-description': '/static/directives/trigger/gitlab/trigger-description.html'
|
||||||
|
},
|
||||||
|
'repository_url': function(build) {
|
||||||
|
return 'https://bitbucket.org/' + build.trigger.build_source;
|
||||||
|
},
|
||||||
|
'link_templates': {
|
||||||
|
'commit': '/commit/{sha}',
|
||||||
|
'branch': '/tree/{branch}',
|
||||||
|
'tag': '/commits/{tag}',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -184,7 +192,7 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
|
||||||
}
|
}
|
||||||
|
|
||||||
var repositoryUrl = type.repository_url;
|
var repositoryUrl = type.repository_url;
|
||||||
if (!repositoryUrl) {
|
if (!repositoryUrl || !repositoryUrl(build)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue