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

Add webhook modeling to projects #2764

Merged
merged 9 commits into from
May 10, 2017
Merged

Conversation

agjohnson
Copy link
Contributor

@agjohnson agjohnson commented Mar 30, 2017

This will add Integration models, which include just webhooks for now. This
extends the integrations page to list integrations, and allows for
per-integration syncing now as well. The brute force method of resyncing
webhooks will be replaced by this work.

See #2755 for more context on the the scope of this work. This also depends on #2745 and can be rebased after that is merged.

This work does not currently attempt to consolidate code, and there might be
some redundancy. The next phase of this work should be to consolidate the oauth
representations and remote modeling into a single place.

  • New features
  • Tests
  • Docs

@agjohnson agjohnson added the PR: work in progress Pull request is not ready for full review label Mar 30, 2017
@agjohnson agjohnson force-pushed the project-integration-webhook branch 2 times, most recently from 24f800f to 841c4d5 Compare April 21, 2017 18:42
@agjohnson
Copy link
Contributor Author

There are a few places I noted required some more testing, and I owe docs here as well. This will require rebasing on master after #2745 is merged for better display.

@agjohnson agjohnson force-pushed the project-integration-webhook branch from 77fbfe6 to 5359231 Compare April 25, 2017 20:32
@agjohnson agjohnson requested a review from ericholscher April 27, 2017 06:19
@agjohnson agjohnson added PR: ready for review and removed PR: work in progress Pull request is not ready for full review labels Apr 27, 2017
@agjohnson agjohnson added this to the Webhook admin dashboard milestone Apr 27, 2017
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 like a great change. Mostly just have some nits and questions.

updated within seconds is an awesome feeling.
The primary method that Read the Docs uses to detect changes to your
documentation is through the use of *webhooks*. Webhooks are configured with
your repository provider and with each commit, merge, or other change to your
Copy link
Member

Choose a reason for hiding this comment

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

repository provider (like GitHub)?

The primary method that Read the Docs uses to detect changes to your
documentation is through the use of *webhooks*. Webhooks are configured with
your repository provider and with each commit, merge, or other change to your
repository, Read the Docs is notified. When this happens, we determine if the
Copy link
Member

Choose a reason for hiding this comment

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

s/When this happens/When we recieve the webhook/

Webhook creation
----------------

If you import a project using a connected account, a webhook will be set up
Copy link
Member

Choose a reason for hiding this comment

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

connected account?

can click **Add integration** and select the integration type you'd like to add.
In order to set up a new webhook with your provider, you'll need the *webhook
URL*. You can get this URL by selecting the integration you just added on the
list of integrations.
Copy link
Member

Choose a reason for hiding this comment

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

You can get this URL by selecting the integration you just added on the list of integrations. sounds confusing, and could be more explicit. Should we be returning them to the detail page, instead of the listing, when they add a new integration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, yeah. There's no good reason not to redirect the user there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added redirect in 8eb590d

integrations, this integration has a specific URL, found on the integration
detail page. This integration can either be added manually or may be created
automatically if you had previously set up a webhook with your provider
manually.
Copy link
Member

Choose a reason for hiding this comment

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

This integration can either be added manually or may be created automatically if you had previously set up a webhook with your provider manually. Not sure what this is saying. It I previously set it up manually its now automatic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you previously created a webhook manually, it will automatically create an integration when we receive data. I can clarify here.


def default_token():
"""Generate default value for token field"""
return ''.join([int_to_base36(randrange(sys.maxint)) for _ in range(2)])
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be cryptographically secure, or is it just a hash? I feel like Django has a way to generate these that can't be guessed.

Either way, we should document the thread profile of it.

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 isn't a hash of any data in particular, so cryptographic security here isn't a concern. Randomization is the primary concern instead.

This was brought in from our auth token implementation, I'm not aware of a built-in token in Django. DRF uses this as a token generator:
https://github.com/encode/django-rest-framework/blob/master/rest_framework/authtoken/models.py#L37-L38

It might be best to replace this with the DRF version, as randrange(sys.maxint) has about 1:1000000000000000 chance of being 4 chars or less, or with concatenation of two of these strings, something like 1:1e-30 chance of being 8 characters or less.

GITHUB_WEBHOOK = 'github_webhook'
BITBUCKET_WEBHOOK = 'bitbucket_webhook'
GITLAB_WEBHOOK = 'gitlab_webhook'
API_WEBHOOK = 'api_webhook'
Copy link
Member

Choose a reason for hiding this comment

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

Should these be defined in a constants.py file, instead of on the class directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Django docs have recommended on the model class for these constants:
https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.Field.choices

project)
try:
log.debug('Bitbucket webhook update failure response: %s',
resp.json())
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure I had a patch that removed the json() call because it blows up on non-JSON data. We should comment here if we don't want to capture non-JSON return data.

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 commented on the last PR that I was fixing this way.

that a webhook has ever been created on our side. Most providers don't
pass the webhook ID in either, so we default to just finding *any*
integration from the provider. This is not ideal, but the
:py:class:`WebhookView` view solves this by perfomring a lookup on the
Copy link
Member

Choose a reason for hiding this comment

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

typo

token = self.request.data.get('token')
if token:
integration = self.get_integration()
obj = Project.objects.get(**kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to catch a DoesNotExist here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is currently bubbling up to be caught in the calling function

@agjohnson
Copy link
Contributor Author

This should be about set now. If the new changes look okay, we should get this merged and out this week.

@agjohnson agjohnson merged commit a66bd56 into master May 10, 2017
@agjohnson agjohnson deleted the project-integration-webhook branch May 10, 2017 21:01
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.

2 participants