Skip to content

Acknowledge network issues on GitHub #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import click
import requests
import stamina
from gidgethub import sansio

from . import __version__
Expand Down Expand Up @@ -55,6 +56,7 @@
PUSHING_TO_REMOTE_FAILED

PR_CREATING
PR_CREATING_FAILED
PR_OPENING

REMOVING_BACKPORT_BRANCH
Expand Down Expand Up @@ -95,6 +97,10 @@
pass


class GitHubException(Exception):
pass


class CherryPicker:
ALLOWED_STATES = WORKFLOW_STATES.BACKPORT_PAUSED, WORKFLOW_STATES.UNSET
"""The list of states expected at the start of the app."""
Expand Down Expand Up @@ -430,16 +436,21 @@
gh_auth = os.getenv("GH_AUTH")
if gh_auth:
set_state(WORKFLOW_STATES.PR_CREATING)
self.create_gh_pr(
base_branch,
head_branch,
commit_message=commit_message,
gh_auth=gh_auth,
)
try:
self.create_gh_pr(
base_branch,
head_branch,
commit_message=commit_message,
gh_auth=gh_auth,
)
except GitHubException:
set_state(WORKFLOW_STATES.PR_CREATING_FAILED)
raise

Check warning on line 448 in cherry_picker/cherry_picker.py

View check run for this annotation

Codecov / codecov/patch

cherry_picker/cherry_picker.py#L446-L448

Added lines #L446 - L448 were not covered by tests
else:
set_state(WORKFLOW_STATES.PR_OPENING)
self.open_pr(self.get_pr_url(base_branch, head_branch))

@stamina.retry(on=GitHubException, timeout=120)
def create_gh_pr(self, base_branch, head_branch, *, commit_message, gh_auth):
"""
Create PR in GitHub
Expand All @@ -458,14 +469,22 @@
"draft": self.config["draft_pr"],
}
url = CREATE_PR_URL_TEMPLATE.format(config=self.config)
response = requests.post(url, headers=request_headers, json=data, timeout=10)
if response.status_code == requests.codes.created:
response_data = response.json()
click.echo(f"Backport PR created at {response_data['html_url']}")
self.pr_number = response_data["number"]
try:
response = requests.post(
url, headers=request_headers, json=data, timeout=30
)
except requests.exceptions.RequestException as req_exc:
raise GitHubException(f"Creating PR on GitHub failed: {req_exc}")

Check warning on line 477 in cherry_picker/cherry_picker.py

View check run for this annotation

Codecov / codecov/patch

cherry_picker/cherry_picker.py#L476-L477

Added lines #L476 - L477 were not covered by tests
else:
click.echo(response.status_code)
click.echo(response.text)
sc = response.status_code
txt = response.text
if sc != requests.codes.created:
raise GitHubException(

Check warning on line 482 in cherry_picker/cherry_picker.py

View check run for this annotation

Codecov / codecov/patch

cherry_picker/cherry_picker.py#L482

Added line #L482 was not covered by tests
f"Unexpected response ({sc}) when creating PR on GitHub: {txt}"
)
response_data = response.json()
click.echo(f"Backport PR created at {response_data['html_url']}")
self.pr_number = response_data["number"]

def open_pr(self, url):
"""
Expand Down Expand Up @@ -543,9 +562,14 @@
raise
else:
if self.push:
self.push_to_remote(
maint_branch, cherry_pick_branch, commit_message
)
try:
self.push_to_remote(
maint_branch, cherry_pick_branch, commit_message
)
except GitHubException:
click.echo(self.get_exit_message(maint_branch))
self.set_paused_state()
raise

Check warning on line 572 in cherry_picker/cherry_picker.py

View check run for this annotation

Codecov / codecov/patch

cherry_picker/cherry_picker.py#L569-L572

Added lines #L569 - L572 were not covered by tests
if not self.is_mirror():
self.cleanup_branch(cherry_pick_branch)
else:
Expand Down
2 changes: 1 addition & 1 deletion cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,5 +1386,5 @@ def test_create_gh_pr_draft_states(
"maintainer_can_modify": True,
"draft": draft_pr,
},
timeout=10,
timeout=30,
)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"click>=6",
"gidgethub",
"requests",
"stamina",
"tomli>=1.1; python_version<'3.11'",
]
optional-dependencies.dev = [
Expand Down
Loading