From 90d61b854919d0e2539b42110a2c637bfea8e7a5 Mon Sep 17 00:00:00 2001 From: "bartholomew-smith[bot]" <156136305+bartholomew-smith[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 18:19:26 -0300 Subject: [PATCH] release without configuration (from releases) (#78) * auto-releaser [release:0.1] * style: format code with Black and isort This commit fixes the style issues introduced in 371490f according to the output from Black and isort. Details: https://github.com/heitorpolidoro/bartholomew-smith/pull/78 --------- Co-authored-by: Heitor Polidoro Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- src/managers/release.py | 52 +++++++++++++++++++++------------- tests/managers/test_release.py | 12 +++++--- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/managers/release.py b/src/managers/release.py index 1b00252..f2dc901 100644 --- a/src/managers/release.py +++ b/src/managers/release.py @@ -14,28 +14,40 @@ def handle_release(event: CheckSuiteRequestedEvent): "Bartholomew - Releaser", head_sha, title="Checking for release command" ) - if head_branch == repository.default_branch: - # repository.create_git_release( - # tag=version_to_release, generate_release_notes=True - # ) - return True + version_to_release = None + check_suite = event.check_suite + is_default_branch = head_branch == repository.default_branch + if is_default_branch: + commits = reversed( + repository.compare(check_suite.before, check_suite.after).commits + ) else: if pull_request := get_existing_pull_request(repository, head_branch): - version_to_release = None - for commit in pull_request.get_commits().reversed: - if version_to_release := get_command(commit.commit.message, "release"): - break - - if not version_to_release: - event.update_check_run( - title="No release command found", conclusion="success" - ) - return - - event.update_check_run( - title=f"Ready to release {version_to_release}", - summary="Release command found ✅", - ) + commits = pull_request.get_commits().reversed + else: + return + + for commit in commits: + if version_to_release := get_command(commit.commit.message, "release"): + break + + if not version_to_release: + event.update_check_run(title="No release command found", conclusion="success") + return + + if is_default_branch: + event.update_check_run( + title=f"Releasing {version_to_release}", + summary="", + ) + repository.create_git_release( + tag=version_to_release, generate_release_notes=True + ) + else: + event.update_check_run( + title=f"Ready to release {version_to_release}", + summary="Release command found ✅", + ) # try: # last_release = repository.get_latest_release() diff --git a/tests/managers/test_release.py b/tests/managers/test_release.py index b550f29..57207d5 100644 --- a/tests/managers/test_release.py +++ b/tests/managers/test_release.py @@ -33,12 +33,16 @@ def test_handle_release_when_there_is_a_command(event, repository, pull_request) ) -def test_handle_release_when_head_branch_is_the_default_branch(event, repository, pull_request): +def test_handle_release_when_head_branch_is_the_default_branch( + event, repository, pull_request +): event.check_suite.head_branch = repository.default_branch commit = Mock(commit=Mock(message="[release:1.2.3]")) - pull_request.get_commits.return_value.reversed = [commit] - assert handle_release(event) is True - repository.create_git_release.assert_called_once_with(tag="1.2.3", generate_release_notes=True) + repository.compare.return_value = Mock(commits=[commit]) + handle_release(event) + repository.create_git_release.assert_called_once_with( + tag="1.2.3", generate_release_notes=True + ) def test_handle_release_when_there_is_no_pull_request(event, repository):