From b64e9a326f870b346523e8b45cb0e876188f3ac3 Mon Sep 17 00:00:00 2001 From: Daniel Dourvaris Date: Mon, 16 Jul 2018 14:14:11 +0200 Subject: [PATCH] integrations: added branch_head into URL variables. This allow triggering more explicit build on webhooks/jenkins. branch_head is the last commit of pushed branch so the build system doesn't have to figure it out itself. - in often updated projects without this explicit specified it could happen that the pushed braanch could change when CI systems fetches the code. --- rhodecode/integrations/types/base.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rhodecode/integrations/types/base.py b/rhodecode/integrations/types/base.py index 4eb68e55..e8427f1d 100644 --- a/rhodecode/integrations/types/base.py +++ b/rhodecode/integrations/types/base.py @@ -124,6 +124,7 @@ class EEIntegration(IntegrationTypeBase): # Helpers # +# updating this required to update the `common_vars` as well. WEBHOOK_URL_VARS = [ ('event_name', 'Unique name of the event type, e.g pullrequest-update'), ('repo_name', 'Full name of the repository'), @@ -134,8 +135,9 @@ WEBHOOK_URL_VARS = [ ('extra:', 'Extra repo variables, read from its settings.'), # special attrs below that we handle, using multi-call - ('branch', 'Name of each brach submitted, if any.'), - ('commit_id', 'Id of each commit submitted, if any.'), + ('branch', 'Name of each branch submitted, if any.'), + ('branch_head', 'Head ID of pushed branch (full sha of last commit), if any.'), + ('commit_id', 'ID (full sha) of each commit submitted, if any.'), # pr events vars ('pull_request_id', 'Unique ID of the pull request.'), @@ -173,11 +175,13 @@ class CommitParsingDataHandler(object): _branch = branch_data[commit_branch] \ if commit_branch else commit_branch branch_commits = {'branch': _branch, + 'branch_head': '', 'commits': []} branches_commits[commit_branch] = branch_commits branch_commits = branches_commits[commit_branch] branch_commits['commits'].append(commit) + branch_commits['branch_head'] = commit['raw_id'] return branches_commits @@ -218,10 +222,17 @@ class WebhookDataHandler(CommitParsingDataHandler): branches_commits = self.aggregate_branch_data( data['push']['branches'], data['push']['commits']) - if '${branch}' in url: + if '${branch}' in url or '${branch_head}' in url: # call it multiple times, for each branch if used in variables for branch, commit_ids in branches_commits.items(): branch_url = string.Template(url).safe_substitute(branch=branch) + + if '${branch_head}' in branch_url: + # last commit in the aggregate is the head of the branch + branch_head = commit_ids['branch_head'] + branch_url = string.Template(branch_url).safe_substitute( + branch_head=branch_head) + # call further down for each commit if used if '${commit_id}' in branch_url: for commit_data in commit_ids['commits']: