-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
from github import UnknownObjectException | ||
from githubapp.events import CheckSuiteRequestedEvent | ||
|
||
from src.helpers.command import get_command | ||
from src.helpers.pull_request import get_existing_pull_request | ||
|
||
|
||
def handle_release(event: CheckSuiteRequestedEvent): | ||
repository = event.repository | ||
|
||
head_sha = event.check_suite.head_sha | ||
head_branch = event.check_suite.head_branch | ||
|
||
event.start_check_run("Releaser", head_sha, title="Checking for release command") | ||
|
||
while True: | ||
head_commit = repository.get_commit(head_sha) | ||
if head_branch == repository.default_branch: | ||
repository.create_git_release( | ||
tag=version_to_release, generate_release_notes=True | ||
) | ||
return | ||
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"Prepared to release {version_to_release}", | ||
summary="Release command found ✅", | ||
) | ||
|
||
# try: | ||
# last_release = repository.get_latest_release() | ||
# except UnknownObjectException: | ||
# last_release = "0" | ||
|
||
# if commit.message.startswith("release"): | ||
# event.create_check_run( | ||
# "Releaser", head_sha, title="Found release command", conclusion="success" | ||
# ) | ||
# return | ||
# while True: | ||
# head_commit = repository.get_commit(head_sha) | ||
# commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import re | ||
from typing import Optional | ||
|
||
|
||
def get_command(text: str, command_prefix: str) -> Optional[str]: | ||
""" | ||
Retrieve the command from the commit message. | ||
The command in the commit message must be in the format [command_prefix: command] | ||
:param text: The Commit object. | ||
:param command_prefix: The command prefix to look for in the commit message. | ||
:return: The extracted command or None if there is no command. | ||
:raises: ValueError if the command is not valid. | ||
""" | ||
command_pattern = rf"\[{command_prefix}:(.+?)\]" | ||
commands_found = re.findall(command_pattern, text) | ||
if commands_found: | ||
return commands_found[-1].strip() | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
from unittest.mock import patch, Mock | ||
|
||
from src.handlers.release import handle_release | ||
|
||
|
||
def test_handle_release(event, repository): | ||
def test_handle_release_when_there_is_no_command(event, repository, pull_request): | ||
handle_release(event) | ||
event.start_check_run.assert_called_once_with( | ||
"Releaser", "sha", title="Checking for release command" | ||
) | ||
pull_request.get_commits.assert_called_once() | ||
event.update_check_run.assert_called_once_with( | ||
title="No release command found", conclusion="success" | ||
) | ||
|
||
|
||
def test_handle_release_when_there_is_a_command(event, repository, pull_request): | ||
commit = Mock(commit=Mock(message="[release:1.2.3]")) | ||
pull_request.get_commits.return_value.reversed = [commit] | ||
|
||
handle_release(event) | ||
repository.get_commit.assert_called_once_with("sha") | ||
event.start_check_run.assert_called_once_with( | ||
"Releaser", "sha", title="Checking for release command" | ||
) | ||
pull_request.get_commits.assert_called_once() | ||
event.update_check_run.assert_called_once_with( | ||
title="Prepared to release 1.2.3", | ||
summary="Release command found ✅\nReleasing 1.2.3", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters