Skip to content

Commit ec97640

Browse files
bjoernricksgreenbonebot
authored andcommitted
Add: Allow to load changelog from file when creating a release
Allow to load a pre-created changelog file when creating a new release instead of gathering the changelog from the git commits. This allows to use different tools then pontos for changelog creation and also reduces required mocking in the create release command tests.
1 parent 060e507 commit ec97640

File tree

4 files changed

+174
-143
lines changed

4 files changed

+174
-143
lines changed

pontos/release/_parser.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
DEFAULT_SIGNING_KEY = "0ED1E580"
3434

3535

36-
class ReleaseVersionAction(
37-
argparse._StoreAction
38-
): # pylint: disable=protected-access
36+
class ReleaseVersionAction(argparse._StoreAction):
3937
def __call__(self, parser, namespace, values, option_string=None):
4038
setattr(namespace, "release_type", ReleaseType.VERSION)
4139
setattr(namespace, self.dest, values)
@@ -144,13 +142,6 @@ def add_create_parser(
144142
help="Only create release changes locally and do not upload them to a "
145143
"remote repository. Also do not create a GitHub release.",
146144
)
147-
create_parser.add_argument(
148-
"--conventional-commits-config",
149-
dest="cc_config",
150-
type=Path,
151-
help="Conventional commits config file (toml), including conventions."
152-
" If not set defaults are used.",
153-
)
154145
create_parser.add_argument(
155146
"--update-project",
156147
help="Update version in project files like pyproject.toml. By default "
@@ -163,6 +154,19 @@ def add_create_parser(
163154
help="Enforce uploading a release as GitHub pre-release. ",
164155
action="store_true",
165156
)
157+
changelog_parser = create_parser.add_mutually_exclusive_group()
158+
changelog_parser.add_argument(
159+
"--conventional-commits-config",
160+
dest="cc_config",
161+
type=Path,
162+
help="Conventional commits config file (toml), including conventions."
163+
" If not set defaults are used.",
164+
)
165+
changelog_parser.add_argument(
166+
"--changelog",
167+
type=Path,
168+
help="Read the release notes from the given file.",
169+
)
166170

167171

168172
def add_sign_parser(

pontos/release/create.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ async def async_run( # type: ignore[override]
180180
release_series: Optional[str] = None,
181181
update_project: bool = True,
182182
github_pre_release: bool = False,
183+
changelog: Optional[str] = None,
183184
) -> CreateReleaseReturnValue:
184185
"""
185186
Create a release
@@ -214,6 +215,8 @@ async def async_run( # type: ignore[override]
214215
update_project: Update version in project files.
215216
github_pre_release: Enforce uploading a release as a GitHub pre
216217
release
218+
changelog: An optional changelog. If not set a changelog will be
219+
gathered from the git commits since the last release.
217220
"""
218221
self.git_tag_prefix = git_tag_prefix or ""
219222
self.repository = repository
@@ -300,9 +303,12 @@ async def async_run( # type: ignore[override]
300303
f"Creating changelog for {release_version} as initial release."
301304
)
302305

303-
release_text = self._create_changelog(
304-
release_version, last_release_version, cc_config
305-
)
306+
if changelog:
307+
release_text = changelog
308+
else:
309+
release_text = self._create_changelog(
310+
release_version, last_release_version, cc_config
311+
)
306312

307313
commit_msg = f"Automatic release to {release_version}"
308314

@@ -416,6 +422,10 @@ def create_release(
416422
)
417423
return CreateReleaseReturnValue.TOKEN_MISSING
418424

425+
changelog_file: Path = args.changelog
426+
if changelog_file and not changelog_file.exists():
427+
error_terminal.error(f"Changelog file {changelog_file} does not exist.")
428+
return CreateReleaseReturnValue.CREATE_RELEASE_ERROR
419429
return CreateReleaseCommand(
420430
terminal=terminal, error_terminal=error_terminal
421431
).run(
@@ -434,4 +444,5 @@ def create_release(
434444
release_series=args.release_series,
435445
update_project=args.update_project,
436446
github_pre_release=args.github_pre_release,
447+
changelog=changelog_file.read_text() if changelog_file else None,
437448
)

0 commit comments

Comments
 (0)