From bcea268fcbd31f6e01dc886fadfcb253573ed9c3 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Mon, 21 Dec 2015 14:20:37 -0500 Subject: [PATCH] use app.gitlab_trigger for config data This includes defaults and makes the structure of the Gitlab trigger parallel the GitHub trigger. --- buildtrigger/gitlabhandler.py | 12 ++++-------- util/config/oauth.py | 8 +++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/buildtrigger/gitlabhandler.py b/buildtrigger/gitlabhandler.py index b2f0bbf28..05cb48184 100644 --- a/buildtrigger/gitlabhandler.py +++ b/buildtrigger/gitlabhandler.py @@ -1,8 +1,9 @@ import logging from functools import wraps +from urlparse import urljoin -from app import app +from app import app, gitlab_trigger from jsonschema import validate from buildtrigger.triggerutil import (RepositoryReadException, TriggerActivationException, @@ -127,9 +128,8 @@ class GitLabBuildTrigger(BuildTriggerHandler): return 'gitlab' def _get_authorized_client(self): - host = app.config.get('GITLAB_TRIGGER_CONFIG', {}).get('GITLAB_ENDPOINT', '') auth_token = self.auth_token or 'invalid' - return gitlab.Gitlab(host, oauth_token=auth_token, timeout=5) + return gitlab.Gitlab(gitlab_trigger.api_endpoint(), oauth_token=auth_token, timeout=5) def is_active(self): return 'hook_id' in self.config @@ -318,11 +318,7 @@ class GitLabBuildTrigger(BuildTriggerHandler): return None def get_repository_url(self): - # Get the host and remove a trailing slash. - host = app.config.get('GITLAB_TRIGGER_CONFIG', {}).get('GITLAB_ENDPOINT', '') - host = host[0:-1] if host[-1] == '/' else host - - return '%s/%s' % (host, self.config['build_source']) + return gitlab_trigger.get_public_url(self.config['build_source']) @_catch_timeouts def lookup_user(self, email): diff --git a/util/config/oauth.py b/util/config/oauth.py index 0b27902c9..1a5efdacd 100644 --- a/util/config/oauth.py +++ b/util/config/oauth.py @@ -95,7 +95,7 @@ class GithubOAuthConfig(OAuthConfig): return [org.lower() for org in allowed] def get_public_url(self, suffix): - return '%s%s' % (self._endpoint(), suffix) + return urlparse.urljoin(self._endpoint(), suffix) def _endpoint(self): endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com') @@ -226,6 +226,12 @@ class GitLabOAuthConfig(OAuthConfig): endpoint = endpoint + '/' return endpoint + def api_endpoint(self): + return self._endpoint() + + def get_public_url(self, suffix): + return urlparse.urljoin(self._endpoint(), suffix) + def service_name(self): return 'GitLab'