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

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

Merged
merged 4 commits into from
Nov 30, 2017
Merged

Conversation

miketaylr
Copy link
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
Member Author

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

Copy link
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.

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

formdata = {
'metadata': get_metadata(('browser', 'ua_header', 'reported_with'),
form_object),
'metadata': get_metadata(metadata_keys, form_object),

This comment was marked as abuse.

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

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
Member Author

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.

This comment was marked as abuse.

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

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.

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

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.

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
Member Author

OK, round 3. r? @karlcow

Copy link
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
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
Member

karlcow commented Nov 30, 2017

Thanks a lot @miketaylr

@miketaylr
Copy link
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