From 6eacc273cd2235920c47452b2b2c43839874b20d Mon Sep 17 00:00:00 2001 From: Karl Dubost Date: Thu, 31 May 2018 11:15:19 +0900 Subject: [PATCH] Issue #1971 - Makes stricter the label construction 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 #2372 we will come to it later. --- tests/unit/test_webhook.py | 11 +++++++---- webcompat/webhooks/helpers.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_webhook.py b/tests/unit/test_webhook.py index 274c39094..12c7261bc 100644 --- a/tests/unit/test_webhook.py +++ b/tests/unit/test_webhook.py @@ -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) @@ -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) diff --git a/webcompat/webhooks/helpers.py b/webcompat/webhooks/helpers.py index c1c4f3fae..dde4fe272 100644 --- a/webcompat/webhooks/helpers.py +++ b/webcompat/webhooks/helpers.py @@ -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. @@ -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):