mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
The check-pr-title.py was created when we used travis (a long time ago).
Now, in github actions we can access to the pr title from ${{
github.event.pull_request.title }}
The idea of this change is to avoid checking in the github api and
simplify the check-pr-title.py tool.
This also is required to be able to use this check in private projects
where a unauthenticated api call is not allowed.
Also it is removed from the actions workflow the pr number variables
which are not used.
42 lines
1.0 KiB
Python
Executable File
42 lines
1.0 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
import re
|
|
|
|
|
|
class InvalidPRTitle(Exception):
|
|
def __init__(self, invalid_title):
|
|
self.invalid_title = invalid_title
|
|
|
|
|
|
def check_pr_title(pr_title: str):
|
|
print(pr_title)
|
|
# cover most common cases:
|
|
# package: foo
|
|
# package, otherpackage/subpackage: this is a title
|
|
# tests/regression/lp-12341234: foo
|
|
# [RFC] foo: bar
|
|
if not re.match(r"[a-zA-Z0-9_\-\*/,. \[\](){}]+: .*", pr_title):
|
|
raise InvalidPRTitle(pr_title)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"pr_title", metavar="PR title", help="the github title to check"
|
|
)
|
|
args = parser.parse_args()
|
|
try:
|
|
check_pr_title(args.pr_title)
|
|
except InvalidPRTitle as e:
|
|
print('Invalid PR title: "{}"\n'.format(e.invalid_title))
|
|
print("Please provide a title in the following format:")
|
|
print("module: short description")
|
|
print("E.g.:")
|
|
print("daemon: fix frobinator bug")
|
|
raise SystemExit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|