From 1177ce9336452eb267faab146c8174396a1afe93 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Fri, 24 Mar 2017 21:29:52 -0500 Subject: [PATCH] Add event property that is the event in the X-GitHub-Event header Fixes #2868. --- master/buildbot/www/hooks/github.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/master/buildbot/www/hooks/github.py b/master/buildbot/www/hooks/github.py index d9be47c9bec..57ff7a32fd1 100644 --- a/master/buildbot/www/hooks/github.py +++ b/master/buildbot/www/hooks/github.py @@ -64,7 +64,7 @@ def process(self, request): if handler is None: raise ValueError('Unknown event: {}'.format(event_type)) - return handler(payload) + return handler(payload, event_type) def _get_payload(self, request): content = request.content.read() @@ -108,10 +108,10 @@ def _get_payload(self, request): return payload - def handle_ping(self, _): + def handle_ping(self, _, __): return [], 'git' - def handle_push(self, payload): + def handle_push(self, payload, event): # This field is unused: user = None # user = payload['pusher']['name'] @@ -121,13 +121,14 @@ def handle_push(self, payload): # project = request.args.get('project', [''])[0] project = payload['repository']['full_name'] - changes = self._process_change(payload, user, repo, repo_url, project) + changes = self._process_change(payload, user, repo, repo_url, project, + event) log.msg("Received {} changes from github".format(len(changes))) return changes, 'git' - def handle_pull_request(self, payload): + def handle_pull_request(self, payload, event): changes = [] number = payload['number'] refname = 'refs/pull/{}/merge'.format(number) @@ -152,7 +153,10 @@ def handle_pull_request(self, payload): # TODO: Get author name based on login id using txgithub module 'author': payload['sender']['login'], 'comments': 'GitHub Pull Request #{} ({} commit{})'.format( - number, commits, 's' if commits != 1 else '') + number, commits, 's' if commits != 1 else ''), + 'properties': { + 'event': event, + }, } if callable(self._codebase): @@ -166,7 +170,7 @@ def handle_pull_request(self, payload): len(changes), number)) return changes, 'git' - def _process_change(self, payload, user, repo, repo_url, project): + def _process_change(self, payload, user, repo, repo_url, project, event): """ Consumes the JSON as a python object and actually starts the build. @@ -209,7 +213,10 @@ def _process_change(self, payload, user, repo, repo_url, project): 'revlink': commit['url'], 'repository': repo_url, 'project': project, - 'properties': {'github_distinct': commit.get('distinct', True)} + 'properties': { + 'github_distinct': commit.get('distinct', True), + 'event': event, + }, } if callable(self._codebase):