From dcbd998670700c54362737ed8e9955501d4da8fd Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 07 2016 10:08:22 +0000 Subject: Adjust all the place that were dong *_hook[0] to do *_hook directly --- diff --git a/pagure-ci/pagure_ci_server.py b/pagure-ci/pagure_ci_server.py index fb43952..a3470d9 100644 --- a/pagure-ci/pagure_ci_server.py +++ b/pagure-ci/pagure_ci_server.py @@ -96,7 +96,7 @@ def handle_messages(): log.info("Trigger on %s PR #%s from %s: %s", project.fullname, pr_id, repo, branch) - url = project.ci_hook[0].ci_url + url = project.ci_hook.ci_url if data['ci_type'] == 'jenkins': url = urlparse.urljoin(url, '/buildWithParameters') @@ -104,7 +104,7 @@ def handle_messages(): requests.post( url, data={ - 'token': project.ci_hook[0].pagure_ci_token, + 'token': project.ci_hook.pagure_ci_token, 'cause': pr_id, 'REPO': project.fullname, 'BRANCH': branch diff --git a/pagure/api/ci/jenkins.py b/pagure/api/ci/jenkins.py index 981055e..e0d45ac 100644 --- a/pagure/api/ci/jenkins.py +++ b/pagure/api/ci/jenkins.py @@ -44,7 +44,7 @@ def jenkins_ci_notification(repo, pagure_ci_token, username=None): if not constant_time.bytes_eq( to_bytes(pagure_ci_token), - to_bytes(project.ci_hook[0].pagure_ci_token)): + to_bytes(project.ci_hook.pagure_ci_token)): raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK) data = flask.request.get_json() diff --git a/pagure/hooks/files/pagure_force_commit_hook.py b/pagure/hooks/files/pagure_force_commit_hook.py index a1bacd4..3b07189 100755 --- a/pagure/hooks/files/pagure_force_commit_hook.py +++ b/pagure/hooks/files/pagure_force_commit_hook.py @@ -42,7 +42,7 @@ def run_as_pre_receive_hook(): # Get the list of branches branches = [ branch.strip() - for branch in repo.pagure_force_commit_hook[0].branches.split(',') + for branch in repo.pagure_force_commit_hook.branches.split(',') if repo.pagure_force_commit_hook] # Remove empty branches diff --git a/pagure/hooks/files/rtd_hook.py b/pagure/hooks/files/rtd_hook.py index 98525c6..3803fb1 100755 --- a/pagure/hooks/files/rtd_hook.py +++ b/pagure/hooks/files/rtd_hook.py @@ -43,7 +43,7 @@ def run_as_post_receive_hook(): # Get the list of branches branches = [ branch.strip() - for branch in repo.rtd_hook[0].branches.split(',') + for branch in repo.rtd_hook.branches.split(',') if repo.rtd_hook] # Remove empty branches @@ -53,7 +53,7 @@ def run_as_post_receive_hook(): if branch] url = 'http://readthedocs.org/build/%s' % ( - repo.rtd_hook[0].project_name.strip() + repo.rtd_hook.project_name.strip() ) for line in sys.stdin: @@ -65,11 +65,11 @@ def run_as_post_receive_hook(): if branches: if refname in branches: print 'Starting RTD build for %s' % ( - repo.rtd_hook[0].project_name.strip()) + repo.rtd_hook.project_name.strip()) requests.post(url) else: print 'Starting RTD build for %s' % ( - repo.rtd_hook[0].project_name.strip()) + repo.rtd_hook.project_name.strip()) requests.post(url) diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 0822242..0781098 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -882,7 +882,7 @@ def add_pull_request_comment(session, request, commit, tree_id, filename, if notification and request.status == 'Open' \ and request.project.ci_hook and PAGURE_CI: REDIS.publish('pagure.ci', json.dumps({ - 'ci_type': request.project.ci_hook[0].ci_type, + 'ci_type': request.project.ci_hook.ci_type, 'pr': request.to_json(public=True, with_comments=False) })) @@ -1255,7 +1255,7 @@ def new_pull_request(session, branch_from, # Send notification to the CI server if REDIS and request.project.ci_hook and PAGURE_CI: REDIS.publish('pagure.ci', json.dumps({ - 'ci_type': request.project.ci_hook[0].ci_type, + 'ci_type': request.project.ci_hook.ci_type, 'pr': request.to_json(public=True, with_comments=False) })) diff --git a/pagure/lib/lib_ci.py b/pagure/lib/lib_ci.py index 0e390e6..ecb3913 100644 --- a/pagure/lib/lib_ci.py +++ b/pagure/lib/lib_ci.py @@ -43,8 +43,8 @@ def process_jenkins_build(session, project, build_id, requestfolder): """ import jenkins # Jenkins Base URL - jenk = jenkins.Jenkins(project.ci_hook[0].ci_url.split('/job/')[0]) - jenkins_name = project.ci_hook[0].ci_url.split( + jenk = jenkins.Jenkins(project.ci_hook.ci_url.split('/job/')[0]) + jenkins_name = project.ci_hook.ci_url.split( '/job/', 1)[1].split('/', 1)[0] build_info = jenk.get_build_info(jenkins_name, build_id) result = build_info['result'] @@ -77,7 +77,7 @@ def process_jenkins_build(session, project, build_id, requestfolder): pagure.lib.add_pull_request_flag( session, request=request, - username=project.ci_hook[0].ci_type, + username=project.ci_hook.ci_type, percent=percent, comment=comment, url=url,