diff --git a/ddev/changelog.d/17348.fixed b/ddev/changelog.d/17348.fixed new file mode 100644 index 0000000000000..5402e6a975519 --- /dev/null +++ b/ddev/changelog.d/17348.fixed @@ -0,0 +1 @@ +Do not open the editor if no changelog should be generated in the changelog new command diff --git a/ddev/src/ddev/cli/release/changelog/new.py b/ddev/src/ddev/cli/release/changelog/new.py index 6416d734eb9c0..a240488c62945 100644 --- a/ddev/src/ddev/cli/release/changelog/new.py +++ b/ddev/src/ddev/cli/release/changelog/new.py @@ -32,11 +32,27 @@ def new(app: Application, entry_type: str | None, targets: tuple[str], message: """ from datadog_checks.dev.tooling.commands.release.changelog import towncrier + create_command = None + + edited = 0 + for check in app.repo.integrations.iter_changed_code(targets): + if not create_command: + create_command = __get_create_command(app, entry_type, message) + + towncrier(check.path, *create_command) + edited += 1 + + if not edited: + app.display_info('No changelog entries to create') + else: + app.display_success(f'Added {edited} changelog entr{"ies" if edited > 1 else "y"}') + + +def __get_create_command(app, entry_type, message): from ddev.release.constants import ENTRY_TYPES latest_commit = app.repo.git.latest_commit pr = app.github.get_pull_request(latest_commit.sha) - message_based_on_git = '' if pr is not None: pr_number = pr.number message_based_on_git = pr.title @@ -44,20 +60,14 @@ def new(app: Application, entry_type: str | None, targets: tuple[str], message: pr_number = app.github.get_next_issue_number() message_based_on_git = latest_commit.subject - if entry_type is not None: - if entry_type not in ENTRY_TYPES: - app.abort(f'Unknown entry type: {entry_type}') - else: + if entry_type is None: entry_type = click.prompt('Entry type?', type=click.Choice(ENTRY_TYPES, case_sensitive=False)) + elif entry_type not in ENTRY_TYPES: + app.abort(f'Unknown entry type: {entry_type}') - create_cmd = [ + return [ 'create', '--content', message or click.edit(text=message_based_on_git, require_save=False) or message_based_on_git, f'{pr_number}.{entry_type}', ] - edited = 0 - for check in app.repo.integrations.iter_changed_code(targets): - towncrier(check.path, *create_cmd) - edited += 1 - app.display_success(f'Added {edited} changelog entr{"ies" if edited > 1 else "y"}') diff --git a/ddev/tests/cli/release/test_changelog.py b/ddev/tests/cli/release/test_changelog.py index 51b788cbbdf26..b738ec63eb1cb 100644 --- a/ddev/tests/cli/release/test_changelog.py +++ b/ddev/tests/cli/release/test_changelog.py @@ -254,10 +254,10 @@ def fragments_dir(self, repo_with_towncrier, network_replay, mocker): mocker.patch( 'ddev.utils.git.GitManager.capture', side_effect=[ - '0000000000000000000000000000000000000000\nFoo', 'M ddev/pyproject.toml', '', '', + '0000000000000000000000000000000000000000\nFoo', ], ) return repo_with_towncrier.path / 'ddev' / 'changelog.d' @@ -308,6 +308,28 @@ def test_prompt_for_entry_type(self, ddev, fragments_dir, helpers, mocker): ) assert fragment_file.read_text() == "Foo" + def test_start_no_changelog(self, ddev, fragments_dir, helpers, mocker): + mocker.patch( + 'ddev.utils.git.GitManager.capture', + side_effect=[ + 'M tests/conftest.py', + '', + '', + '0000000000000000000000000000000000000000\nFoo', + ], + ) + edit_patch = mocker.patch('click.edit', return_value=None) + result = ddev('release', 'changelog', 'new', 'added') + + assert result.exit_code == 0, result.output + assert helpers.remove_trailing_spaces(result.output) == helpers.dedent( + ''' + No changelog entries to create + ''' + ) + assert not (fragments_dir / '15476.added').exists() + edit_patch.assert_not_called() + def test_edit_entry(self, ddev, fragments_dir, helpers, mocker): message = 'Foo \n\n Bar' mocker.patch(