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:
parent
675e1799d8
commit
bcea268fcb
2 changed files with 11 additions and 9 deletions
|
@ -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):
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
Reference in a new issue