From abcb761ae1be8625cf06786778c1e31c01003d8c Mon Sep 17 00:00:00 2001 From: Mike DePaulo Date: Tue, 17 Oct 2023 10:25:18 -0400 Subject: [PATCH] Update validate_commit_message.py [noissue] --- .ci/scripts/validate_commit_message.py | 63 +++++++++++++++----------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index 2bc6f02b..fd6e1156 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -1,63 +1,74 @@ # WARNING: DO NOT EDIT! # -# This file was generated by plugin_template, and is managed by bootstrap.py. Please use -# bootstrap.py to update this file. +# This file was generated by plugin_template, and is managed by it. Please use +# './plugin-template --github pulp_file' to update this file. # # For more info visit https://github.com/pulp/plugin_template -import glob -import os import re -import subprocess import sys +from pathlib import Path +import subprocess + +import os +import warnings from github import Github -KEYWORDS = ["fixes", "closes", "re", "ref"] -NO_ISSUE = "[noissue]" -CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation", ".dev"] +NO_ISSUE = "[noissue]" +CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation"] sha = sys.argv[1] message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8") + + +KEYWORDS = ["fixes", "closes"] + g = Github(os.environ.get("GITHUB_TOKEN")) -repo = g.get_repo("pulp/pulp-oci-images") +repo = g.get_repo("pulp/pulp_file") 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: + if gi.closed_at and "cherry picked from commit" not in message: + warnings.warn( + "When backporting, use the -x flag to append a line that says " + "'(cherry picked from commit ...)' to the original commit message." + ) sys.exit(f"Error: issue #{issue} is closed.") def __check_changelog(issue): - matches = glob.glob("CHANGES/{issue}.*".format(issue=issue)) + matches = list(Path("CHANGES").rglob(f"{issue}.*")) if len(matches) < 1: - sys.exit("Could not find changelog entry in CHANGES/ for {issue}.".format(issue=issue)) + sys.exit(f"Could not find changelog entry in CHANGES/ for {issue}.") for match in matches: - if os.path.splitext(match)[1] not in CHANGELOG_EXTS: - sys.exit("Invalid extension for changelog entry '{match}'.".format(match=match)) + if match.suffix not in CHANGELOG_EXTS: + sys.exit(f"Invalid extension for changelog entry '{match}'.") + if match.suffix == ".feature" and "cherry picked from commit" in message: + sys.exit(f"Can not backport '{match}' as it is a feature.") print("Checking commit message for {sha}.".format(sha=sha[0:7])) # validate the issue attached to the commit -if NO_ISSUE in message: - print("Commit {sha} has no issue attached. Skipping issue check".format(sha=sha[0:7])) -elif "Merge" in message and "cherry picked from commit" in message: - pass -else: - regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS)) - pattern = re.compile(regex, re.IGNORECASE) +regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS)) +pattern = re.compile(regex, re.IGNORECASE) - issues = pattern.findall(message) +issues = pattern.findall(message) - if issues: - for issue in pattern.findall(message): - __check_status(issue) - __check_changelog(issue) +if issues: + for issue in pattern.findall(message): + __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)) + elif "Merge" in message and "cherry picked from commit" in message: + pass else: sys.exit( "Error: no attached issues found for {sha}. If this was intentional, add "