Skip to content

Commit

Permalink
release without configuration (from releases) (#78)
Browse files Browse the repository at this point in the history
* 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: #78

---------

Co-authored-by: Heitor Polidoro <heitor.polidoro@gmail.com>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 19, 2024
1 parent fddc337 commit 90d61b8
Showing 2 changed files with 40 additions and 24 deletions.
52 changes: 32 additions & 20 deletions src/managers/release.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 8 additions & 4 deletions tests/managers/test_release.py
Original file line number Diff line number Diff line change
@@ -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):

0 comments on commit 90d61b8

Please sign in to comment.