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

Refactor webhooks, add modern webhooks, and fix issues with Bitbucket #2433

Merged
merged 3 commits into from
Oct 5, 2016

Conversation

agjohnson
Copy link
Contributor

@agjohnson agjohnson commented Oct 2, 2016

Fixes #2424

  • Adds new API endpoint for webhook consumption
  • Adds webhook signals for future use
  • Cleans up old webhook implementations
  • Fixes old Bitbucket webhook implementation
  • Sets new webhooks to point to API endpoint
  • Removes GitHub service creation by naming the webhook 'web' -- 'readthedocs' created
    an RTD service on GitHub
  • Updates Gitlab fixture data with example from API
  • Drops request.POST['payload'] from all old webhooks, not sure what it was
  • Made tests actually send JSON to webhook views

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This is a great change, not having to map incoming pushes to projects. It will definitely make stuff easier going forward.

We should also update the "webhook URL" thats output on the project page, and update the documentation here as well.

if request.method == 'POST':
try:
# GitHub RTD integration
obj = json.loads(request.POST['payload'])
Copy link
Member

@ericholscher ericholscher Oct 4, 2016

Choose a reason for hiding this comment

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

This is required for old GitHub hooks that POST'd with form data, instead of a straight JSON post. I believe we need to keep it around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger, I suppose it's possible we have some old webhook configurations lingering then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, that would mean GitHub was sending the payload as JSON encoded in the payload field? I don't see any signs that this was the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! nevermind, found it and you are correct on the usage here:
https://developer.github.com/webhooks/creating/#content-type

else:
return HttpResponse("You must POST to this resource.")
return HttpResponse('Method not allowed', status=405)
Copy link
Member

Choose a reason for hiding this comment

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

Seems less explicit than telling folks they need to POST.

if request.method == 'POST':
payload = request.POST.get('payload')
Copy link
Member

Choose a reason for hiding this comment

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

Think this is similarly required for old BB API's no? We're depending on request.body being JSON here, but presumably this code was working previously, so some BB requests were using this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where I'm more confused. I think that may have been the case with old POST services from bitbucket, but webhooks don't deliver x-www-form-urlencoded bodies?

Most I found was here:
https://confluence.atlassian.com/bitbucket/post-service-management-223216518.html

You're probably right in that we need to keep this here too.

branches = [request.data['ref'].replace('refs/heads/', '')]
except KeyError:
raise ParseError('Parameter "ref" is required')
if event == GITHUB_PUSH:
Copy link
Member

Choose a reason for hiding this comment

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

We should be logging when we get other events.

except KeyError:
raise ParseError('Parameter "ref" is required')
if event == GITHUB_PUSH:
to_build, not_building = build_branches(project, branches)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably not throw away the not_building list here -- would be useful to log if nothing else.

return {'build_triggered': triggered,
'project': project.slug,
'versions': to_build}
return {'build_triggered': False}
Copy link
Member

Choose a reason for hiding this comment

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

This code feels like it could be abstracted, and it's the same for GH/BB except for a couple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I debated this, it felt odd both ways. I'll clean this up somehow.

@ericholscher ericholscher added Needed: documentation Documentation is required Needed: patch A pull request is required Status: reviewed and removed PR: ready for review labels Oct 4, 2016
@agjohnson
Copy link
Contributor Author

Addressed this feedback in latest push, needs quick re-review.

I didn't add info to the project detail page -- this doesn't exist on that page and is the wrong page to add information like this anyways. I feel like what we want is a webhook admin dashboard page instead. This page should push users to connect their account to set up a webhook, it should contain the hidden resync webhook form, and a fallback to manual set up could list the custom webhook URLs for manual set up. I'll create an issue to address this later.

I didn't update the docs because of this, it's hard to communicate the webhook changes in docs. If we had a webhook admin page, it would supersede these docs anyways. The current docs aren't incorrect, so there's that at least.

@agjohnson agjohnson added PR: ready for review and removed Needed: documentation Documentation is required Needed: patch A pull request is required Status: reviewed labels Oct 5, 2016
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Looks good. I imagine it wasn't really possible to test the Post-commit changes, so I'm a bit weary about that, so we should make sure that doesn't blow up on deploy.

@agjohnson
Copy link
Contributor Author

I did do some testing with ngrok and fresh webhooks -- but yeah, can't feasibly test old webhooks or service pushes. Hopefully our test data is good enough coverage here. We'll need to plan to watch this deploy.

I'll rebase and merge this.

* Adds new API endpoint for webhook consumption
* Adds webhook signals for future use
* Cleans up old webhook implementations
* Fixes old Bitbucket webhook implementation
* Sets new webhooks to point to API endpoint
* Removes GitHub service creation by naming the webhook 'web' -- 'readthedocs' created
  an RTD service on GitHub
* Updates Gitlab fixture data with example from API
* Drops `request.POST['payload']` from all old webhooks, not sure what it was
* Made tests actually send JSON to webhook views
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.

Bitbucket webook trigger fails on private projects
2 participants