From 5da086b95d2058142fecc53d7b6a8e5906255f90 Mon Sep 17 00:00:00 2001 From: Can Bulut Bayburt Date: Wed, 15 Jan 2025 15:50:57 +0100 Subject: [PATCH] Changelog validation: ensure changelog filename matches the package name --- .github/workflows/changelogs/changelogs.py | 6 +++++- .github/workflows/changelogs/test_changelogs.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/changelogs/changelogs.py b/.github/workflows/changelogs/changelogs.py index 0434118d33ce..5c2c6cd35aee 100644 --- a/.github/workflows/changelogs/changelogs.py +++ b/.github/workflows/changelogs/changelogs.py @@ -73,6 +73,7 @@ class IssueType: MISSING_CHLOG = "Changelog not added" WRONG_CHLOG = "Changelog added without changes" EMPTY_CHLOG = "No changelog entries found" + INVALID_CHLOG_FILENAME = "Changelog filename must be in format: '{}.changes..'" MISSING_NEWLINE = "Missing newline at the end" WRONG_CAP = "Wrong capitalization" WRONG_SPACING = "Wrong spacing" @@ -265,7 +266,7 @@ def get_modified_files_for_pkg(self, pkg_path: str, pkg_name: str, files: list[s for f in files: # Check if the file exists in a subdirectory of the base path of the package if f.startswith(pkg_path): - if os.path.basename(f).startswith(pkg_name + ".changes."): + if ".changes." in os.path.basename(f): # Ignore if the change is a removal if os.path.isfile(os.path.join(self.uyuni_root, f)): pkg_chlogs.append(f) @@ -629,6 +630,9 @@ def validate(self, file_list: list[str]) -> list[Issue]: if not files["changes"]: # Files are modified but no changelog file added issues.append(Issue(IssueType.MISSING_CHLOG, package=pkg)) + for chlog_file in files["changes"]: + if not os.path.basename(chlog_file).startswith(f"{pkg}.changes."): + issues.append(Issue(IssueType.INVALID_CHLOG_FILENAME.format(pkg), package=pkg)) # Validate each changelog file and gather all the issues for file in files["changes"]: diff --git a/.github/workflows/changelogs/test_changelogs.py b/.github/workflows/changelogs/test_changelogs.py index 6cb99a107123..f9d4a05e7e50 100644 --- a/.github/workflows/changelogs/test_changelogs.py +++ b/.github/workflows/changelogs/test_changelogs.py @@ -491,6 +491,14 @@ def test_validate_chlog_for_wrong_pkg(validator, chlog_file): ) +def test_validate_chlog_invalid_filename(validator, base_path): + chlog_file = base_path / "pkg/path/invalid.changes.my.feature" + chlog_file.write_text("- This is a changelog entry.\n") + issues = validator.validate(["pkg/path/invalid.changes.my.feature", "pkg/path/myfile.txt"]) + assert len(issues) == 1, issues_to_str(issues, 1) + assert IssueType.INVALID_CHLOG_FILENAME.format("mypkg") in str(issues[0]) and "mypkg" in str(issues[0]) + + def test_validate_change_in_subdir(validator, base_path): chlog_file = base_path / "pkg/other/otherpkg.changes.my.feature" chlog_file.write_text("- This is a changelog entry.\n")