Skip to content

Commit

Permalink
fix_no_history_in_common (#239)
Browse files Browse the repository at this point in the history
* fix no history in common

[release:bugfix]

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

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

Details: #239

---------

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 8, 2024
1 parent e2551ce commit 5c8c5a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 13 additions & 13 deletions src/helpers/pull_request_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Method to helps with Github PullRequests"""

import logging
from typing import NoReturn, Optional
from typing import NoReturn, Optional, Union

import github
from github.PullRequest import PullRequest
Expand Down Expand Up @@ -30,7 +30,7 @@ def create_pull_request(
branch: str,
title: Optional[str] = None,
body: Optional[str] = None,
) -> Optional[PullRequest]:
) -> Optional[Union[PullRequest, str]]:
"""
Creates a PR from the default branch to the given branch.
Expand All @@ -53,17 +53,17 @@ def create_pull_request(
draft=False,
)
except github.GithubException as ghe:
if ghe.data and any(
error.get("message")
== f"No commits between {repository.default_branch} and {branch}"
for error in ghe.data["errors"]
):
logger.warning(
"No commits between '%s' and '%s'", repository.default_branch, branch
)
else:
raise
return None
possible_errors = [
f"No commits between {repository.default_branch} and {branch}",
f"The {branch} branch has no history in common with main",
]
for error in ghe.data["errors"]:
message = error.get("message")
if message in possible_errors:
logger.warning(message)
return message

raise


def update_pull_requests(repository: Repository, base_branch: str) -> NoReturn:
Expand Down
4 changes: 3 additions & 1 deletion tests/helpers/test_pull_request_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ def test_get_existing_pull_request(repository, expected_result_index, pull_reque
[
"",
"No commits between master and branch",
"The branch branch has no history in common with main",
"Other",
],
ids=[
"Create Pull Request",
"No commits",
"No commits in common",
"Other error",
],
)
Expand All @@ -57,7 +59,7 @@ def test_create_pull_request(repository, error_message):
repository.create_pull.side_effect = GithubException(
0, data={"errors": [{"message": error_message}]}
)
expected_result = None
expected_result = error_message

if error_message == "Other":
with pytest.raises(GithubException):
Expand Down

0 comments on commit 5c8c5a8

Please sign in to comment.