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

533/1 Refactoring and adding needscontact #534

Merged
merged 4 commits into from
Jan 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
sys.path.append(os.path.realpath(os.pardir))
import webcompat

from webcompat.issues import filter_untriaged

# Any request that depends on parsing HTTP Headers (basically anything
# on the index route, will need to include the following: environ_base=headers
headers = {'HTTP_USER_AGENT': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; '
Expand Down Expand Up @@ -79,6 +81,30 @@ def test_issues_list_page(self):
self.assertEqual(rv.status_code, 200)
self.assertNotEqual(rv.status_code, 307)

def test_issues_untriaged(self):
'''Test that the untriaged filtering is correct.'''
issues = [
{u'labels': [{u'name': u'bug'}, {u'name': u'help wanted'}],
u'title': u"fake bug 0",
u'id': 0},
{u'labels': [],
u'title': u"fake bug 1",
u'id': 1},
{u'labels': [{u'name': u'contactready'}],
u'title': u"fake bug 2",
u'id': 2},
{u'labels': [{u'name': u'needsdiagnosis'}],
u'title': u"fake bug 3",
u'id': 3},
{u'labels': [{u'name': u'needscontact'}],
u'title': u"fake bug 4",
u'id': 4},
{u'labels': [{u'name': u'sitewait'}],
u'title': u"fake bug 5",
u'id': 5}]
result = '[{"labels": [{"name": "bug"}, {"name": "help wanted"}], "id": 0, "title": "fake bug 0"}, {"labels": [], "id": 1, "title": "fake bug 1"}]'
self.assertEqual(filter_untriaged(issues), result)


if __name__ == '__main__':
unittest.main()
16 changes: 9 additions & 7 deletions webcompat/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def get_issue_category(issue_category):
* needsdiagnosis
* sitewait
'''
category_list = ['contactready', 'needsdiagnosis', 'sitewait']
category_list = ['contactready', 'needscontact',
'needsdiagnosis', 'sitewait']
issues_path = 'repos/{0}'.format(ISSUES_PATH)
params = request.args.copy()

Expand Down Expand Up @@ -184,18 +185,19 @@ def get_category_from_search(issue_category):
the home page - but this endpoint returns paginated results.

Note: until GitHub fixes a bug where requesting issues filtered by labels
doesn't return pagination via Link, we get those results from this endpoint.
Once it's fixed, we can get "contactready", "needsdiagnosis" and "sitewait"
issues from /issues/category/<issue_category>.
doesn't return pagination via Link, we get those results from this
endpoint. Once it's fixed, we can get "contactready", "needsdiagnosis"
and "sitewait" issues from /issues/category/<issue_category>.
'''
category_list = ['contactready', 'needsdiagnosis', 'sitewait']
category_list = ['contactready', 'needscontact',
'needsdiagnosis', 'sitewait']
params = request.args.copy()

if issue_category in category_list:
query_string = 'label:{0}'.format(issue_category)
elif issue_category == 'untriaged':
query_string = ('state:open -label:contactready '
'-label:sitewait -label:needsdiagnosis')
query_string = ' '.join(['-label:%s' % cat for cat in category_list])
query_string += ' state:open '
return get_search_results(query_string, params)


Expand Down
18 changes: 8 additions & 10 deletions webcompat/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ def filter_untriaged(issues):
def is_untriaged(issue):
'''Filter function.'''
match = True
if issue.get('labels') == []:
match = True
else:
for label in issue.get('labels'):
if 'contactready' in label.get('name'):
match = False
elif 'needsdiagnosis' in label.get('name'):
match = False
elif 'sitewait' in label.get('name'):
match = False
category_list = ['contactready', 'needscontact',
'needsdiagnosis', 'sitewait']
labels = [label.get('name') for label in issue.get('labels')]
# if the intersection of labels and category_list is not empty
# then it's not part of untriaged
common_cat = set(labels).intersection(category_list)
if common_cat:
match = False
return match

return json.dumps([issue for issue in issues if is_untriaged(issue)])