Skip to content

Commit

Permalink
add --no-internal option, closes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics committed Oct 12, 2024
1 parent 8abb77c commit 18fc3a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .snippets/21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Add option to skip snippets marked as 'internal'
<!--
type: feature
scope: all
affected: all
-->

This adds the option `--no-internal` to skip snippets with scope `internal`
during the changelog generation. This change explicitly does not add a
documentation to the `README` file to show and test this behaviour in a second
pull request.
7 changes: 6 additions & 1 deletion snippets2changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def parse_args(argv: Union[Sequence[str], None] = None) -> Args:
action='store_true',
help="Update specified changelog in place",
)
parser_changelog.add_argument(
"--no-internal",
action='store_true',
help="Skip snippets with scope set as 'internal'",
)

parser_create = subparsers.add_parser(
"create",
Expand Down Expand Up @@ -119,7 +124,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, verbosity=args.verbose)
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()


Expand Down
8 changes: 7 additions & 1 deletion snippets2changelog/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create(self, file_name: Path) -> None:
class ChangelogCreator(ExtractVersion, SnippetParser, SnippetCreator, SnippetCollector): # type: ignore
"""docstring for ChangelogCreator"""

def __init__(self, changelog: Path, snippets_folder: Path, update_in_place: bool, verbosity: int = 0) -> None:
def __init__(self, changelog: Path, snippets_folder: Path, update_in_place: bool, skip_internal: bool = False, verbosity: int = 0) -> None:
if changelog.exists():
self._changelog = changelog
self._update_in_place = update_in_place
Expand All @@ -87,6 +87,8 @@ def __init__(self, changelog: Path, snippets_folder: Path, update_in_place: boo
self._logger.debug(("semver_data:", self.semver_data))
# VersionInfo(major=0, minor=1, patch=0, prerelease=None, build=None))

self._skip_internal = skip_internal

def update_changelog(self) -> None:
new_changelog_content = ""
# create a "prolog" and an "epilog", with the new content in between
Expand All @@ -97,6 +99,10 @@ def update_changelog(self) -> None:
self.parse(file_name=file_name)
snippet_content = self.parsed_content
self._logger.debug(snippet_content)

if "internal" in snippet_content["scope"] and self._skip_internal:
continue

if snippet_content["type"] == "bugfix":
self.semver_data = self.semver_data.bump_patch()
elif snippet_content["type"] == "feature":
Expand Down

0 comments on commit 18fc3a6

Please sign in to comment.