This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazy.py
executable file
·96 lines (73 loc) · 2.98 KB
/
lazy.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
import requests
from dateutil.parser import parse
from tzlocal import get_localzone
import pytz
from argparse import ArgumentParser
def parse_date(date):
tzinfo = get_localzone()
parsed_date = parse(date, dayfirst=True)
local_date = tzinfo.localize(parsed_date)
utc_date = local_date.astimezone(pytz.utc)
return utc_date
def search_for_issues(user, repo):
endpoint = 'https://api.github.com/search/issues?'\
'q=repo:{}/{}+type:issue+state:closed'.format(USER, REPO)
r = requests.get(endpoint)
return r.json()
def get_milestones_and_issues(data):
milestones = {}
issues = {}
for i in json['items']:
milestones[i['milestone']['title']] = {
'url': i['milestone']['html_url'],
'date': parse(i['milestone']['created_at'])
}
issues[i['title']] = {
'url': i['html_url'],
'milestone': i['milestone']['title'],
'date': parse(i['closed_at'])
}
return milestones, issues
def filter_by_date(milestones, issues, date):
issues_in_scope = {}
milestones_in_scope = {}
for i, v in issues.items():
if v['date'] >= date:
issues_in_scope[i] = v
for i, v in issues_in_scope.items():
m = v['milestone']
milestones_in_scope[m] = milestones[m]
return milestones_in_scope, issues_in_scope
def print_markdown(milestones_in_scope, issues_in_scope):
res = ''
for milestone in sorted(milestones_in_scope,
key=lambda f: milestones[f]['date']):
res += '\n[{}]({})\n'.format(milestone,
milestones_in_scope[milestone]['url'])
for issue, data in issues_in_scope.items():
if data['milestone'] == milestone:
res += '- [{}]({})\n'.format(issue, data['url'])
return res.strip('\n')
if __name__ == '__main__':
parser = ArgumentParser(description='Lists all closed issues for a '
'given GitHub repository from a certain date '
'until now')
parser.add_argument('-u', '--user', required=True,
help='Username owner of the GitHub repository')
parser.add_argument('-r', '--repo', required=True,
help='Repository from where we want to list '
'the closed issues')
parser.add_argument('-d', '--date', required=True,
help='Issues will be taken from this date. '
'Format %%D-%%M-%%Y')
args = parser.parse_args()
USER = args.user
REPO = args.repo
DATE = args.date
parsed_date = parse_date(DATE)
json = search_for_issues(USER, REPO)
milestones, issues = get_milestones_and_issues(json)
milestones_in_scope, issues_in_scope = filter_by_date(milestones,
issues, parsed_date)
print(print_markdown(milestones_in_scope, issues_in_scope))