Show More
@@ -0,0 +1,93 b'' | |||
|
1 | #!/usr/bin/env python | |
|
2 | # | |
|
3 | # A small script to automatically reject idle Diffs | |
|
4 | # | |
|
5 | # you need to set the PHABBOT_USER and PHABBOT_TOKEN environment variable for authentication | |
|
6 | from __future__ import absolute_import, print_function | |
|
7 | ||
|
8 | import datetime | |
|
9 | import os | |
|
10 | import sys | |
|
11 | ||
|
12 | import phabricator | |
|
13 | ||
|
14 | MESSAGE = """There seems to have been no activities on this Diff for the past 3 Months. | |
|
15 | ||
|
16 | By policy, we are automatically moving it out of the `need-review` state. | |
|
17 | ||
|
18 | Please, move it back to `need-review` without hesitation if this diff should still be discussed. | |
|
19 | ||
|
20 | :baymax:need-review-idle: | |
|
21 | """ | |
|
22 | ||
|
23 | ||
|
24 | PHAB_URL = "https://phab.mercurial-scm.org/api/" | |
|
25 | USER = os.environ.get("PHABBOT_USER", "baymax") | |
|
26 | TOKEN = os.environ.get("PHABBOT_TOKEN") | |
|
27 | ||
|
28 | ||
|
29 | NOW = datetime.datetime.now() | |
|
30 | ||
|
31 | # 3 months in seconds | |
|
32 | DELAY = 60 * 60 * 24 * 30 * 3 | |
|
33 | ||
|
34 | ||
|
35 | def get_all_diff(phab): | |
|
36 | """Fetch all the diff that the need review""" | |
|
37 | return phab.differential.query( | |
|
38 | status="status-needs-review", | |
|
39 | order="order-modified", | |
|
40 | paths=[('HG', None)], | |
|
41 | ) | |
|
42 | ||
|
43 | ||
|
44 | def filter_diffs(diffs, older_than): | |
|
45 | """filter diffs to only keep the one unmodified sin <older_than> seconds""" | |
|
46 | olds = [] | |
|
47 | for d in diffs: | |
|
48 | modified = int(d['dateModified']) | |
|
49 | modified = datetime.datetime.fromtimestamp(modified) | |
|
50 | d["idleFor"] = idle_for = NOW - modified | |
|
51 | if idle_for.total_seconds() > older_than: | |
|
52 | olds.append(d) | |
|
53 | return olds | |
|
54 | ||
|
55 | ||
|
56 | def nudge_diff(phab, diff): | |
|
57 | """Comment on the idle diff and reject it""" | |
|
58 | diff_id = int(d['id']) | |
|
59 | phab.differential.createcomment( | |
|
60 | revision_id=diff_id, message=MESSAGE, action="reject" | |
|
61 | ) | |
|
62 | ||
|
63 | ||
|
64 | if not USER: | |
|
65 | print( | |
|
66 | "not user specified please set PHABBOT_USER and PHABBOT_TOKEN", | |
|
67 | file=sys.stderr, | |
|
68 | ) | |
|
69 | elif not TOKEN: | |
|
70 | print( | |
|
71 | "not api-token specified please set PHABBOT_USER and PHABBOT_TOKEN", | |
|
72 | file=sys.stderr, | |
|
73 | ) | |
|
74 | sys.exit(1) | |
|
75 | ||
|
76 | phab = phabricator.Phabricator(USER, host=PHAB_URL, token=TOKEN) | |
|
77 | phab.connect() | |
|
78 | phab.update_interfaces() | |
|
79 | print('Hello "%s".' % phab.user.whoami()['realName']) | |
|
80 | ||
|
81 | diffs = get_all_diff(phab) | |
|
82 | print("Found %d Diffs" % len(diffs)) | |
|
83 | olds = filter_diffs(diffs, DELAY) | |
|
84 | print("Found %d old Diffs" % len(olds)) | |
|
85 | for d in olds: | |
|
86 | diff_id = d['id'] | |
|
87 | status = d['statusName'] | |
|
88 | modified = int(d['dateModified']) | |
|
89 | idle_for = d["idleFor"] | |
|
90 | msg = 'nudging D%s in "%s" state for %s' | |
|
91 | print(msg % (diff_id, status, idle_for)) | |
|
92 | # uncomment to actually affect phab | |
|
93 | nudge_diff(phab, d) |
@@ -24,6 +24,7 b' outputs, which should be fixed later.' | |||
|
24 | 24 | > -X contrib/packaging/hg-docker \ |
|
25 | 25 | > -X contrib/packaging/hgpackaging/ \ |
|
26 | 26 | > -X contrib/packaging/inno/ \ |
|
27 | > -X contrib/phab-clean.py \ | |
|
27 | 28 | > -X contrib/python-zstandard/ \ |
|
28 | 29 | > -X contrib/win32/hgwebdir_wsgi.py \ |
|
29 | 30 | > -X contrib/perf-utils/perf-revlog-write-plot.py \ |
General Comments 0
You need to be logged in to leave comments.
Login now