forked from cockpit-project/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues-review
executable file
·92 lines (74 loc) · 3.31 KB
/
issues-review
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
#!/usr/bin/env python3
import argparse
import time
from task import github
bug_msg = """
This issue is closed due to inactivity.
If you are still able to reproduce it, please comment here and provide us with
an updated reproducer.
"""
rfe_msg = """
This issue is closed due to inactivity.
We are sorry, but we won't be able to address this in any time soon.
If you are interested in helping us with the implementation, please comment here.
"""
general_msg = """
This issue is closed due to inactivity.
If this issue is a bug report and you are still able to reproduce it, please
comment here and provide us with an updated reproducer.
If this issue is a request for a new feature, we are sorry, but we won't be able
to address this in any time soon. If you are interested in helping us with
the implementation, please comment here.
"""
def issues_review(api, opts):
now = time.time()
treshold = opts.age * 86400
count = 100
page = 1
while count == 100:
issues = api.get("issues?filter=all&page=%i&per_page=%i" % (page, count))
page += 1
count = len(issues)
for issue in issues:
age = now - time.mktime(time.strptime(issue["updated_at"], "%Y-%m-%dT%H:%M:%SZ"))
if age >= treshold:
print("Labelling #%i last updated at %s" % (issue["number"], issue["updated_at"]))
api.post("issues/%i/labels" % issue["number"], [opts.label])
def close_issues(api, opts):
count = 100
page = 1
while count == 100:
issues = api.get("issues?filter=all&page=%i&per_page=%i&labels=%s" % (page, count, opts.label))
page += 1
count = len(issues)
for issue in issues:
labels = api.get("issues/%i/labels" % issue["number"])
enhancement = [l for l in labels if l["name"] == "enhancement"]
bug = [l for l in labels if l["name"] == "bug"]
if bug:
print("Closing #%i as stale bug" % issue["number"])
api.post("issues/%i/comments" % issue["number"], {"body": bug_msg})
elif enhancement:
print("Closing #%i as stale enhancement" % issue["number"])
api.post("issues/%i/comments" % issue["number"], {"body": rfe_msg})
else:
print("Closing #%i as stale bug or enhancement" % issue["number"])
api.post("issues/%i/comments" % issue["number"], {"body": general_msg})
api.post("issues/%i" % issue["number"], {"state": "closed"})
def main():
parser = argparse.ArgumentParser(description='Label or close labeled stable issues')
parser.add_argument('-a', '--age', metavar='DAYS', default=90,
help='Label issues whose last update is older than given number of days (default: %(default)s)')
parser.add_argument('-l', '--label', default=time.strftime('review-%Y-%m'),
help='Label name (default: %(default)s)')
parser.add_argument('-c', '--close', action='store_true',
help='Close all issues with the label')
parser.add_argument('--repo', help='Work on this GitHub repository (owner/name)')
opts = parser.parse_args()
api = github.GitHub(repo=opts.repo)
if opts.close:
close_issues(api, opts)
else:
issues_review(api, opts)
if __name__ == '__main__':
main()