# HG changeset patch # User Marcin Kuzminski # Date 2018-02-16 18:22:21 # Node ID f44c5e923b57957d4de3a65ea9f55ee17241fbf7 # Parent 727a3d6d18961d7dd5eb44813fb4a5a5ed78e132 pull-request-events: expose pr title and uid for commits inside. - used mostly for jenkins integration functions diff --git a/rhodecode/events/pullrequest.py b/rhodecode/events/pullrequest.py --- a/rhodecode/events/pullrequest.py +++ b/rhodecode/events/pullrequest.py @@ -37,6 +37,7 @@ class PullRequestEvent(RepoEvent): self.pullrequest = pullrequest def as_dict(self): + from rhodecode.lib.utils2 import md5_safe from rhodecode.model.pull_request import PullRequestModel data = super(PullRequestEvent, self).as_dict() @@ -46,6 +47,9 @@ class PullRequestEvent(RepoEvent): repos=[self.pullrequest.source_repo] ) issues = _issues_as_dict(commits) + # calculate hashes of all commits for unique identifier of commits + # inside that pull request + commits_hash = md5_safe(':'.join(x.get('raw_id', '') for x in commits)) data.update({ 'pullrequest': { @@ -59,6 +63,7 @@ class PullRequestEvent(RepoEvent): 'shadow_url': PullRequestModel().get_shadow_clone_url( self.pullrequest, request=self.request), 'status': self.pullrequest.calculated_review_status(), + 'commits_uid': commits_hash, 'commits': commits, } }) diff --git a/rhodecode/integrations/types/base.py b/rhodecode/integrations/types/base.py --- a/rhodecode/integrations/types/base.py +++ b/rhodecode/integrations/types/base.py @@ -135,8 +135,11 @@ WEBHOOK_URL_VARS = [ # pr events vars ('pull_request_id', 'Unique ID of the pull request.'), + ('pull_request_title', 'Title of the pull request.'), ('pull_request_url', 'Pull request url.'), ('pull_request_shadow_url', 'Pull request shadow repo clone url.'), + ('pull_request_commits_uid', 'Calculated UID of all commits inside the PR. ' + 'Changes after PR update'), # user who triggers the call ('username', 'User who triggered the call.'), @@ -244,8 +247,11 @@ class WebhookDataHandler(object): 'register %s call(%s) to url %s', self.name, event, url) url = string.Template(url).safe_substitute( pull_request_id=data['pullrequest']['pull_request_id'], + pull_request_title=data['pullrequest']['title'], pull_request_url=data['pullrequest']['url'], - pull_request_shadow_url=data['pullrequest']['shadow_url'],) + pull_request_shadow_url=data['pullrequest']['shadow_url'], + pull_request_commits_uid=data['pullrequest']['commits_uid'], + ) return [(url, self.headers, data)] def __call__(self, event, data): diff --git a/rhodecode/tests/integrations/test_webhook.py b/rhodecode/tests/integrations/test_webhook.py --- a/rhodecode/tests/integrations/test_webhook.py +++ b/rhodecode/tests/integrations/test_webhook.py @@ -86,6 +86,8 @@ def test_webook_parse_url_for_pull_reque base_data['pullrequest'] = { 'pull_request_id': 999, 'url': 'http://pr-url.com', + 'title': 'example-pr-title', + 'commits_uid': 'abcdefg1234', 'shadow_url': 'http://pr-url.com/repository' } headers = {'exmaple-header': 'header-values'}