Skip to content

Fixes #1938: Add "extra labels" in new issue webhook#1944

Merged
karlcow merged 4 commits intomasterfrom
issues/1938/1
Nov 30, 2017
Merged

Fixes #1938: Add "extra labels" in new issue webhook#1944
karlcow merged 4 commits intomasterfrom
issues/1938/1

Conversation

@miketaylr
Copy link
Copy Markdown
Member

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

@miketaylr
Copy link
Copy Markdown
Member Author

r? @karlcow
r? @zoepage (to get more familiar with the python code)

Copy link
Copy Markdown
Member

@karlcow karlcow left a 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.

Comment thread webcompat/form.py Outdated

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.

Comment thread webcompat/form.py
formdata = {
'metadata': get_metadata(('browser', 'ua_header', 'reported_with'),
form_object),
'metadata': get_metadata(metadata_keys, form_object),

This comment was marked as abuse.

Comment thread 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.

@miketaylr
Copy link
Copy Markdown
Member Author

There are missing tests.

Ha yeah, just came here to comment that I still have tests to write. :)

Thanks for review so far!

@karlcow
Copy link
Copy Markdown
Member

karlcow commented Nov 29, 2017

huh… I had a full comment about changing the strategy on helpers.py and it's not there. huh.

Copy link
Copy Markdown
Member

@karlcow karlcow left a 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.

Comment thread 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.

@miketaylr
Copy link
Copy Markdown
Member Author

OK, there's a few things I don't love about this, will comment inline. But it works, yay?

Comment thread 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.

This comment was marked as abuse.

Comment thread 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.

This comment was marked as abuse.

return metadata_dict


def extract_browser_label(metadata_dict):

This comment was marked as abuse.

@miketaylr
Copy link
Copy Markdown
Member Author

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.

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Copy Markdown
Member

@karlcow karlcow left a 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.

Comment thread 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.

return extra_label.encode('utf-8')
else:
return None

This comment was marked as abuse.

This comment was marked as abuse.

"""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.

Comment thread tests/test_webhook.py Outdated
"""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.

Comment thread 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.

Comment thread 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.

@miketaylr
Copy link
Copy Markdown
Member Author

OK, round 3. r? @karlcow

Copy link
Copy Markdown
Member

@karlcow karlcow left a 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.

@karlcow
Copy link
Copy Markdown
Member

karlcow commented Nov 30, 2017

There is a check fail because of indentation and line length in test_webhook, I'll fix it in a follow up issue.

@karlcow karlcow merged commit 4f36857 into master Nov 30, 2017
@karlcow
Copy link
Copy Markdown
Member

karlcow commented Nov 30, 2017

Thanks a lot @miketaylr

@miketaylr
Copy link
Copy Markdown
Member Author

There is a check fail because of indentation and line length in test_webhook, I'll fix it in a follow up issue.

(I pushed a commit that fixed this on master... sorry about that)

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.

3 participants