Skip to content

Commit

Permalink
Issue webcompat#1971 - Makes stricter the label construction
Browse files Browse the repository at this point in the history
This doesn't solve everything, but it provides a way to mitigate some of the issues we met. It cut down a lot of possible values and variability. And the fallback being "fixme" if everything else fails, we can count on humans for guessing if possible the browser label.

This doesn't address yet the issue webcompat#2372 we will come to it later.
  • Loading branch information
karlcow committed May 31, 2018
1 parent db0cd4f commit 6eacc27
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
11 changes: 7 additions & 4 deletions tests/unit/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ def test_extract_browser_label(self):
({'browser': 'Firefox (tablet)'}, 'browser-fixme'),
({'browser': 'Firefox 30.0'}, 'browser-firefox'),
({'browser': 'Firefox Mobile 30.0'}, 'browser-firefox-mobile'),
({'browser': 'Firefox Mobile (Tablet) 88.0'},
'browser-firefox-mobile-tablet')
({'browser': 'Firefox Mobile (Tablet) 88.0'}, 'browser-firefox-tablet'), # noqa
({'browser': 'Firefox Mobile Nightly 59.0a1 (2017-12-04)'}, 'browser-firefox-mobile'), # noqa
({'browser': 'Mozilla/5.0 (Android 8.0.0; Mobile; rv:58.0) Gecko/58.0 Firefox/58.0'}, 'browser-fixme'), # noqa
({'browser': 'Firefox Developer Edition 60.0b14 (64-bit)'}, 'browser-firefox'), # noqa
({'browser': 'Firefox Mobile Nightly 61.0 & Firefox PC Nightly'}, 'browser-firefox-mobile'), # noqa
]
for metadata_dict, expected in metadata_tests:
actual = helpers.extract_browser_label(metadata_dict)
Expand Down Expand Up @@ -186,8 +189,8 @@ def test_get_issue_labels(self):
"""Extract list of labels from an issue body."""
labels_tests = [
(self.issue_body, ['browser-firefox', 'type-media', 'type-stylo']),
(self.issue_body2, ['type-foobar']),
(self.issue_body3, ['browser-firefox-mobile-tablet'])
(self.issue_body2, ['browser-fixme', 'type-foobar']),
(self.issue_body3, ['browser-firefox-tablet'])
]
for issue_body, expected in labels_tests:
actual = helpers.get_issue_labels(issue_body)
Expand Down
30 changes: 26 additions & 4 deletions webcompat/webhooks/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from webcompat.helpers import extract_url
from webcompat.helpers import proxy_request

BROWSERS = ['blackberry', 'brave', 'chrome', 'edge', 'firefox', 'iceweasel', 'ie', 'lynx', 'myie', 'opera', 'puffin', 'qq', 'safari', 'samsung', 'seamonkey', 'uc', 'vivaldi'] # noqa


def extract_metadata(body):
"""Parse all the hidden comments for issue metadata.
Expand All @@ -38,13 +40,33 @@ def extract_browser_label(metadata_dict):
# Only proceed if browser looks like "FooBrowser 99.0"
if browser and re.search(r'([^\d]+?)\s[\d\.]+', browser):
browser = browser.lower()
browser = browser.rsplit(' ', 1)[0]
browser = browser.encode('utf-8')
# Remove parenthesis from the name
browser = browser.translate(None, '()')
dash_browser = '-'.join(browser.split())
return 'browser-{name}'.format(name=dash_browser)
# Before returning a label, we need to clean up a bit
label_data = browser.split(' ')
# Let's focus on the known browser.
name = label_data[0]
if name not in BROWSERS:
browser_name = 'fixme'
else:
browser_name = label_data[0]
# Let's find a type for the browser.
remainder = label_data[1:]
browser_type = None
if 'mobile' in remainder:
browser_type = 'mobile'
if 'tablet' in remainder:
browser_type = 'tablet'
if browser_type:
dash_browser = '{browser_name}-{browser_type}'.format(
browser_name=browser_name,
browser_type=browser_type)
else:
dash_browser = browser_name
else:
return 'browser-fixme'
dash_browser = 'fixme'
return 'browser-{name}'.format(name=dash_browser)


def extract_extra_labels(metadata_dict):
Expand Down

0 comments on commit 6eacc27

Please sign in to comment.