use app.gitlab_trigger for config data

This includes defaults and makes the structure of the Gitlab trigger
parallel the GitHub trigger.
This commit is contained in:
Jimmy Zelinskie 2015-12-21 14:20:37 -05:00 committed by Jimmy Zelinskie
parent 675e1799d8
commit bcea268fcb
2 changed files with 11 additions and 9 deletions

View file

@ -1,8 +1,9 @@
import logging import logging
from functools import wraps from functools import wraps
from urlparse import urljoin
from app import app from app import app, gitlab_trigger
from jsonschema import validate from jsonschema import validate
from buildtrigger.triggerutil import (RepositoryReadException, TriggerActivationException, from buildtrigger.triggerutil import (RepositoryReadException, TriggerActivationException,
@ -127,9 +128,8 @@ class GitLabBuildTrigger(BuildTriggerHandler):
return 'gitlab' return 'gitlab'
def _get_authorized_client(self): def _get_authorized_client(self):
host = app.config.get('GITLAB_TRIGGER_CONFIG', {}).get('GITLAB_ENDPOINT', '')
auth_token = self.auth_token or 'invalid' 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): def is_active(self):
return 'hook_id' in self.config return 'hook_id' in self.config
@ -318,11 +318,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
return None return None
def get_repository_url(self): def get_repository_url(self):
# Get the host and remove a trailing slash. return gitlab_trigger.get_public_url(self.config['build_source'])
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'])
@_catch_timeouts @_catch_timeouts
def lookup_user(self, email): def lookup_user(self, email):

View file

@ -95,7 +95,7 @@ class GithubOAuthConfig(OAuthConfig):
return [org.lower() for org in allowed] return [org.lower() for org in allowed]
def get_public_url(self, suffix): def get_public_url(self, suffix):
return '%s%s' % (self._endpoint(), suffix) return urlparse.urljoin(self._endpoint(), suffix)
def _endpoint(self): def _endpoint(self):
endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com') endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com')
@ -226,6 +226,12 @@ class GitLabOAuthConfig(OAuthConfig):
endpoint = endpoint + '/' endpoint = endpoint + '/'
return 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): def service_name(self):
return 'GitLab' return 'GitLab'