Skip to content

Commit

Permalink
Changelog validation: ensure changelog filename matches the package name
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbayburt committed Jan 16, 2025
1 parent 919081e commit 5da086b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/changelogs/changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<author>.<feature>'"
MISSING_NEWLINE = "Missing newline at the end"
WRONG_CAP = "Wrong capitalization"
WRONG_SPACING = "Wrong spacing"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"]:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/changelogs/test_changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5da086b

Please sign in to comment.