Skip to content

Commit

Permalink
Add option to generate headings only (no commit messages)
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 20, 2019
1 parent c66c8e1 commit 2585476
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/matyan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def get_branch_type(branch_type: AnyStr) -> str:
def prepare_changelog(
between: str = None,
unique_commit_messages: bool = False,
headings_only: bool = False,
path: str = None
) -> Dict[
str, Dict[str, Dict[str, Union[str, Dict[str, Union[str, str]]]]]
Expand All @@ -207,6 +208,7 @@ def prepare_changelog(
:param between:
:param unique_commit_messages:
:param headings_only:
:param path:
:return:
"""
Expand Down Expand Up @@ -266,6 +268,9 @@ def prepare_changelog(
}
branch_types.update({ticket_number: branch_type})

if headings_only:
return tree

# Now go through commits
for json_entry in filter(None, logs['LOG']):
try:
Expand Down Expand Up @@ -387,6 +392,7 @@ def prepare_changelog(
def prepare_releases_changelog(
between: str = None,
unique_commit_messages: bool = False,
headings_only: bool = False,
path: str = None
) -> Dict[
str, Dict[str, Dict[str, Union[str, Dict[str, Union[str, str]]]]]
Expand All @@ -395,6 +401,7 @@ def prepare_releases_changelog(
:param between:
:param unique_commit_messages:
:param headings_only:
:param path:
:return:
"""
Expand Down Expand Up @@ -458,7 +465,10 @@ def prepare_releases_changelog(
'release': release,
}
branch_types.update({ticket_number: branch_type})


if headings_only:
return releases_tree

# Now go through commits
for json_entry in filter(None, logs['LOG']):
try:
Expand Down Expand Up @@ -632,6 +642,7 @@ def json_changelog(between: str = None,
include_other: bool = True,
show_releases: bool = False,
latest_release: bool = False,
headings_only: bool = False,
path: str = None):
if latest_release:
latest_two_releases = get_latest_releases(limit=2, path=path)
Expand Down Expand Up @@ -685,18 +696,27 @@ def json_changelog_cli() -> Type[None]:
action='store_true',
help="Generate changelog for the latest release only",
)
parser.add_argument(
'--headings-only',
dest="headings_only",
default=False,
action='store_true',
help="Generate headings only (no commit messages, only branch titles)",
)
args = parser.parse_args(sys.argv[1:])
between = args.between if validate_between(args.between) else None
include_other = not args.no_other
show_releases = args.show_releases
latest_release = args.latest_release
headings_only = args.headings_only

print(
json_changelog(
between=between,
include_other=include_other,
show_releases=show_releases,
latest_release=latest_release
latest_release=latest_release,
headings_only=headings_only
)
)

Expand All @@ -705,6 +725,7 @@ def generate_changelog(between: str = None,
include_other: bool = True,
show_releases: bool = False,
latest_release: bool = False,
headings_only: bool = False,
path: str = None) -> str:
"""Generate changelog (markdown format)."""

Expand All @@ -725,6 +746,7 @@ def generate_changelog(between: str = None,
tree = prepare_changelog(
between=between,
unique_commit_messages=True,
headings_only=headings_only,
path=path
)
for branch_type, tickets in tree.items():
Expand Down Expand Up @@ -761,6 +783,7 @@ def generate_changelog(between: str = None,
releases_tree = prepare_releases_changelog(
between=between,
unique_commit_messages=True,
headings_only=headings_only,
path=path
)
for release, branches in releases_tree.items():
Expand Down Expand Up @@ -832,18 +855,27 @@ def generate_changelog_cli() -> Type[None]:
action='store_true',
help="Generate changelog for the latest release only",
)
parser.add_argument(
'--headings-only',
dest="headings_only",
default=False,
action='store_true',
help="Generate headings only (no commit messages, only branch titles)",
)
args = parser.parse_args(sys.argv[1:])
between = args.between if validate_between(args.between) else None
include_other = not args.no_other
show_releases = args.show_releases
latest_release = args.latest_release
headings_only = args.headings_only

print(
generate_changelog(
between=between,
include_other=include_other,
show_releases=show_releases,
latest_release=latest_release
latest_release=latest_release,
headings_only=headings_only
)
)

Expand Down

0 comments on commit 2585476

Please sign in to comment.