-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repo.py
69 lines (56 loc) · 2.05 KB
/
Repo.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pycurl
import certifi
from io import BytesIO
import json
class Repo:
def __init__(self, url):
self.base_url = url
self.user, self.name = self.id = self.set_id()
self.transformed_url = self.url_transformer()
self.label_url = self.url_transformer(True)
self.issues = self.updated_issues()
self.labels = self.updated_labels()
self.filtered_issues = []
@staticmethod
def get_from_url(url):
buffer = BytesIO()
curl = pycurl.Curl()
curl.setopt(curl.URL, url)
curl.setopt(curl.WRITEDATA, buffer)
curl.setopt(curl.CAINFO, certifi.where())
curl.perform()
curl.close()
return buffer
def updated_issues(self):
return json.loads(self.get_from_url(self.transformed_url).getvalue().decode('iso-8859-1'))
def updated_labels(self):
return json.loads(self.get_from_url(self.label_url).getvalue().decode('iso-8859-1'))
def set_id(self):
url = self.base_url
split_url = url.split('/')
user, repo = split_url[-3], split_url[-2]
return user, repo
def url_transformer(self, for_labels=False):
url = f"https://api.github.com/repos/{self.user}/{self.name}/"
return url + "labels" if for_labels else url + "issues"
def print_issues(self):
for issue in self.issues:
if issue['labels']:
print(issue['labels'])
def print_labels(self):
for label in self.labels:
print(label['name'])
def filter_issues(self, wl):
"""Returns issues that match at least a word from the wordlist.
Args:
repo: Repo object representing a GitHub repository.
wl: A list of words.
Returns:
The curated list containing only matching issues.
"""
for issue in self.issues:
for label in issue['labels']:
for word in wl:
if word in label['name']:
self.filtered_issues.append(issue)
break