Skip to content

Commit

Permalink
Do not open the editor if no changelog should be generated in the cha…
Browse files Browse the repository at this point in the history
…ngelog new command (#17348)

* Do not open the editor if no changelog should be generated in the changelog new command

* Update ddev/src/ddev/cli/release/changelog/new.py

Co-authored-by: Ilia Kurenkov <[email protected]>

---------

Co-authored-by: Ilia Kurenkov <[email protected]>
  • Loading branch information
FlorentClarret and iliakur authored Apr 5, 2024
1 parent 21d0d70 commit fae94ce
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions ddev/changelog.d/17348.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not open the editor if no changelog should be generated in the changelog new command
32 changes: 21 additions & 11 deletions ddev/src/ddev/cli/release/changelog/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,42 @@ 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
else:
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"}')
24 changes: 23 additions & 1 deletion ddev/tests/cli/release/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fae94ce

Please sign in to comment.