Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Aug 30, 2022
1 parent 6d66907 commit 103ae42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ci/jenkins/Prepare.groovy.j2
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def check_pr(pr_number) {
variable: 'GITHUB_TOKEN',
)]) {
sh (
script: "python3 tests/scripts/check_pr.py --pr ${pr_number}",
script: "python3 ci/scripts/check_pr.py --pr ${pr_number}",
label: 'Check PR title and body',
)
}
Expand Down
40 changes: 21 additions & 19 deletions tests/scripts/check_pr.py → ci/scripts/check_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

GITHUB_USERNAME_REGEX = re.compile(r"(@[a-zA-Z0-9-]+)", flags=re.MULTILINE)
OK = object()
FAIL = object()


@dataclass
Expand All @@ -42,48 +43,44 @@ class Check:

def non_empty(s: str):
if len(s) == 0:
return False
return FAIL
return OK


def usernames(s: str):
m = GITHUB_USERNAME_REGEX.findall(s)
if m and len(m) > 0:
return m
return OK
return m if m else OK


def tags(s: str):
items = tags_from_title(s)
if len(items) == 0:
return False
return FAIL
return OK


def trailing_period(s: str):
if s.endswith("."):
return False
return FAIL
return OK


title_checks = [
Check(check=non_empty, error_fn=lambda d: "PR must have a title but title was empty"),
Check(check=trailing_period, error_fn=lambda d: "PR must not end in a tailing '.'"),
Check(
check=usernames,
error_fn=lambda d: f"PR title must not tag anyone but found these usernames: {d}",
),
Check(
check=tags,
error_fn=lambda d: f"PR title must have a topic tag like [the_topic] (e.g. [tir], [relay], etc.) but found none",
),
# TODO(driazati): enable this check once https://github.com/apache/tvm/issues/12637 is done
# Check(
# check=usernames,
# error_fn=lambda d: f"PR title must not tag anyone but found these usernames: {d}",
# ),
]
body_checks = [
Check(check=non_empty, error_fn=lambda d: "PR must have a body but body was empty"),
Check(
check=usernames,
error_fn=lambda d: f"PR body must not tag anyone but found these usernames: {d}",
),
# TODO(driazati): enable this check once https://github.com/apache/tvm/issues/12637 is done
# Check(
# check=usernames,
# error_fn=lambda d: f"PR body must not tag anyone but found these usernames: {d}",
# ),
]


Expand Down Expand Up @@ -139,6 +136,9 @@ def run_checks(checks: List[Check], s: str, name: str) -> bool:
body = pr["body"]
title = pr["title"]

body = body.strip()
title = title.strip()

title_passed = run_checks(checks=title_checks, s=title, name="PR title")
print("")
body_passed = run_checks(checks=body_checks, s=body, name="PR body")
Expand All @@ -147,5 +147,7 @@ def run_checks(checks: List[Check], s: str, name: str) -> bool:
print("All checks passed!")
exit(0)
else:
print("Some checks failed, please review the logs above")
print(
"Some checks failed, please review the logs above and edit your PR on GitHub accordingly"
)
exit(1)

0 comments on commit 103ae42

Please sign in to comment.