Fixes #1938: Add "extra labels" in new issue webhook#1944
Conversation
karlcow
left a comment
There was a problem hiding this comment.
- Some coding suggestions.
- There are missing tests.
|
|
||
| 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.
| 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. |
karlcow
left a comment
There was a problem hiding this comment.
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.
| 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? |
| 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.
| 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.
| 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.
karlcow
left a comment
There was a problem hiding this comment.
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.
| 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.
| 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.
| """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.
| 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.
| 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 |
karlcow
left a comment
There was a problem hiding this comment.
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