Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize installation_* webhook events #420

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

gagbo
Copy link
Contributor

@gagbo gagbo commented Jul 19, 2023

Fixes #415

This Pull Request adds support for deserializing GitHub-sent webhook events related to GitHub Apps installations.
This is another breaking change because I could not figure out a cleaner way to deal with the WrappedEventPayload::installation field duality:

  • When receiving an installation event, the installation field contains a full copy of crate::models::Installation, but
  • when receiving any other type of event, the installation field only contains an id and a node_id (Note: node_id is not present in the first case.)

If there's a better solution than breaking the API again, I'll be happy to apply that.

It might also be nice to try to have a proper WebhookEvent type I guess? But I don't know where it would fit. The main things I would like to have for
supporting webhooks is a failible constructor that takes a string as parameter. Since webhook have their "Event::type" stored in a HTTP header (X-GitHub-Event), I
think it would be nice to have a WebhookEvent::try_from(r#type: String, payload: &[u8]) -> Result<Self> that would automatically try to parse the payload to the
correct enum variant if type is known, and falls back to the Unknown(serde_json::Value) variant if type isn't known/handled by Octocrab.

I can provide payloads from my test app if that helps, it just takes time to anonymize them so I'll only do it on demand.

Cheers,

Gerry

Breaking: the installation stored in WrappedEventPayload now contains
2 variants, depending on whether the event comes from an installation_
related webhook event, or something else.
@XAMPPRocky
Copy link
Owner

Thank you for your PR!

@XAMPPRocky XAMPPRocky merged commit 01e8024 into XAMPPRocky:main Jul 19, 2023
10 checks passed
@gagbo gagbo deleted the feat/installation_events branch July 19, 2023 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Installation events in EventPayload
2 participants