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

feat: Allow disabling parsing of provider-specific references

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