-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
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.
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']) |
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.
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.
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.
Roger, I suppose it's possible we have some old webhook configurations lingering then.
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.
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.
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.
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) |
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.
Seems less explicit than telling folks they need to POST.
if request.method == 'POST': | ||
payload = request.POST.get('payload') |
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.
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?
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.
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: |
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.
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) |
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.
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} |
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.
This code feels like it could be abstracted, and it's the same for GH/BB except for a couple lines.
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.
Yeah, I debated this, it felt odd both ways. I'll clean this up somehow.
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. |
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 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.
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
54ced28
to
d4d3322
Compare
Fixes #2424
an RTD service on GitHub
request.POST['payload']
from all old webhooks, not sure what it was