Skip to content

Commit

Permalink
Merge pull request #44 from octue/feature/add-link-to-pull-request-in…
Browse files Browse the repository at this point in the history
…-release-notes

Add option to add link to pull request in release notes
  • Loading branch information
cortadocodes committed Nov 1, 2021
2 parents f642d40 + 6e322ad commit d8daaeb
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 43 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ Note that these comment lines are invisible in rendered markdown.
### Usage
```shell
usage: compile-release-notes [-h] [--pull-request-url PULL_REQUEST_URL] [--api-token API_TOKEN] [--header HEADER] [--list-item-symbol LIST_ITEM_SYMBOL]
[--no-link-to-pull-request]
{LAST_RELEASE,LAST_PULL_REQUEST,PULL_REQUEST_START}
positional arguments:
Expand All @@ -224,6 +225,9 @@ optional arguments:
--header HEADER The header (including MarkDown styling) to put the release notes under. Default is '## Contents'
--list-item-symbol LIST_ITEM_SYMBOL
The MarkDown list item symbol to use for listing commit messages in the release notes. Default is '- '
--no-link-to-pull-request
If provided, don't add a link to the given pull request in the release notes.
```
### GitHub workflows
Expand Down
19 changes: 18 additions & 1 deletion conventional_commits/compile_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ReleaseNotesCompiler:
:param str header: the header to put above the autogenerated release notes, including any markdown styling (defaults to "## Contents")
:param str list_item_symbol: the markdown symbol to use for listing the commit messages in the release notes (defaults to a ticked checkbox but could be a bullet point or number)
:param dict|None commit_codes_to_headings_mapping: mapping of commit codes to the header they should be put under, including markdown styling (e.g. "### Fixes")
:param bool include_link_to_pull_request: if `True`, link to the given pull request in the release notes; ignore if no pull request URL is given
:return None:
"""

Expand All @@ -67,6 +68,7 @@ def __init__(
header="## Contents",
list_item_symbol="-",
commit_codes_to_headings_mapping=None,
include_link_to_pull_request=True,
):
if stop_point.upper() not in STOP_POINTS:
raise ValueError(f"`stop_point` must be one of {STOP_POINTS!r}; received {stop_point!r}.")
Expand All @@ -83,6 +85,7 @@ def __init__(
self.header = header
self.list_item_symbol = list_item_symbol
self.commit_codes_to_headings_mapping = commit_codes_to_headings_mapping or COMMIT_CODES_TO_HEADINGS_MAPPING
self.include_link_to_pull_request = include_link_to_pull_request

if self.stop_point == PULL_REQUEST_START:
if self.current_pull_request is not None:
Expand Down Expand Up @@ -247,7 +250,14 @@ def _build_release_notes(self, categorised_commit_messages):
:param dict categorised_commit_messages:
:return str:
"""
release_notes_for_printing = f"{AUTO_GENERATION_START_INDICATOR}\n{self.header}\n"
if self.current_pull_request is not None and self.include_link_to_pull_request:
link_to_pull_request = (
f" ([#{self.current_pull_request['number']}]({self.current_pull_request['html_url']}))"
)
else:
link_to_pull_request = ""

release_notes_for_printing = f"{AUTO_GENERATION_START_INDICATOR}\n{self.header}{link_to_pull_request}\n"

breaking_change_count = categorised_commit_messages.pop(BREAKING_CHANGE_COUNT_KEY)

Expand Down Expand Up @@ -318,6 +328,12 @@ def main(argv=None):
help="The MarkDown list item symbol to use for listing commit messages in the release notes. Default is '- '",
)

parser.add_argument(
"--no-link-to-pull-request",
action="store_true",
help="If provided, don't add a link to the given pull request in the release notes.",
)

args = parser.parse_args(argv)

release_notes = ReleaseNotesCompiler(
Expand All @@ -326,6 +342,7 @@ def main(argv=None):
api_token=args.api_token,
header=args.header,
list_item_symbol=args.list_item_symbol,
include_link_to_pull_request=not args.no_link_to_pull_request,
).compile_release_notes()

print(release_notes)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = conventional_commits
version = 0.3.1
version = 0.4.0
description = A pre-commit hook, semantic version checker, and release note compiler for facilitating continuous deployment via Conventional Commits.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
Loading

0 comments on commit d8daaeb

Please sign in to comment.