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) |
@@ -1,39 +1,40 b'' | |||||
1 | #require test-repo |
|
1 | #require test-repo | |
2 |
|
2 | |||
3 | $ . "$TESTDIR/helpers-testrepo.sh" |
|
3 | $ . "$TESTDIR/helpers-testrepo.sh" | |
4 | $ import_checker="$TESTDIR"/../contrib/import-checker.py |
|
4 | $ import_checker="$TESTDIR"/../contrib/import-checker.py | |
5 |
|
5 | |||
6 | $ cd "$TESTDIR"/.. |
|
6 | $ cd "$TESTDIR"/.. | |
7 |
|
7 | |||
8 | There are a handful of cases here that require renaming a module so it |
|
8 | There are a handful of cases here that require renaming a module so it | |
9 | doesn't overlap with a stdlib module name. There are also some cycles |
|
9 | doesn't overlap with a stdlib module name. There are also some cycles | |
10 | here that we should still endeavor to fix, and some cycles will be |
|
10 | here that we should still endeavor to fix, and some cycles will be | |
11 | hidden by deduplication algorithm in the cycle detector, so fixing |
|
11 | hidden by deduplication algorithm in the cycle detector, so fixing | |
12 | these may expose other cycles. |
|
12 | these may expose other cycles. | |
13 |
|
13 | |||
14 | Known-bad files are excluded by -X as some of them would produce unstable |
|
14 | Known-bad files are excluded by -X as some of them would produce unstable | |
15 | outputs, which should be fixed later. |
|
15 | outputs, which should be fixed later. | |
16 |
|
16 | |||
17 | $ testrepohg locate 'set:**.py or grep(r"^#!.*?python")' \ |
|
17 | $ testrepohg locate 'set:**.py or grep(r"^#!.*?python")' \ | |
18 | > 'tests/**.t' \ |
|
18 | > 'tests/**.t' \ | |
19 | > -X hgweb.cgi \ |
|
19 | > -X hgweb.cgi \ | |
20 | > -X setup.py \ |
|
20 | > -X setup.py \ | |
21 | > -X contrib/automation/ \ |
|
21 | > -X contrib/automation/ \ | |
22 | > -X contrib/debugshell.py \ |
|
22 | > -X contrib/debugshell.py \ | |
23 | > -X contrib/hgweb.fcgi \ |
|
23 | > -X contrib/hgweb.fcgi \ | |
24 | > -X contrib/packaging/hg-docker \ |
|
24 | > -X contrib/packaging/hg-docker \ | |
25 | > -X contrib/packaging/hgpackaging/ \ |
|
25 | > -X contrib/packaging/hgpackaging/ \ | |
26 | > -X contrib/packaging/inno/ \ |
|
26 | > -X contrib/packaging/inno/ \ | |
|
27 | > -X contrib/phab-clean.py \ | |||
27 | > -X contrib/python-zstandard/ \ |
|
28 | > -X contrib/python-zstandard/ \ | |
28 | > -X contrib/win32/hgwebdir_wsgi.py \ |
|
29 | > -X contrib/win32/hgwebdir_wsgi.py \ | |
29 | > -X contrib/perf-utils/perf-revlog-write-plot.py \ |
|
30 | > -X contrib/perf-utils/perf-revlog-write-plot.py \ | |
30 | > -X doc/gendoc.py \ |
|
31 | > -X doc/gendoc.py \ | |
31 | > -X doc/hgmanpage.py \ |
|
32 | > -X doc/hgmanpage.py \ | |
32 | > -X i18n/posplit \ |
|
33 | > -X i18n/posplit \ | |
33 | > -X mercurial/thirdparty \ |
|
34 | > -X mercurial/thirdparty \ | |
34 | > -X tests/hypothesishelpers.py \ |
|
35 | > -X tests/hypothesishelpers.py \ | |
35 | > -X tests/test-check-interfaces.py \ |
|
36 | > -X tests/test-check-interfaces.py \ | |
36 | > -X tests/test-demandimport.py \ |
|
37 | > -X tests/test-demandimport.py \ | |
37 | > -X tests/test-imports-checker.t \ |
|
38 | > -X tests/test-imports-checker.t \ | |
38 | > -X tests/test-verify-repo-operations.py \ |
|
39 | > -X tests/test-verify-repo-operations.py \ | |
39 | > | sed 's-\\-/-g' | "$PYTHON" "$import_checker" - |
|
40 | > | sed 's-\\-/-g' | "$PYTHON" "$import_checker" - |
General Comments 0
You need to be logged in to leave comments.
Login now