Skip to content

Commit

Permalink
Improve ci checks
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
mdellweg committed Feb 13, 2023
1 parent 888f1d2 commit 53be831
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
25 changes: 8 additions & 17 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from pathlib import Path

import toml
from github import Github

KEYWORDS = ["fixes", "closes"]
Expand All @@ -15,16 +16,8 @@
"EXPERIMENT",
]
NO_ISSUE = "[noissue]"
# TODO (On a rainy afternoon) Fetch the extensions from pyproject.toml
CHANGELOG_EXTS = [
".feature",
".bugfix",
".doc",
".removal",
".misc",
".deprecation",
".translation",
".devel",
f"{item['directory']}." for item in toml.load("pyproject.toml")["tool"]["towncrier"]["type"]
]

sha = sys.argv[1]
Expand All @@ -38,15 +31,15 @@
repo = g.get_repo("pulp/pulp-cli")


def __check_status(issue):
def check_status(issue):
gi = repo.get_issue(int(issue))
if gi.pull_request:
sys.exit(f"Error: issue #{issue} is a pull request.")
if gi.closed_at:
sys.exit(f"Error: issue #{issue} is closed.")


def __check_changelog(issue):
def check_changelog(issue):
matches = list(Path("CHANGES").rglob(f"{issue}.*"))

if len(matches) < 1:
Expand All @@ -60,14 +53,12 @@ def __check_changelog(issue):

# validate the issue attached to the commit
regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
pattern = re.compile(regex, re.IGNORECASE)

issues = pattern.findall(message)
issues = re.findall(regex, message, re.IGNORECASE)

if issues:
for issue in pattern.findall(message):
__check_status(issue)
__check_changelog(issue)
for issue in issues:
check_status(issue)
check_changelog(issue)
else:
if NO_ISSUE in message:
print("Commit {sha} has no issues but is tagged {tag}.".format(sha=sha[0:7], tag=NO_ISSUE))
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
python-version: "3.10"
- name: Install python dependencies
run: |
pip install pygithub
pip install toml pygithub
- name: Check commit message
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down

0 comments on commit 53be831

Please sign in to comment.