webhooks icon indicating copy to clipboard operation
webhooks copied to clipboard

Installation webhook payload format error

Open merinjo opened this issue 6 years ago • 9 comments

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"

merinjo avatar Nov 01 '18 11:11 merinjo

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 ;)

deankarn avatar Nov 28 '18 15:11 deankarn

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.

emaincourt avatar Jan 03 '19 11:01 emaincourt

That’s great new @emaincourt thank you for reaching out to them :)

deankarn avatar Jan 03 '19 13:01 deankarn

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.

wolfeidau avatar Apr 07 '19 02:04 wolfeidau

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

deankarn avatar Apr 20 '19 16:04 deankarn

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. 🤦🏽

edwardofclt avatar Feb 08 '21 22:02 edwardofclt

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
  }
}
...

teabolt avatar Apr 19 '21 19:04 teabolt

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?

gsaraf avatar May 15 '21 16:05 gsaraf

@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

iamsumit avatar Mar 07 '22 07:03 iamsumit

Seeing #144 merged - can this issue be considered resolved?

elewis787 avatar Mar 09 '23 19:03 elewis787