Skip to content

Commit

Permalink
fix-when-error-in-creating-pr (#241)
Browse files Browse the repository at this point in the history
* fix(PullRequestManager): Fix when error in creating PR

* [release:bugfix]

* style: format code with Black, isort and Ruff Formatter

This commit fixes the style issues introduced in 5a5ccab according to the output
from Black, isort and Ruff Formatter.

Details: #241

---------

Co-authored-by: Heitor Polidoro <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 10, 2024
1 parent 74dbfbe commit f8a7a13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/managers/pull_request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def manage(event: CheckSuiteRequestedEvent) -> None:
summary = []
if head_branch != repository.default_branch:
pull_request = get_or_create_pull_request(repository, head_branch, check_run)
if not pull_request:
if not pull_request or isinstance(pull_request, str):
return
auto_merge_error = enable_auto_merge(pull_request, check_run)

Expand Down
24 changes: 14 additions & 10 deletions tests/managers/test_pull_request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ def pull_request_helper():


@pytest.mark.parametrize(
"head_branch, pull_request_user_login, auto_merge_error, create_pull_request",
"head_branch, pull_request_user_login, auto_merge_error, create_pull_request, create_pull_request_error",
[
["master", "heitorpolidoro", "", True],
["branch", "heitorpolidoro", "", True],
["branch", Config.BOT_NAME, "", True],
["branch", "heitorpolidoro", "Some error", True],
["branch", "heitorpolidoro", "", False],
["master", "heitorpolidoro", "", True, ""],
["branch", "heitorpolidoro", "", True, ""],
["branch", "heitorpolidoro", "", True, "Error in creating Pull Request"],
["branch", Config.BOT_NAME, "", True, ""],
["branch", "heitorpolidoro", "Error in enable auto merge", True, ""],
["branch", "heitorpolidoro", "", False, ""],
],
)
def test_manage(
Expand All @@ -39,13 +40,16 @@ def test_manage(
pull_request_user_login,
auto_merge_error,
create_pull_request,
create_pull_request_error,
pull_request,
pull_request_helper,
):
event.check_suite.head_branch = head_branch
pull_request.user.login = pull_request_user_login
if not create_pull_request:
pull_request = None
if create_pull_request_error:
pull_request = create_pull_request_error
with (
patch(
"src.managers.pull_request_manager.get_or_create_pull_request",
Expand All @@ -54,12 +58,12 @@ def test_manage(
patch(
"src.managers.pull_request_manager.enable_auto_merge",
return_value=auto_merge_error,
) as enable_auto_merge,
) as enable_auto_merge_mock,
):
manage(event)
if head_branch == "master":
check_run.assert_not_called()
elif create_pull_request:
elif create_pull_request and not create_pull_request_error:
if pull_request_user_login == Config.BOT_NAME:
summary = "Pull Request #123 created"
else:
Expand All @@ -71,9 +75,9 @@ def test_manage(
check_run.update.assert_called_once_with(
title="Done", summary=summary, conclusion="success"
)
enable_auto_merge.assert_called_once()
enable_auto_merge_mock.assert_called_once()
else:
enable_auto_merge.assert_not_called()
enable_auto_merge_mock.assert_not_called()


@pytest.mark.parametrize(
Expand Down

0 comments on commit f8a7a13

Please sign in to comment.