Closed patcon closed 9 years ago
Ah. So seems we def need to use the X-GitHub-Event
header to make this script more robust. For instance, the watch
event_type has no hash top-level key called "watch" with data in it like the "issue" and "pull_request" events had -- just a "repository" hash.
# headers
X-GitHub-Event: "pull_request"
# payload
{
"action": "opened",
"number": 1,
"pull_request": {
"url": "https://api.github.com/repos/patcon/roobot/pulls/1",
"id": 13190670,
"html_url": "https://github.com/patcon/roobot/pull/1",
"diff_url": "https://github.com/patcon/roobot/pull/1.diff",
"patch_url": "https://github.com/patcon/roobot/pull/1.patch",
"issue_url": "https://api.github.com/repos/patcon/roobot/issues/1",
"number": 1,
"state": "open",
"title": "A test pull request with a body",
"user": {
"login": "patcon",
"id": 305339,
"avatar_url": "https://gravatar.com/avatar/7e945991d1d70075cff59331d72ef4d8?d=https%3A%2F%2Fidenticons.github.com%2F5d6d17375e48728255af334496b52416.png&r=x",
"gravatar_id": "7e945991d1d70075cff59331d72ef4d8",
...
}
}
}
# headers
X-GitHub-Event: "watch"
# payload
{
"action": "started",
"repository": {
"id": 17421297,
"name": "roobot",
"full_name": "patcon/roobot",
"owner": {
"login": "patcon",
"id": 305339,
"avatar_url": "https://gravatar.com/avatar/7e945991d1d70075cff59331d72ef4d8?d=https%3A%2F%2Fidenticons.github.com%2F5d6d17375e48728255af334496b52416.png&r=x",
"gravatar_id": "7e945991d1d70075cff59331d72ef4d8",
"url": "https://api.github.com/users/patcon",
"html_url": "https://github.com/patcon",
...
}
}
}
:+1: Great find! Would have messed things up.
Is this in master or is a PR in progress on a fork?
Sorry, no code yet. the snippets are just the payloads copied from a repo's webhook setting GUI on github :)
Looks like this could probably be closed now?
:+1:
Right now, we're checking for
"action": "opened"
in the payload, and then checking for a key with the enabled event types (fromHUBOT_GITHUB_EVENT_NOTIFIER_TYPES
).Just realized that we could instead expect the format for the envvar to be:
Perhaps we could default to the
opened
action if not specified (and down the line, perhaps have a hash specifying the default for each type).