Get basic support for GitLab working in the UI

This commit is contained in:
Joseph Schorr 2015-05-03 09:58:48 -07:00
parent e3aededcbc
commit f091aaa07e
4 changed files with 33 additions and 7 deletions

View file

@ -34,7 +34,12 @@ def attach_gitlab_build_trigger():
permission = AdministerRepositoryPermission(namespace, repository)
if permission.can():
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)
if not repo:
msg = 'Invalid repository: %s/%s' % (namespace, repository)

View file

@ -1168,6 +1168,8 @@ class GitLabBuildTrigger(BuildTriggerHandler):
def list_build_sources(self):
gl_client = self._get_authorized_client()
current_user = gl_client.currentuser()
if current_user is False:
raise RepositoryReadException('Unable to get current user')
repositories = gl_client.getprojects()
if repositories is False:
@ -1178,7 +1180,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
owner = repo['namespace']['name']
if not owner in namespaces:
namespaces[owner] = {
'personal': owner == current_user.username,
'personal': owner == current_user['username'],
'repos': [],
'info': {
'name': owner,
@ -1244,7 +1246,10 @@ class GitLabBuildTrigger(BuildTriggerHandler):
def load_dockerfile_contents(self):
gl_client = self._get_authorized_client()
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'])
if repository is False:
@ -1254,6 +1259,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
branches = find_matching_branches(self.config, branches)
if branches == []:
return None
branch_name = branches[0]
if repository['default_branch'] in branches:
branch_name = repository['default_branch']
@ -1261,6 +1267,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
contents = gl_client.getrawfile(repository['id'], branch_name, path)
if contents is False:
return None
return contents
def list_field_values(self, field_name):
@ -1277,7 +1284,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
return []
if field_name == 'tag_name':
tags = gl_client.getall(gl_client.getrepositorytags(repo['id']))
tags = gl_client.getrepositorytags(repo['id'])
if tags is False:
return []
return [tag['name'] for tag in tags]
@ -1324,14 +1331,14 @@ class GitLabBuildTrigger(BuildTriggerHandler):
metadata['commit_info']['committer'] = {
'username': committer['username'],
'avatar_url': committer['avatar_url'],
'url': client.host + '/' + committer['username'],
'url': gl_client.host + '/' + committer['username'],
}
if author is not None:
metadata['commit_info']['author'] = {
'username': author['username'],
'avatar_url': author['avatar_url'],
'url': client.host + '/' + author['username']
'url': gl_client.host + '/' + author['username']
}
prepared = PreparedBuild(self.trigger)

View file

@ -25,6 +25,12 @@
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"
analyze="checkAnalyze(isValid)"></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 class="trigger-setup-custom" repository="repository" trigger="trigger"
next-step-counter="nextStepCounter" current-step-valid="state.stepValid"

View file

@ -136,6 +136,14 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
'templates': {
'credentials': '/static/directives/trigger/githost/credentials.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;
if (!repositoryUrl) {
if (!repositoryUrl || !repositoryUrl(build)) {
return null;
}