forked from yugabyte/yugabyte-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-diff-name.py
executable file
·76 lines (65 loc) · 3.2 KB
/
check-diff-name.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
#!/usr/bin/env python3
import os
import re
import argparse
from subprocess import check_output
DIFF_NAME_RE = re.compile(
r'(?P<backport>\[BACKPORT [0-9\.\-]+\])?\[(?P<issues>(#[0-9]+, )*#[0-9]+)\] '
r'(?P<area>[\w,\s]+): (?P<description>.{10,100})$')
# Tests - correct and incorrect samples
CORRECT_NAMES = {
"multiple issue numbers": "[#1234, #1235] area: Ideally short title",
"one issue and one backport": "[BACKPORT 2.2-1][#1235] area: Ideally short title",
"one issue, no backports": "[#1235] area: Ideally short title",
"different issue numbers": "[BACKPORT 2.2-1][#1235, #1, #10292012] area: Ideally short title",
"complex area":
"[BACKPORT 2.2-1][#1235] area of, probably, some 1 Interest: Ideally short title"
}
for reason, cname in CORRECT_NAMES.items():
assert DIFF_NAME_RE.match(cname), \
f"New DIFF_NAME_RE doesn't match on '{cname}' which has '{reason}'"
INCORRECT_NAMES = {
"more than one backport in one diff":
"[BACKPORT 2.1][BACKPORT 2.2-1][#1235, #1, #10292012] area: Ideally short title",
"illegal literal in build number for backport":
"[BACKPORT 2.2-b1][#1235, #1, #10292012] area: Ideally short title",
"wrong issues list (trailing comma)":
"[BACKPORT 2.2-1][#1235, #1, #10292012,] area: Ideally short title",
"wrong issue number (comma)":
"[BACKPORT 2.2-1][#1,235, #1, #10292012] area: Ideally short title",
"wrong issues list (leading comma)":
"[BACKPORT 2.2-1][,#1235, #1, #10292012] area: Ideally short title",
"wrong issue number (dash)":
"[BACKPORT 2.2-1][#12-5, #b1, #1029?2012] area: Ideally short title",
"too short title":
"[BACKPORT 2.2-1][#1235, #1, #10292012] area: Ideally s",
"too long title":
"[BACKPORT 2.2-1][#1235, #1, #10292012] area: Ideally short title Ideally short title "
"Ideally short title Ideally short title Ideally short title ..."
}
for reason, iname in INCORRECT_NAMES.items():
assert not DIFF_NAME_RE.match(iname), \
f"New DIFF_NAME_RE doesn't warn on '{iname}' which has '{reason}'"
parser = argparse.ArgumentParser(
description="Tool to check Phabricator diff name of current working copy (CWD)")
parser.add_argument('--base', '-b', action='store_true',
help='Use master branch as merge base to detect diff (for arc which call)')
parser.add_argument('--repository', '-r', default=os.path.dirname(__file__),
help='What repository to inspect')
args = parser.parse_args()
arc_which_cmd = ['arc', 'which']
if args.base:
arc_which_cmd += ['--base', 'git:merge-base(origin/master)']
arc_which_out = check_output(arc_which_cmd, cwd=args.repository).decode('utf-8')
diff_descs = re.findall('D[0-9]+.*', arc_which_out)
if diff_descs:
for diff_desc in diff_descs:
diff_id, diff_name = re.search('(D[0-9]+) (.*)', diff_desc).groups()
parsed_diff_name = DIFF_NAME_RE.match(diff_name)
if parsed_diff_name:
print(f"ok: Diff {diff_id} has correct name")
else:
print(f"error: Diff {diff_id} name "
f"should fit '{DIFF_NAME_RE.pattern}' but it is '{diff_name}'")
else:
print("advice: No diffs were found, time to create one ?")