Pass trigger information on build status. Set up a trigger for the sample building repository. Allow to list the builds started from a trigger. Protect the callback with the proper auth for creating a trigger on a repo.
This commit is contained in:
parent
f60f9eb62a
commit
9e426816a5
7 changed files with 94 additions and 43 deletions
|
@ -7,6 +7,8 @@ from endpoints.common import render_page_template, common_login
|
|||
from app import app, mixpanel
|
||||
from data import model
|
||||
from util.names import parse_repository_name
|
||||
from util.http import abort
|
||||
from auth.permissions import AdministerRepositoryPermission
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -113,10 +115,18 @@ def github_oauth_attach():
|
|||
@login_required
|
||||
@parse_repository_name
|
||||
def attach_github_build_trigger(namespace, repository):
|
||||
token = exchange_github_code_for_token(request.args.get('code'))
|
||||
model.create_build_trigger(namespace, repository, 'github', token,
|
||||
current_user.db_user())
|
||||
admin_path = '%s/%s/%s' % (namespace, repository, 'admin')
|
||||
full_url = url_for('web.repository', path=admin_path) + '?tab=trigger'
|
||||
logger.debug('Redirecting to full url: %s' % full_url)
|
||||
return redirect(full_url)
|
||||
permission = AdministerRepositoryPermission(namespace, repository)
|
||||
if permission.can():
|
||||
token = exchange_github_code_for_token(request.args.get('code'))
|
||||
repo = model.get_repository(namespace, repository)
|
||||
if not repo:
|
||||
msg = 'Invalid repository: %s/%s' % (namespace, repository)
|
||||
abort(404, message=msg)
|
||||
|
||||
model.create_build_trigger(repo, 'github', token, current_user.db_user())
|
||||
admin_path = '%s/%s/%s' % (namespace, repository, 'admin')
|
||||
full_url = url_for('web.repository', path=admin_path) + '?tab=trigger'
|
||||
logger.debug('Redirecting to full url: %s' % full_url)
|
||||
return redirect(full_url)
|
||||
|
||||
abort(403)
|
Reference in a new issue