Skip to content

Commit

Permalink
Add event property that is the event in the X-GitHub-Event header
Browse files Browse the repository at this point in the history
Fixes #2868.
  • Loading branch information
seankelly committed Mar 25, 2017
1 parent 369ea01 commit 1177ce9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions master/buildbot/www/hooks/github.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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']
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1177ce9

Please sign in to comment.