Коммит cf41a97d создал по автору Timothée Mazzucotelli's avatar Timothée Mazzucotelli
Просмотр файлов

feat: Allow disabling parsing of provider-specific references

владелец 6520cbac
......@@ -158,6 +158,7 @@ class Changelog:
repository: str,
provider: ProviderRefParser | None = None,
style: StyleType | None = None,
parse_provider_refs: bool = True,
):
"""
Initialization method.
......@@ -166,8 +167,10 @@ class Changelog:
repository: The repository (directory) for which to build the changelog.
provider: The provider to use (github.com, gitlab.com, etc.).
style: The commit style to use (angular, atom, etc.).
parse_provider_refs: Whether to parse provider-specific references in the commit messages.
"""
self.repository: str = repository
self.parse_provider_refs: bool = parse_provider_refs
# set provider
if not provider:
......@@ -298,7 +301,7 @@ class Changelog:
# expand commit object with provider parsing
if self.provider:
commit.update_with_provider(self.provider)
commit.update_with_provider(self.provider, self.parse_provider_refs)
elif self.remote_url:
# set the commit url based on remote_url (could be wrong)
......
......@@ -75,6 +75,14 @@ def get_parser() -> argparse.ArgumentParser:
default=sys.stdout,
help="Output to given file. Default: stdout.",
)
parser.add_argument(
"-R",
"--no-parse-refs",
action="store_false",
dest="parse_refs",
default=True,
help="Do not parse provider-specific references in commit messages (issues, PRs, etc.).",
)
parser.add_argument(
"-s", "--style", choices=STYLES, default="basic", dest="style", help="The commit style to match against."
)
......@@ -124,7 +132,11 @@ def main(args: list[str] | None = None) -> int:
template = templates.get_template(opts.template)
# build data
changelog = Changelog(opts.repository, style=opts.style)
changelog = Changelog(
opts.repository,
style=opts.style,
parse_provider_refs=opts.parse_refs,
)
# get rendered contents
rendered = template.render(changelog=changelog)
......
......@@ -84,12 +84,13 @@ class Commit:
"""
self.style.update(style.parse_commit(self))
def update_with_provider(self, provider: ProviderRefParser) -> None:
def update_with_provider(self, provider: ProviderRefParser, parse_refs: bool = True) -> None: # noqa: WPS231
"""
Apply the provider-parsed data to this commit.
Arguments:
provider: The provider to use.
parse_refs: Whether to parse references for this provider.
"""
# set the commit url based on provider
# FIXME: hardcoded 'commits'
......@@ -100,14 +101,15 @@ class Commit:
self.url = f"{provider.url}/{provider.namespace}/{provider.project}/commit/{self.hash}"
# build commit text references from its subject and body
for ref_type in provider.REF.keys():
self.text_refs[ref_type] = provider.get_refs(ref_type, "\n".join([self.subject] + self.body))
if "issues" in self.text_refs:
self.text_refs["issues_not_in_subject"] = []
for issue in self.text_refs["issues"]:
if issue.ref not in self.subject:
self.text_refs["issues_not_in_subject"].append(issue)
if parse_refs:
for ref_type in provider.REF.keys():
self.text_refs[ref_type] = provider.get_refs(ref_type, "\n".join([self.subject] + self.body))
if "issues" in self.text_refs:
self.text_refs["issues_not_in_subject"] = []
for issue in self.text_refs["issues"]:
if issue.ref not in self.subject:
self.text_refs["issues_not_in_subject"].append(issue)
class CommitStyle(ABC):
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать