-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Updated models to match actual data structures transmitted by GitHub. #1844
Conversation
Unfortunately these changes will break the As mentioned in your linked issue, the problem is that the GitHub push webhook uses vastly different payload/objects to the push event in the events API. What we need to do here is make "new" response models for the webhook side of things, rather than modifying the event side of things. I'd suggest renaming all the "new" ones as So in other words
|
I just tried that, and I don't know when to create a new |
@ryangribble Any news regarding my question? |
im not really sure what you mean sorry. The As a first step can you create the response models and push them up? Then we can see what the best way is to deserialize the webhook payload |
@ryangribble I merged with latest changes on All the new Can you review it please and try to help me figure it out? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you've polluted your master branch with merge commits and other stuff that isn't actually in our master. There are a few spurious files/changes still on this PR that need to be reverted, which ive marked up
In terms of the deserializer code, you might be getting hung up on some of the magic that is in there, for the events API endpoints (but that doesn't have any bearing on what you're trying to do with webhooks). The magic stuff is to handle For a basic webhook, you won't use any of that stuff though... you would have your own API/webserver which receives the webhook. You would check the Eg var eventHeader = "push";
var payload = "<json payload here>";
if (eventHeader == "push")
{
var push = new SimpleJsonSerializer().Deserialize<PushWebhookPayload>(payload);
}
else if (eventHeader == "check_run")
{
var checkRun = new SimpleJsonSerializer().Deserialize<CheckRunEventPayload>(payload);
} This is the bare bones way to do it... I'm keen to think about how we could add some helpers to the library to make it easier. The problem is it's not possible to at runtime dynamically deserialize the payload into a specific response type, that the user can know at compile time. We can do the ugly trick like we do with the event APIs, where the user only gets a base class, which the deserializer has populated with an inheritted/derived class, but the user has to somehow know this, and cast it to the correct type, but I really dont like that. Another way I was thinking we could do it, is by allowing the user to register their delegate code for the given types they care about, and we could then run that. This has the advantage of being strongly typed at compile time. It might look something like this: // Setup code
Octokit.Webhooks.RegisterWebhookHandler(WebhookType.Push, x => {
// x is a PushWebhookPayload
});
Octokit.Webhooks.RegisterWebhookHandler(WebhookType.CheckRun, x => {
// x is a CheckRunEventPayload
});
// When receiving a webhook
var headers = request.Headers;
var payload = request.Body;
Octokit.Webhooks.Process(header, payload); // this would switch on the hook type found in the headers, then call any registered handler, passing the deserialized/strongly typed response model into the delegate provided by the user Now whether this stuff would belong in this core library or in an addon package But in terms of this PR I think we can just get the response models defined, and see if you can confirm that the first code sample I provided (using the Octokit deserializer directly) is working for you. We also have heaps more webhook payloads to implement if you want to add any others while you're here 👍 |
Hello, @ryangribble @itaibh , I'm actually interested in this PR. |
@GMouron fine by me 😃 |
Actually, I see that @itaibh did make the modifications asked by the code review |
Hmmm I must have missed that last commit that says it addresses the review comments, I will take a look at this review again |
Hello, any idea of when this could land on master ? Thanks :) |
Octokit/Models/Response/ActivityPayloads/PushWebhookCommitter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Itai Bar-Haim <[email protected]>
b06bbfe
to
4905d42
Compare
This felt very close to landing, so I rebased the branch on |
Codecov Report
@@ Coverage Diff @@
## master #1844 +/- ##
==========================================
- Coverage 67.05% 66.84% -0.22%
==========================================
Files 538 542 +4
Lines 14141 14219 +78
==========================================
+ Hits 9482 9504 +22
- Misses 4659 4715 +56
|
@itaibh thanks for the contribution, and for working through the review with us! |
Great, thank you @shiftkey. I will now be able to remove my home-built version 😉 |
release_notes: Added new types for webhook commit payload |
Closes #1789