haskell-github / github

The github API for Haskell
https://hackage.haskell.org/package/github
BSD 3-Clause "New" or "Revised" License
408 stars 190 forks source link

Add support for github events and webhooks #256

Open iphydf opened 7 years ago

iphydf commented 7 years ago

I'm exposing a github webhook in a web service I'm working on. I'm using the github-webhook-handler, which uses github-types package, which is incomplete (it has 1 field implemented per event) and broken ("push" for example expects a "size" field, but the JSON payload doesn't have one).

This now effectively means one of three things:

  1. I write a separate app in a different language with support for github events.
  2. I handle the JSON directly (ew, no).
  3. I improve support in either github-types or github. I already use github a lot, so I'd prefer this support be in github, but then I need to rip out the webhook handler and get it to work with github.

I don't have time for 2. and 3. I'm not sufficiently motivated to do 1. So I'll wait. I'm happy to provide sample inputs for each of the possible payloads.

kvanbere commented 6 years ago

Fixed by PR #303 if it lands.

TomMD commented 6 years ago

This should probably be closed and point to https://github.com/onrock-eng/github-webhooks

iphydf commented 6 years ago

No, probably not, because that package is very incomplete.

Compare: https://github.com/onrock-eng/github-webhooks/blob/master/src/GitHub/Data/Webhooks/Events.hs#L852 with: https://github.com/TokTok/github-tools/blob/master/src/GitHub/Types/Events/PullRequestEvent.hs#L15

The latter is complete. As you can see, many fields are missing from the former.

TomMD commented 6 years ago

The discussion in the linked PR suggests events are out of scope of this package. That was my point which I intended more as a question. So: should this ticket be closed as out of scope / won't fix with a pointer to other interesting packages or should we work to merge events into this package?

A solution might be to file a completeness bug against the onrock-eng repo, keep this ticket open and hope for a PR, just use TokTok's repo, or something else.

kvanbere commented 6 years ago

I was unaware github-webhooks was incomplete. The fields are sourced from the documentation/sample payloads provided from GitHub [1].

Some information is nested multiple levels deep in the data which is structured to match the JSON, so if they perform flattening that might explain the inconsistency you see.

[1] https://github.com/onrock-eng/github-webhooks/blob/master/fixtures/pull-request-event.json

kvanbere commented 6 years ago

If not, feel free to file a bug against github-webhooks and we’ll take a look before 1.0.0

iphydf commented 6 years ago

It doesn't seem to have any way to test for completeness. Our github event types are tested for completeness every day by ensuring that serialising the haskell data structure results in the same json object as the input.

I'm not sure what you mean by flattening, but toktok's github data structures are pretty much a dumb translation of whatever github feeds us, updated whenever that changes.

Randomly looking at one of the data structures in github-webhooks (the pull request event), I see HookPullRequest with assignee, but not assignees, which is something github added about a year ago so you can have multiple. It also doesn't have requested_reviewers or requested_teams or maintainer_can_modify or author_association (besides the things it has commented out).