forked from yugabyte/yugabyte-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: D10049 Test Plan: Common: - create new diff in any arc-enabled repo - run script against this repo: `../yugabyte-db/arcanist_util/check-diff-name.py -b -r ../internal-services` For `-b` flag: - create diff on branch - push this branch to git - run script without `-b` - it will not show any diff - run script with `-b` - it start seeing revision Reviewers: bogdan, mbautin, steve.varnau Reviewed By: steve.varnau Subscribers: steve.varnau, #devops Differential Revision: https://phabricator.dev.yugabyte.com/D10809
- Loading branch information
1 parent
f79a017
commit 045dffa
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 ?") |