Skip to content

Commit

Permalink
fix: Add github fixes footer support, and make footer lookups case in…
Browse files Browse the repository at this point in the history
…sensitive
  • Loading branch information
EdgyEdgemond committed Aug 22, 2024
1 parent 37e93ae commit 6520681
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog_gen/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
FOOTER_PARSERS = [
r"(Refs)(: )(#?[\w-]+)",
r"(closes)( )(#[\w-]+)",
r"(fixes)( )(#[\w-]+)",
r"(Authors)(: )(.*)",
]

Expand Down
10 changes: 5 additions & 5 deletions changelog_gen/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __lt__(self: t.Self, other: Change) -> bool: # noqa: D105
def issue_ref(self: t.Self) -> str:
"""Extract issue ref from footers."""
for footer in self.footers:
if footer.footer in ("Refs", "closes"):
if footer.footer.lower() in ("refs", "closes", "fixes"):
return footer.value
return ""

Expand Down Expand Up @@ -100,7 +100,7 @@ def extract(self: t.Self) -> list[Change]: # noqa: C901, PLR0912, PLR0915
if prm is not None:
# Strip githubs additional link information from description.
description = re.sub(r" \(#\d+\)$", "", description)
footers["PR"] = Footer("PR", ": ", prm.group()[1:-1])
footers["pr"] = Footer("PR", ": ", prm.group()[1:-1])
details = m[5] or ""

# Handle missing refs in commit message, skip link generation in writer
Expand All @@ -117,10 +117,10 @@ def extract(self: t.Self) -> list[Change]: # noqa: C901, PLR0912, PLR0915

for line in details.split("\n"):
for parser in self.context.config.footer_parsers:
m = re.match(parser, line)
m = re.match(parser, line, re.IGNORECASE)
if m is not None:
self.context.info(" '%s' footer extracted '%s%s%s'", parser, m[1], m[2], m[3])
footers[m[1]] = Footer(m[1], m[2], m[3])
footers[m[1].lower()] = Footer(m[1], m[2], m[3])

header = self.type_headers.get(commit_type, commit_type)
change = Change(
Expand All @@ -142,7 +142,7 @@ def extract(self: t.Self) -> list[Change]: # noqa: C901, PLR0912, PLR0915
link_template = parser["link"]
links.append(Link(text_template.format(change), link_template.format(change)))
else:
footer = footers.get(parser["target"])
footer = footers.get(parser["target"].lower())
if footer is None:
continue
text_template = parser.get("text", "{0}")
Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_config_displayed(cli_runner):
footer_parsers = [
'(Refs)(: )(#?[\w-]+)',
'(closes)( )(#[\w-]+)',
'(fixes)( )(#[\w-]+)',
'(Authors)(: )(.*)',
]
link_parsers = []
Expand Down
9 changes: 5 additions & 4 deletions tests/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def conventional_commits(multiversion_repo):
"fix typo",
"""feat(docs)!: Detail about 3
Refs: #3
Fixes #3
""",
"""fix: Detail about 1
Expand Down Expand Up @@ -98,6 +98,7 @@ def test_git_commit_extraction(conventional_commits):
hashes = conventional_commits
link_parsers = [
{"target": "Refs", "pattern": r"#(\d+)$", "link": "https://github.com/NRWLDev/changelog-gen/issues/{0}"},
{"target": "fixes", "pattern": r"#(\d+)$", "link": "https://github.com/NRWLDev/changelog-gen/issues/{0}"},
{"target": "Authors", "pattern": r"@(\w+)[, ]?", "link": "https://github.com/{0}", "text": "@{0}"},
{
"target": "__change__",
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_git_commit_extraction(conventional_commits):
commit_hash=hashes[2],
commit_type="feat",
footers=[
Footer("Refs", ": ", "#3"),
Footer("Fixes", " ", "#3"),
],
links=[
Link("3", "https://github.com/NRWLDev/changelog-gen/issues/3"),
Expand Down Expand Up @@ -227,7 +228,7 @@ def test_git_commit_extraction_include_all(conventional_commits):
commit_hash=hashes[2],
commit_type="feat",
footers=[
Footer("Refs", ": ", "#3"),
Footer("Fixes", " ", "#3"),
],
),
Change(
Expand Down Expand Up @@ -307,7 +308,7 @@ def test_git_commit_extraction_handles_random_tags(conventional_commits, multive
commit_hash=hashes[2],
commit_type="feat",
footers=[
Footer("Refs", ": ", "#3"),
Footer("Fixes", " ", "#3"),
],
),
Change(
Expand Down

0 comments on commit 6520681

Please sign in to comment.