Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .ci/scripts/check_changelog_snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/env python3
# /// script
# requires-python = ">=3.11"
# dependencies = [
# ]
# ///
import re
import sys
from pathlib import Path

import tomllib

EXCEPTIONS = [
".TEMPLATE.md",
".gitkeep",
"pulp-glue",
]


def snippet_valid(path: Path, changelog_exts: list[str]) -> bool:
return (path.name in EXCEPTIONS) or (
path.suffix in changelog_exts
and (path.stem.startswith("+") or re.fullmatch(r"\d*", path.stem))
)


if __name__ == "__main__":
with Path("pyproject.toml").open("rb") as fp:
pyproject_toml = tomllib.load(fp)
changelog_exts = [
f".{item['directory']}" for item in pyproject_toml["tool"]["towncrier"]["type"]
]
matches = Path("CHANGES").rglob("*")
invalid_snippets = ", ".join(f"'{s}'" for s in matches if not snippet_valid(s, changelog_exts))
if invalid_snippets:
sys.exit(f"LINT: Invalid changelog entries: {invalid_snippets}.")
2 changes: 1 addition & 1 deletion .ci/scripts/pr_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from git import Repo


def main():
def main() -> None:
assert len(sys.argv) == 3

with Path("pyproject.toml").open("rb") as fp:
Expand Down
6 changes: 4 additions & 2 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ def check_changelog(issue: str) -> None:
print(f"Checking commit message for {sha[0:7]}.")

# validate the issue attached to the commit
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(
keywords=("|").join(re.escape(k) for k in KEYWORDS)
)
issues = re.findall(issue_regex, message, re.IGNORECASE)
cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$"
cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE)

if issues:
for issue in issues:
if not cherry_pick:
check_status(issue)
check_changelog(issue)
check_status(issue)

print(f"Commit message for {sha[0:7]} passed.")
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ _lint:
find tests .ci -name '*.sh' -print0 | xargs -0 shellcheck -x
ruff format --check --diff
ruff check --output-format concise
.ci/scripts/check_changelog_snippets.py
.ci/scripts/check_click_for_mypy.py
mypy
cd pulp-glue; mypy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/env python3
# /// script
# requires-python = ">=3.11"
# dependencies = [
# ]
# ///
import re
import sys
from pathlib import Path

import tomllib

EXCEPTIONS = [
".TEMPLATE.md",
".gitkeep",
{%- if cookiecutter.glue %}
"pulp-glue{{ cookiecutter.__app_label_suffix}}",
{%- endif %}
]


def snippet_valid(path: Path, changelog_exts: list[str]) -> bool:
return (path.name in EXCEPTIONS) or (
path.suffix in changelog_exts
and (path.stem.startswith("+") or re.fullmatch(r"\d*", path.stem))
)


if __name__ == "__main__":
with Path("pyproject.toml").open("rb") as fp:
pyproject_toml = tomllib.load(fp)
changelog_exts = [
f".{item['directory']}" for item in pyproject_toml["tool"]["towncrier"]["type"]
]
matches = Path("CHANGES").rglob("*")
invalid_snippets = ", ".join(f"'{s}'" for s in matches if not snippet_valid(s, changelog_exts))
if invalid_snippets:
sys.exit(f"LINT: Invalid changelog entries: {invalid_snippets}.")
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from git import Repo


def main():
def main() -> None:
assert len(sys.argv) == 3

with Path("pyproject.toml").open("rb") as fp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ def check_changelog(issue: str) -> None:
print(f"Checking commit message for {sha[0:7]}.")

# validate the issue attached to the commit
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(
keywords=("|").join(re.escape(k) for k in KEYWORDS)
)
issues = re.findall(issue_regex, message, re.IGNORECASE)
cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$"
cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE)

if issues:
for issue in issues:
if not cherry_pick:
check_status(issue)
check_changelog(issue)
check_status(issue)

print(f"Commit message for {sha[0:7]} passed.")
1 change: 1 addition & 0 deletions cookiecutter/ci/{{ cookiecutter.__project_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ _lint:
{%- if cookiecutter.glue and cookiecutter.app_label %}
.ci/scripts/check_cli_dependencies.py
{%- endif %}
.ci/scripts/check_changelog_snippets.py
.ci/scripts/check_click_for_mypy.py
mypy
{%- if cookiecutter.glue %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dev = [
]
lint = [
{include-group = "test"},
"mypy~=1.20.0",
"mypy~=2.4.0",
"ruff~=0.16.0",
"shellcheck-py~=0.11.0.1",
"types-pygments",
Expand Down
Loading