wereHamster / github-types

This package includes (some) type definitions for objects which are consumed or produced by the GitHub v3 API
http://hackage.haskell.org/package/github-types
MIT License
2 stars 1 forks source link

"push" event handling broken #5

Open iphydf opened 7 years ago

iphydf commented 7 years ago

I get the following error when receiving a "push" event from GitHub: ParseError "Error in $: key \"size\" not present".

This is a sample JSON event body:

{
  "ref": "refs/heads/boop",
  "before": "b6de7903a74c8a369b194a63d045c9aed1064af3",
  "after": "0000000000000000000000000000000000000000",
  "created": false,
  "deleted": true,
  "forced": false,
  "base_ref": null,
  "compare": "https://github.com/TokTok/github-tools/compare/b6de7903a74c...000000000000",
  "commits": [],
  "head_commit": null,
  "repository": {
    "id": 69141484,
    "name": "github-tools",
    "full_name": "TokTok/github-tools",
    "owner": {
      "name": "TokTok",
      "email": "iphydf@gmail.com"
    },
    "private": false,
    "html_url": "https://github.com/TokTok/github-tools",
    "description": "Small GitHub utilities like pull-status and changelog generator",
    "fork": false,
    "url": "https://github.com/TokTok/github-tools",
    "forks_url": "https://api.github.com/repos/TokTok/github-tools/forks",
    "keys_url": "https://api.github.com/repos/TokTok/github-tools/keys{/key_id}",
    "collaborators_url": "https://api.github.com/repos/TokTok/github-tools/collaborators{/collaborator}",
    "teams_url": "https://api.github.com/repos/TokTok/github-tools/teams",
    "hooks_url": "https://api.github.com/repos/TokTok/github-tools/hooks",
    "issue_events_url": "https://api.github.com/repos/TokTok/github-tools/issues/events{/number}",
    "events_url": "https://api.github.com/repos/TokTok/github-tools/events",
    "assignees_url": "https://api.github.com/repos/TokTok/github-tools/assignees{/user}",
    "branches_url": "https://api.github.com/repos/TokTok/github-tools/branches{/branch}",
    "tags_url": "https://api.github.com/repos/TokTok/github-tools/tags",
    "blobs_url": "https://api.github.com/repos/TokTok/github-tools/git/blobs{/sha}",
    "git_tags_url": "https://api.github.com/repos/TokTok/github-tools/git/tags{/sha}",
    "git_refs_url": "https://api.github.com/repos/TokTok/github-tools/git/refs{/sha}",
    "trees_url": "https://api.github.com/repos/TokTok/github-tools/git/trees{/sha}",
    "statuses_url": "https://api.github.com/repos/TokTok/github-tools/statuses/{sha}",
    "languages_url": "https://api.github.com/repos/TokTok/github-tools/languages",
    "stargazers_url": "https://api.github.com/repos/TokTok/github-tools/stargazers",
    "contributors_url": "https://api.github.com/repos/TokTok/github-tools/contributors",
    "subscribers_url": "https://api.github.com/repos/TokTok/github-tools/subscribers",
    "subscription_url": "https://api.github.com/repos/TokTok/github-tools/subscription",
    "commits_url": "https://api.github.com/repos/TokTok/github-tools/commits{/sha}",
    "git_commits_url": "https://api.github.com/repos/TokTok/github-tools/git/commits{/sha}",
    "comments_url": "https://api.github.com/repos/TokTok/github-tools/comments{/number}",
    "issue_comment_url": "https://api.github.com/repos/TokTok/github-tools/issues/comments{/number}",
    "contents_url": "https://api.github.com/repos/TokTok/github-tools/contents/{+path}",
    "compare_url": "https://api.github.com/repos/TokTok/github-tools/compare/{base}...{head}",
    "merges_url": "https://api.github.com/repos/TokTok/github-tools/merges",
    "archive_url": "https://api.github.com/repos/TokTok/github-tools/{archive_format}{/ref}",
    "downloads_url": "https://api.github.com/repos/TokTok/github-tools/downloads",
    "issues_url": "https://api.github.com/repos/TokTok/github-tools/issues{/number}",
    "pulls_url": "https://api.github.com/repos/TokTok/github-tools/pulls{/number}",
    "milestones_url": "https://api.github.com/repos/TokTok/github-tools/milestones{/number}",
    "notifications_url": "https://api.github.com/repos/TokTok/github-tools/notifications{?since,all,participating}",
    "labels_url": "https://api.github.com/repos/TokTok/github-tools/labels{/name}",
    "releases_url": "https://api.github.com/repos/TokTok/github-tools/releases{/id}",
    "deployments_url": "https://api.github.com/repos/TokTok/github-tools/deployments",
    "created_at": 1474774012,
    "updated_at": "2016-11-15T22:46:07Z",
    "pushed_at": 1481755655,
    "git_url": "git://github.com/TokTok/github-tools.git",
    "ssh_url": "git@github.com:TokTok/github-tools.git",
    "clone_url": "https://github.com/TokTok/github-tools.git",
    "svn_url": "https://github.com/TokTok/github-tools",
    "homepage": "",
    "size": 51,
    "stargazers_count": 1,
    "watchers_count": 1,
    "language": "Haskell",
    "has_issues": true,
    "has_downloads": true,
    "has_wiki": false,
    "has_pages": false,
    "forks_count": 2,
    "mirror_url": null,
    "open_issues_count": 1,
    "forks": 2,
    "open_issues": 1,
    "watchers": 1,
    "default_branch": "master",
    "stargazers": 1,
    "master_branch": "master",
    "organization": "TokTok"
  },
  "pusher": {
    "name": "iphydf",
    "email": "iphydf@users.noreply.github.com"
  },
  "organization": {
    "login": "TokTok",
    "id": 17427091,
    "url": "https://api.github.com/orgs/TokTok",
    "repos_url": "https://api.github.com/orgs/TokTok/repos",
    "events_url": "https://api.github.com/orgs/TokTok/events",
    "hooks_url": "https://api.github.com/orgs/TokTok/hooks",
    "issues_url": "https://api.github.com/orgs/TokTok/issues",
    "members_url": "https://api.github.com/orgs/TokTok/members{/member}",
    "public_members_url": "https://api.github.com/orgs/TokTok/public_members{/member}",
    "avatar_url": "https://avatars.githubusercontent.com/u/17427091?v=3",
    "description": "#toktok on Freenode"
  },
  "sender": {
    "login": "iphydf",
    "id": 10647936,
    "avatar_url": "https://avatars.githubusercontent.com/u/10647936?v=3",
    "gravatar_id": "",
    "url": "https://api.github.com/users/iphydf",
    "html_url": "https://github.com/iphydf",
    "followers_url": "https://api.github.com/users/iphydf/followers",
    "following_url": "https://api.github.com/users/iphydf/following{/other_user}",
    "gists_url": "https://api.github.com/users/iphydf/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/iphydf/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/iphydf/subscriptions",
    "organizations_url": "https://api.github.com/users/iphydf/orgs",
    "repos_url": "https://api.github.com/users/iphydf/repos",
    "events_url": "https://api.github.com/users/iphydf/events{/privacy}",
    "received_events_url": "https://api.github.com/users/iphydf/received_events",
    "type": "User",
    "site_admin": false
  }
}
iphydf commented 7 years ago

Hm, I guess I misunderstood the meaning of "events" here. I thought it was supposed to be useful for events posted by github webhooks. Instead, it seems to be for timeline events. This issue can be ignored then.

wereHamster commented 7 years ago

The two kinds of events overlap. As you've probably seen, I haven't updated the package in a while, and I didn't keep up with the changes in the GitHub API. If it makes sense to keep the definition of events unified across the different sources (webhook, timeline, ...) then this issue is valid.

Actually, if you look at the documentation there is http://hackage.haskell.org/package/github-types-0.2.1/docs/GitHub-Types-Events.html#v:webhookPayloadParser.

iphydf commented 7 years ago

They overlap, but the timeline events contain a lot less data. You'll end up having lots of Maybe a in the records. I started contributing back my work, but it's going to take more than an hour to unify timeline events and webhook events, so here is my code: https://github.com/TokTok/github-tools/tree/master/web/GitHub/Types/Events and https://github.com/TokTok/github-tools/tree/master/web/GitHub/Types/Base.

wereHamster commented 7 years ago

Ah, that's a shame :( If they are distinct enough then we should keep the types separate.