Skip to content
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
3 changes: 2 additions & 1 deletion release_automation/scripts/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,8 @@ def delete_branch(self, branch_name: str) -> bool:
return True
except GitHubClientError as e:
error_msg = str(e).lower()
if "404" in error_msg or "not found" in error_msg:
# A DELETE on a missing ref answers 422 "Reference does not exist", not 404
if "404" in error_msg or "not found" in error_msg or "reference does not exist" in error_msg:
return False
raise

Expand Down
16 changes: 16 additions & 0 deletions release_automation/tests/test_github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ def test_list_branches(self, mock_run_gh):
self.assertEqual(branches[1].name, "branch2")
self.assertEqual(branches[1].sha, "sha2")

@patch("release_automation.scripts.github_client.GitHubClient._run_gh")
def test_delete_branch(self, mock_run_gh):
mock_run_gh.return_value = ""
self.assertTrue(self.client.delete_branch("feature"))

# GitHub answers a DELETE on a missing ref with 422, not 404
mock_run_gh.side_effect = GitHubClientError("gh: Reference does not exist (HTTP 422)")
self.assertFalse(self.client.delete_branch("missing"))

mock_run_gh.side_effect = GitHubClientError("gh: Not Found (HTTP 404)")
self.assertFalse(self.client.delete_branch("missing"))

mock_run_gh.side_effect = GitHubClientError("gh: Resource not accessible by integration (HTTP 403)")
with self.assertRaises(GitHubClientError):
self.client.delete_branch("protected")

@patch("release_automation.scripts.github_client.GitHubClient._run_gh")
def test_get_file_content(self, mock_run_gh):
mock_run_gh.return_value = "file content"
Expand Down
Loading