webhooks
webhooks copied to clipboard
Installation webhook payload format error
When an Installation webhook is triggered for deleting a github app, there is a slight difference in the format of payload. For a delete, the CreatedAt and UpdatedAt fields return a string from the webhook. But the payload struct is defined as int64. Can we have a fix for this ? It could include both int64 and string
CreatedAt int64 json:"created_at,string"
UpdatedAt int64 json:"updated_at,string"
?
Values coming from the delete action webhook is "created_at":"2018-11-01T11:22:36.000Z", "updated_at":"2018-11-01T11:22:36.000Z"
I will be looking into this and looks like it will require some custom unmarshalling to handle both cases and if I do it to once payload I'd like to do it to all of them, since that's a breaking change I will look at doing this before the next major release ;)
Hi ! I've been discussing with the Github support about this point a few days ago and it's a bug on their side. It should always be an int64, they are supposed to fix it. They should tell me when it's done, I won't hesitate to post it here.
That’s great new @emaincourt thank you for reaching out to them :)
Looks like this is still an issue, guessing the workaround is to fork this and make a custom serialiser.
Is there any interest in accepting this as a PR?
Cheers.
Yes I’d definitely accept this as a PR, it would also be nice to have another convenience method to return time.Time as well as Int64
Just checking in, it's been a few years since the issue was opened. There is a forked repo that has a proposed fix. Could we merge it in?
Edit: Not sure what happened to my original comment. 🤦🏽
Hey. Any updates on the fix? I am following https://docs.github.com/en/developers/apps/setting-up-your-development-environment-to-create-a-github-app and in one of the steps I have to parse an installation event.
Currently I'm using a workaround by decoding the JSON into a map in case of an error, but the CreatedAt and UpdatedAt fields become 0:
b := bytes.NewBuffer(make([]byte, 0))
tee := io.TeeReader(r.Body, b)
bodyCopy, _ := ioutil.ReadAll(tee)
r.Body = ioutil.NopCloser(b)
eventPayload, err := webhookProvider.Parse(r, github.PullRequestEvent, github.InstallationEvent)
if err != nil {
if err == github.ErrEventNotFound {
log.Println("Received an event with unexpected type")
return
} else if err.Error() == "json: cannot unmarshal string into Go struct field .installation.created_at of type int64" {
// Fix installation payload
var f map[string]interface{}
err := json.Unmarshal(bodyCopy, &f)
if err != nil {
log.Println(err)
return
}
var pl github.InstallationPayload
var b bytes.Buffer
json.NewEncoder(&b).Encode(&f)
json.NewDecoder(&b).Decode(&pl)
eventPayload = pl
} else {
log.Println(err)
return
}
}
...
I'm encountering this now. Seems like a long standing issue.
@emaincourt - any update from Github?
@deankarn - would another PR solving this issue be welcome?
@deankarn Its been long since any update on this issue. I considered it as a bug in the GitHub documentation (maybe?) and raised a PR to fix this. I used time.Time
type instead of int64.
If changes looks okay to you, I will fix the tests.
https://github.com/go-playground/webhooks/pull/144
Seeing #144 merged - can this issue be considered resolved?