softprops / afterparty

rust github webhook server
MIT License
55 stars 13 forks source link

Schema updates to make ping and push work again #13

Closed clux closed 7 years ago

clux commented 8 years ago

This allows push and ping events to be parsed successfully.

However, this only remains true if the only elements in events.txt are ping and push. Tried to get status to work by updating the schema, but I just can't get it to work no matter how I change it. It seems to always not understand some key, and that key is always there in the schema so I don't really understand.

Additionally, if you add status to events.txt, then this also breaks the push event mysteriously. Maybe there's some mismatch in the re-used structs between events?

I tried updating the remaining structs before noticing this (which is why this PR updates more events), although almost all of them were up to date.

So in short; this PR doesn't really fix a lot if you want all the events. If you have any suggestions I'm happy to try tweaking things.

clux commented 8 years ago

Think I've figured out the reason why the Push event is failing when the other events are present in events.txt:

the Push event has a commits array, each element contains a simple author object:

      "author": {
        "name": "baxterthehacker",
        "email": "baxterthehacker@users.noreply.github.com",
        "username": "baxterthehacker"
      },

unfortunately, when looking at the generated events.rs.in the Push struct requires a Commits struct which requires the Author struct. Unfortunately, this author struct is actually is very different:

#[derive(Default, Debug, Deserialize)]
pub struct Author {
    #[serde(rename="avatar_url")]
    pub avatar_url: String,
    #[serde(rename="events_url")]
    pub events_url: String,
    #[serde(rename="followers_url")]
    pub followers_url: String,
    #[serde(rename="following_url")]
    pub following_url: String,
    #[serde(rename="gists_url")]
    pub gists_url: String,
    #[serde(rename="gravatar_id")]
    pub gravatar_id: String,
    #[serde(rename="html_url")]
    pub html_url: String,
    #[serde(rename="id")]
    pub id: u64,
    #[serde(rename="login")]
    pub login: String,
    #[serde(rename="organizations_url")]
    pub organizations_url: String,
    #[serde(rename="received_events_url")]
    pub received_events_url: String,
    #[serde(rename="repos_url")]
    pub repos_url: String,
    #[serde(rename="site_admin")]
    pub site_admin: bool,
    #[serde(rename="starred_url")]
    pub starred_url: String,
    #[serde(rename="subscriptions_url")]
    pub subscriptions_url: String,
    #[serde(rename="type")]
    pub _type: String,
    #[serde(rename="url")]
    pub url: String,
}

which appears to come from the status event which has another author object embedded inside as a primary data structure:

"author": {
      "login": "baxterthehacker",
      "id": 6752317,
      "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
      "gravatar_id": "",
      "url": "https://api.github.com/users/baxterthehacker",
      "html_url": "https://github.com/baxterthehacker",
      "followers_url": "https://api.github.com/users/baxterthehacker/followers",
      "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
      "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
      "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
      "repos_url": "https://api.github.com/users/baxterthehacker/repos",
      "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
      "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
      "type": "User",
      "site_admin": false
    },

Looks like the names of these structs are just named after the the original key in the json, which is not unique across events.