-
Notifications
You must be signed in to change notification settings - Fork 203
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
Fixes #1938: Add "extra labels" in new issue webhook #1944
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.
- Some coding suggestions.
- There are missing tests.
webcompat/form.py
Outdated
@@ -210,9 +210,13 @@ def build_formdata(form_object): | |||
else: | |||
summary = '{0} - {1}'.format(normalized_url, problem_summary) | |||
|
|||
metadata_keys = ['browser', 'ua_header', 'reported_with'] | |||
extra_label = form_object.get('extra_label', None) | |||
if extra_label and extra_label in app.config['EXTRA_LABELS']: |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
formdata = { | ||
'metadata': get_metadata(('browser', 'ua_header', 'reported_with'), | ||
form_object), | ||
'metadata': get_metadata(metadata_keys, form_object), |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
webcompat/webhooks/helpers.py
Outdated
labels.append(priority_label) | ||
for label in (browser_label, extra_label, priority_label): | ||
if label: | ||
labels.append(label) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Ha yeah, just came here to comment that I still have tests to write. :) Thanks for review so far! |
huh… I had a full comment about changing the strategy on helpers.py and it's not there. huh. |
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.
An additional comment I thought I had made in the previous Review. I was sure I did it. I must have forgotten to add… :(
Anyway.
webcompat/webhooks/helpers.py
Outdated
Currently this only handles a single label, | ||
because that's all that we set in webcompat.com. | ||
""" | ||
match_list = re.search(r'<!--\s@extra_label:\s([\w-]+)\s-->', body) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
da3823b
to
8094eac
Compare
OK, there's a few things I don't love about this, will comment inline. But it works, yay? |
tests/test_webhook.py
Outdated
self.assertEqual(browser_label, 'browser-firefox') | ||
browser_label_none = helpers.extract_browser_label(self.issue_body2) | ||
browser_label_none = helpers.extract_browser_label( | ||
helpers.extract_metadata(self.issue_body2)) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
webcompat/webhooks/helpers.py
Outdated
match_list = re.findall(r'<!--\s@(\w+):\s(.+)\s-->', body) | ||
# Build a dict but only for the first seen instance of a key | ||
# (in case there are duplicates added by the user after) | ||
metadata_dict = {} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
webcompat/webhooks/helpers.py
Outdated
return metadata_dict | ||
|
||
|
||
def extract_browser_label(metadata_dict): |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
r? @karlcow |
"""Return the browser label from metadata_dict.""" | ||
browser = metadata_dict.get('browser', None) | ||
# Only proceed if browser looks like "FooBrowser 99.0" | ||
if browser and re.search(r'([^\d]+?)\s[\d\.]+', browser): |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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 are still missing tests extract_metadata
.
The code did it by chaining but that's not good for unittests :) If in the future one of the two functions fail, it will be harder to discover which one.
and see more suggestions and trimming code where it's possible.
We are getting closer.
webcompat/webhooks/helpers.py
Outdated
match_list = re.findall(r'<!--\s@(\w+):\s(.+)\s-->', body) | ||
# Build a dict but only for the first seen instance of a key | ||
# (in case there are duplicates added by the user after) | ||
metadata_dict = {} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
webcompat/webhooks/helpers.py
Outdated
return extra_label.encode('utf-8') | ||
else: | ||
return None | ||
|
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
"""Return the browser label from metadata_dict.""" | ||
browser = metadata_dict.get('browser', None) | ||
# Only proceed if browser looks like "FooBrowser 99.0" | ||
if browser and re.search(r'([^\d]+?)\s[\d\.]+', browser): |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
tests/test_webhook.py
Outdated
@@ -133,15 +139,41 @@ def test_fails_on_not_known_action(self): | |||
|
|||
def test_extract_browser_label(self): | |||
"""Extract browser label name.""" | |||
browser_label = helpers.extract_browser_label(self.issue_body) | |||
browser_label = helpers.extract_browser_label( | |||
helpers.extract_metadata(self.issue_body)) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
tests/test_webhook.py
Outdated
self.assertEqual(browser_label, 'browser-firefox') | ||
browser_label_none = helpers.extract_browser_label(self.issue_body2) | ||
browser_label_none = helpers.extract_browser_label( | ||
helpers.extract_metadata(self.issue_body2)) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
tests/test_webhook.py
Outdated
self.assertEqual(extra_label, 'type-media') | ||
extra_label_none = helpers.extract_extra_label( | ||
helpers.extract_metadata(self.issue_body2)) | ||
self.assertEqual(extra_label_none, None) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This adds an extract_metadata method which the other helpers use.
…tion methods/tests.
8094eac
to
9681903
Compare
OK, round 3. r? @karlcow |
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.
ok let's do it.
Thanks for the modifications mike.
There is a check fail because of indentation and line length in test_webhook, I'll fix it in a follow up issue. |
Thanks a lot @miketaylr |
(I pushed a commit that fixed this on master... sorry about that) |
Tested with this branch deployed to staging:
with &label=type-stylo in params:
https://staging.webcompat.com/issues/1310
without label param (just to prove things still work):
https://staging.webcompat.com/issues/1311