forked from cockpit-project/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissues-review
executable file
·38 lines (30 loc) · 1.3 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
#!/usr/bin/env python3
import argparse
import time
from task import github
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 main():
parser = argparse.ArgumentParser(description='Add review label to stale 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('--repo', help='Work on this GitHub repository (owner/name)')
opts = parser.parse_args()
api = github.GitHub(repo=opts.repo)
issues_review(api, opts)
if __name__ == '__main__':
main()