From 43642c221dd849cc7f133f36bfe8f55445867818 Mon Sep 17 00:00:00 2001 From: Jonas Scharpf Date: Thu, 14 Nov 2024 19:20:05 +0100 Subject: [PATCH] Make URL to tags in rendered changelog configurable This fixes #33 --- .snippets/33.md | 8 ++++++++ README.md | 5 +++++ snippets2changelog/cli.py | 8 +++++++- snippets2changelog/creator.py | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 .snippets/33.md diff --git a/.snippets/33.md b/.snippets/33.md new file mode 100644 index 0000000..b52707e --- /dev/null +++ b/.snippets/33.md @@ -0,0 +1,8 @@ +## Make URL to tags in rendered changelog configurable + + +Introduce `--version-reference` to make the URL to the tags in the rendered changelog configurable diff --git a/README.md b/README.md index 98f66bb..bd4fea2 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,11 @@ the changelog generation. This is useful if those changes are not affecting the "product" like internal documentation changes or similar things, which e.g. do not require a deployment. +The option `--version-reference` allows to configure the URL to the tags in the +rendered changelog file. Use e.g. +`https://github.com///tree/` +for a project using this package. + ### Parse Parse an existing snippet file and return the data as JSON without indentation diff --git a/snippets2changelog/cli.py b/snippets2changelog/cli.py index ff1f7f9..6987485 100755 --- a/snippets2changelog/cli.py +++ b/snippets2changelog/cli.py @@ -80,6 +80,12 @@ def parse_args(argv: Union[Sequence[str], None] = None) -> Args: action='store_true', help="Print latest changelog entry as JSON instead of updating the changelog file", ) + parser_changelog.add_argument( + "--version-reference", + type=str, + help="Base version reference for links to tags in rendered changelog", + default="https://github.com/brainelectronics/snippets2changelog/tree/", + ) parser_create = subparsers.add_parser( "create", @@ -130,7 +136,7 @@ def fn_info(_args: Args) -> None: def fn_changelog(args: Args) -> None: cc = ChangelogCreator(changelog=args.changelog, snippets_folder=args.snippets, update_in_place=args.in_place, skip_internal=args.no_internal, verbosity=args.verbose) - cc.update_changelog(dry_run=args.dry_run) + cc.update_changelog(dry_run=args.dry_run, version_reference=args.version_reference) def fn_create(args: Args) -> None: diff --git a/snippets2changelog/creator.py b/snippets2changelog/creator.py index e5bc948..5be4eda 100644 --- a/snippets2changelog/creator.py +++ b/snippets2changelog/creator.py @@ -90,7 +90,7 @@ def __init__(self, changelog: Path, snippets_folder: Path, update_in_place: boo self._skip_internal = skip_internal - def update_changelog(self, dry_run: bool = False) -> None: + def update_changelog(self, dry_run: bool = False, version_reference: str = "https://github.com/brainelectronics/snippets2changelog/tree/") -> None: new_changelog_content = "" # create a "prolog" and an "epilog", with the new content in between existing_changelog_content = read_file(path=self._changelog, parse="read").split(self._version_line) @@ -124,7 +124,7 @@ def update_changelog(self, dry_run: bool = False) -> None: "affected": snippet_content["affected"], }, "content": snippet_content["details"], - "version_reference": f"https://github.com/brainelectronics/snippets2changelog/tree/{self.semver_data}", + "version_reference": f"{version_reference}/{self.semver_data}", } latest_changelog_entry = changelog_entry_content self._logger.debug(f"changelog_entry_content: {changelog_entry_content}")