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

Fix #1228 - Improves webhooks to send labels at once #1566

Merged
merged 9 commits into from
May 24, 2017

Conversation

karlcow
Copy link
Member

@karlcow karlcow commented May 19, 2017

r? @miketaylr

Instead of sending two requests which might have created the issue #1553, we are now sending one request only.
We also created a bunch of additional tests in their own file.
Comments in each commit have additional details explaining the context.

You can test locally the Webhook by doing.

# start webcompat.com on localhost
python run.py
# In another shell
http POST http://localhost:5000/webhooks/labeler 'Content-Type:application/json' 'X-GitHub-Event: issues' 'X-Hub-Signature:sha1=43da93fa444d40c2bbec6c3b055ef29859870c79' < /path/to/webcompat.com/tests/fixtures/webhooks/new_event_valid.json

Testing

nosetests --verbosity=2 --nocapture 
API access to comments greater than 30 returns pagination in Link ... ok
API issue for a non existent number returns JSON 404. ... ok
API issue search with bad keywords returns JSON 404. ... ok
API access to labels without auth returns JSON 200. ... ok
API with wrong parameter returns JSON 404. ... ok
API setting labels without auth returns JSON 403 error code. ... ok
API access to user activity without auth returns JSON 401. ... ok
API with wrong category returns JSON 404. ... ok
API with wrong route returns JSON 404. ... ok
Checks that domain name is extracted. ... ok
Checks that metadata is processed and wrapped. ... ok
Checks that URL is normalized. ... ok
Test HTTP Links formating. ... ok
Test browser parsing via get_browser helper method. ... ok
Test browser name parsing via get_browser_name helper method. ... ok
Test name extraction from Dict via get_name helper method. ... ok
Test OS parsing via get_os helper method. ... ok
Test version string composition from Dict ... ok
Test that API params are correctly converted to Search API. ... ok
normalize_api_params shouldn't transform unknown params. ... ok
Test HTTP Links parsing for GitHub only. ... ok
test_rewrite_and_sanitize_link (tests.test_helpers.TestHelpers) ... ok
Test we're correctly rewriting the passed in link. ... ok
Test that we're removing access_token parameters. ... ok
Check Cache-Control for issues. ... ok
Check ETAG for issues. ... ok
Checks if we receive a 304 Not Modified. ... ok
Page title format for different URIs. ... ok
Test that Base64 screenshots return the expected status codes. ... ok
Test that /upload/ doesn't let you GET. ... ok
Test that uploaded files return the expected status code. ... ok
Test that /about exists. ... ok
Test that asks user to log in before displaying activity. ... ok
Test POST to /csp-report w/ correct content-type returns 204. ... ok
Test POST w/ wrong content-type to /csp-report returns 400. ... ok
Test that the home page exists. ... ok
Test issues and integer for: ... ok
Test that the /issues/<number> exists, and does not redirect. ... ok
Test that the /issues route gets 200 and does not redirect. ... ok
Test that the /login route 302s to GitHub. ... ok
Sends 400 to POST on /issues/new with missing parameters. ... ok
Test that /issues/new exists. ... ok
Checks 500 is not accepted for /issues/new POST. ... ok
Test that /privacy exists. ... ok
Rate Limit URI sends 410 Gone. ... ok
Test that the /tools/cssfixme route gets 200. ... ok
Test that the /tools/cssfixme route gets 200 with ?url query. ... ok
Test that the /tools/cssfixme route gets 200 with bad ?url query. ... ok
Extract browser label name. ... ok
POST without bogus signature on labeler webhook is forbidden. ... ok
POST with event not being 'issues' or 'ping' fails. ... ok
POST without signature on labeler webhook is forbidden. ... ok
POST with action different of opened fails. ... ok
GET is forbidden on labeler webhook. ... ok
POST with PING events just return a 200 and contains pong. ... ok

----------------------------------------------------------------------
Ran 55 tests in 6.471s

OK

or for just testing the webhook.

nosetests --verbosity=2 --nocapture tests/test_webhook.py

- We use the LOCALHOST key for testing
- Takes this opportunity to straighten a bit the way we create import.
We might want to do that in the future but for now, it is basically
unused code.
The goal is to make the function more usable in web hooks tests.
We now have a function to check
and one to compute a signature.
It makes also fixtures independent with regards to content change.
Only one case is not tested for now, when basically we are
communicating with GitHub.
There are a couple of strategies for mocking the service. It needs a
bit more cycles of thinking.
- Removes the GET. Flask handles this already for us
- Creates only 1 requests for setting labels instead of two, probably
avoiding race condition mentioned in webcompat#1553
- Sends plain/text messages where it is granted.
- Logs the failure when tagging didn’t happen properly
- Renames set_label as set_labels and rationalises the functions
Copy link
Member

@miketaylr miketaylr left a comment

Choose a reason for hiding this comment

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

LGTM. Just a few minor questions -- thanks Karl!


# Any request that depends on parsing HTTP Headers (basically anything
# on the index route, will need to include the following: environ_base=headers
headers = {'HTTP_USER_AGENT': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; '

This comment was marked as abuse.

This comment was marked as abuse.

}
uri = 'https://api.github.com/repos/{0}/{1}/labels'.format(
app.config['ISSUES_REPO_URI'], issue_number)
return requests.post(uri, data=json.dumps(payload), headers=headers)

This comment was marked as abuse.

This comment was marked as abuse.

@karlcow
Copy link
Member Author

karlcow commented May 24, 2017

@miketaylr Modifications done.

@miketaylr
Copy link
Member

Thanks Karl. Let's merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants