Skip to content

Commit

Permalink
Allow link in changelog scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ezr-ondrej committed Aug 30, 2023
1 parent b410d01 commit 8f5742a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/rhenvision_changelog/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from git_changelog import templates
from git_changelog.build import Changelog
from git_changelog.providers import GitHub, RefDef, RefRe
from git_changelog.commit import AngularConvention, Commit

RefRe.BBB = r"(?:^|[\s,]|\(|/)" # blank or bracket before
RefRe.BBA = r"(?:[\s,]|$)|\)" # blank or bracket after
Expand All @@ -30,8 +31,22 @@ def build_ref_url(self, ref_type: str, match_dict: Dict[str, str]) -> str: # no
match_dict["jira_url"] = self.jira_url
if not match_dict.get("jira_project"):
match_dict["jira_project"] = self.jira_project

return super().build_ref_url(ref_type, match_dict)

class AngularJiraConvention(AngularConvention):
"""A class to enhance scope by an Jira issue URL."""

def parse_commit(self, commit: Commit):
result = super().parse_commit(commit)
scope = result["scope"]
if isinstance(scope, str) and "issues" in commit.text_refs:
for issue in commit.text_refs["issues"]:
if issue.ref in scope:
result["scope"] = "[{}]({})".format(scope, issue.url)

return result


class ProvisioningChangelog(Changelog):
"""A class to represent a Provisioning common project changelog."""
Expand All @@ -46,9 +61,9 @@ def __init__(self, repository: str, jira_url: str, jira_project: str, limit=None
namespace, project = "/".join(split[3:-1]), split[-1]

provider = GitHubJiraProvider(namespace, project, jira_url, jira_project)
super().__init__(repository, provider=provider, convention="angular", parse_provider_refs=True)
super().__init__(repository, provider=provider, convention=AngularJiraConvention, parse_provider_refs=True)

def get_log(self) -> str:
def get_log(self):
"""Get the `git log` output possibly limited by limit passed to constructor.
Returns:
Expand Down
37 changes: 37 additions & 0 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Test changelog parses Jira issues properly"""

from rhenvision_changelog.changelog import ProvisioningChangelog
from rhenvision_changelog.commit_check import check_commit

jira_project = "HMS"
commit_head = """a5bc1e0f00aed28102579d14d651a27d5dded4a4
John Doe
[email protected]
1669736056
John Doe
[email protected]
1669736056
HEAD -> branch, origin/branch
"""

class StubbedChangelog(ProvisioningChangelog):
def __init__(self, commit_message):
self.commit_message = commit_message
super().__init__('.', 'https://jira.test.com', jira_project)

def get_log(self) -> str:
"""Get stubbed `git log` output defined by stub passed to constructor.
Returns:
The stubbed `git log` in a particular format.
"""
return commit_head + self.commit_message + "\n\n"+self.MARKER+"\n"

def get_remote_url(self) -> str:
return "https://github.com/RHEnVision/provisioning"



def test_jira_issue_parsing() -> int:
changelog = StubbedChangelog("feat(HMS-123): Subject")
assert changelog.commits[0].convention["scope"] == "[HMS-123](https://jira.test.com/browse/HMS-123)"

0 comments on commit 8f5742a

Please sign in to comment.