hubot-archive / hubot-github-repo-event-notifier

Notifies about any GitHub repo event available via webhook.
https://www.npmjs.org/package/hubot-github-repo-event-notifier
57 stars 42 forks source link

Allow `event_type:action` format for enabling notifications #9

Closed patcon closed 9 years ago

patcon commented 10 years ago

Right now, we're checking for "action": "opened" in the payload, and then checking for a key with the enabled event types (from HUBOT_GITHUB_EVENT_NOTIFIER_TYPES).

Just realized that we could instead expect the format for the envvar to be:

HUBOT_GITHUB_EVENT_NOTIFIER_TYPES="issue:opened,pull_request:opened"

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).

patcon commented 10 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",
      ...
    }
  }
}
parkr commented 10 years ago

:+1: Great find! Would have messed things up.

sc0ttkclark commented 10 years ago

Is this in master or is a PR in progress on a fork?

patcon commented 10 years ago

Sorry, no code yet. the snippets are just the payloads copied from a repo's webhook setting GUI on github :)

geekgonecrazy commented 9 years ago

Looks like this could probably be closed now?

patcon commented 9 years ago

:+1: