This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
forked from webcompat/webcompat.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.py
49 lines (40 loc) · 1.67 KB
/
issues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
'''Module that handles submission of issues via the GitHub API, both for an
authed user and the proxy case.'''
import json
from webcompat import app
from webcompat import github
from webcompat.form import build_formdata
from webcompat.helpers import proxy_request
from webcompat.helpers import REPO_URI
def report_issue(form, proxy=False):
'''Report an issue, as a logged in user or anonymously.'''
# /repos/:owner/:repo/issues
path = 'repos/{0}'.format(REPO_URI)
if proxy:
return proxy_request('post', path,
data=json.dumps(build_formdata(form)))
else:
return github.post(path, build_formdata(form))
def filter_new(issues):
'''Return the list of new issues, encoded as JSON.
"new" means anything that isn't an issue with a "contactready",
"sitewait", or "needsdiagnosis" label.
'''
def is_new(issue):
'''Filter function.'''
match = True
category_list = ['status-contactready', 'status-needscontact',
'status-needsdiagnosis', 'status-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_new(issue)])