Skip to content

Fix Webhook creation. #1117

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

Merged
merged 4 commits into from
Feb 27, 2019
Merged

Fix Webhook creation. #1117

merged 4 commits into from
Feb 27, 2019

Conversation

dominicgunn
Copy link
Contributor

@dominicgunn dominicgunn commented Feb 11, 2019

Changes

Attempting to create webhooks fail unless a name is specified. As per the documentation the only name that is valid is "web", so I haven't opted to allow modification of this but creation seems to fail without it.

This seems to impact only Github Enterprise.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@dominicgunn
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels Feb 11, 2019
@gmlewis
Copy link
Collaborator

gmlewis commented Feb 11, 2019

The only documentation I found about this:
https://developer.github.com/v3/repos/hooks/#create-a-hook
says that the name field has a default value of web.

Do you want to contact GitHub ([email protected]) and ask them to clarify what is going on after describing the situation you discovered? I have found their support team to be incredibly responsive and helpful.

@radeksimko
Copy link
Contributor

I have just emailed GitHub support about this, will update here once I get response from them.

@radeksimko
Copy link
Contributor

radeksimko commented Feb 26, 2019

Here's a response I received from a helpful GitHub support folk:


This field is currently a legacy field, in that we only provide a single option for this: 'web' for webhooks. Previously we had the concept of GitHub Services: https://developer.github.com/changes/2018-10-01-denying-new-github-services/ that allowed you to create hooks for this.

However as mentioned in the above article we have since deprecated and switched off this service. We decided to leave this field in, to prevent issues with current integrations that might still rely on this. In this case it automatically defaults to 'web' if omitted, or if provided, must have the value 'web'.

For instance the following core curl request works:

curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $TOKEN" \
-d "{\"config\":{\"url\":\"$URL\"}}" \
https://github.com/api/repos/mattamorphic/WebhookTest/hooks

Where $TOKEN is the OAuth token, and $URL is the resource to send the requests to.

Long term we could choose to add other values to this as we are often iterating on the services that we provide, we could also choose to in the long term officially deprecate and remove this field as part of an ongoing effort to improve our validation rules.

In terms of the PR, #1117, the author @dominicgunn mentions that:

Attempting to create webhooks fail unless a name is specified

As we haven't been able to reproduce this with the above curl I'd be interested to know if the user can reproduce this with a curl -v?

TL;DR; This field has a single value, is a legacy field, and has a default value if omitted.

In terms of defining this field in the SDK, I feel like the SDK should emulate the API behaviour:

  1. Optional, and if not provided default to 'web'
  2. If provided this can only accept 'web'

I'm not sure if the SDK has any convention around validation of arguments, which may need to be added.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @dominicgunn, and thank you, @radeksimko for contacting GitHub support and reporting back!

I have just one minor tweak, and then we can merge after we get a second LGTM.

@gmlewis gmlewis requested a review from gauntface February 27, 2019 00:30
@gmlewis
Copy link
Collaborator

gmlewis commented Feb 27, 2019

Note that this PR does not implement the recommendation in the above comment but it sounds to me like the API is not changing, so this solution would solve the issue and is fine with me.

We'll see if @gauntface agrees.

@dominicgunn
Copy link
Contributor Author

dominicgunn commented Feb 27, 2019

For some deeper clarity, this is against a enterprise version of Github (GHE), I'm not sure how much difference that would make.

In terms of allowing this to be definable by the user, I'm not against it but it feels superfluous given that the only accepted value will be "web".

Thanks @radeksimko for reaching out to Github support, I'm sorry I haven't been more involved in the discussion here.

@gauntface
Copy link
Contributor

I'm ok with this landing, but it does sound like a bug in GHE if you are getting an error without the name field.

@radeksimko
Copy link
Contributor

radeksimko commented Feb 27, 2019

In terms of allowing this to be definable by the user, I'm not against it but it feels superfluous given that the only accepted value will be "web".

Having it definable would help us a lot in the Terraform GitHub provider as we still haven't upgraded SDK since this field was removed and if the field is put back we can deprecate it more gracefully and easily, rather than just pulling the cord and forcing everyone to change their configurations.

Also we might actually not deprecate it at all as there might be some plans in the future around that field as the GitHub Support folk mentioned.

I'm willing to PR that change separately though.

@sourabh3b
Copy link

Hi All,
Adding my thoughts to the conversation.
I am facing the same issue.
Getting this error, while adding a webhook to a repo using go-github client : "name" wasn't supplied. []
It's due to the field "name" in POST /repos/:owner/:repo/hooks API. The documentation at https://developer.github.com/v3/repos/hooks/#create-a-hook says that name is not required, whereas enterprise documentation at https://developer.github.com/enterprise/2.14/v3/repos/hooks/#create-a-hook says that both name and config are required. Hence I am able to add webhook using Postman but not using go-github client.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, everyone, for your comments. This should help GitHub Enterprise users.
LGTM.
Merging.

@gmlewis gmlewis merged commit d173fe3 into google:master Feb 27, 2019
@dominicgunn dominicgunn deleted the webhook_fix branch February 28, 2019 09:52
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants