From 53be8313c0502d08a90bf618f34aead5857c2449 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Thu, 22 Dec 2022 18:22:12 +0100 Subject: [PATCH] Improve ci checks [noissue] --- .ci/scripts/validate_commit_message.py | 25 ++++++++----------------- .github/workflows/main.yml | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index 44ef5e37a..1c1c0524b 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -4,6 +4,7 @@ import sys from pathlib import Path +import toml from github import Github KEYWORDS = ["fixes", "closes"] @@ -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] @@ -38,7 +31,7 @@ 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.") @@ -46,7 +39,7 @@ def __check_status(issue): 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: @@ -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)) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e35bc7af..8e5885471 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }}