Skip to content

Commit 55be1a1

Browse files
committed
check if branch is accessible
1 parent 42ff42d commit 55be1a1

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

  • integrations/github/src/haystack_integrations/components/connectors/github

integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,37 @@ def _parse_github_url(self, url: str) -> tuple[str, str, str]:
106106

107107
def _check_fork_status(self, fork_path: str) -> bool:
108108
"""
109-
Check if a forked repository exists and is ready.
109+
Check if a forked repository exists and is ready for branch operations.
110110
111111
:param fork_path: Repository path in owner/repo format
112-
:return: True if fork exists and is ready, False otherwise
112+
:return: True if fork exists and branches are accessible, False otherwise
113113
"""
114-
url = f"https://api.github.com/repos/{fork_path}"
115114
try:
115+
# First check if repository exists
116+
url = f"https://api.github.com/repos/{fork_path}"
117+
response = requests.get(
118+
url,
119+
headers=self._get_request_headers(),
120+
timeout=10,
121+
)
122+
if response.status_code != 200: # noqa: PLR2004
123+
return False
124+
125+
# Get default branch name
126+
repo_data = response.json()
127+
default_branch = repo_data.get("default_branch")
128+
if not default_branch:
129+
return False
130+
131+
# Check if default branch is accessible via Git refs API
132+
url = f"https://api.github.com/repos/{fork_path}/git/refs/heads/{default_branch}"
116133
response = requests.get(
117134
url,
118135
headers=self._get_request_headers(),
119136
timeout=10,
120137
)
121138
return response.status_code == 200 # noqa: PLR2004
139+
122140
except requests.RequestException:
123141
return False
124142

@@ -186,7 +204,7 @@ def _create_issue_branch(self, fork_path: str, issue_number: str) -> None:
186204
default_branch = response.json()["default_branch"]
187205

188206
# Get the SHA of the default branch
189-
url = f"https://api.github.com/repos/{fork_path}/git/ref/heads/{default_branch}"
207+
url = f"https://api.github.com/repos/{fork_path}/git/refs/heads/{default_branch}"
190208
response = requests.get(url, headers=self._get_request_headers(), timeout=10)
191209
response.raise_for_status()
192210
sha = response.json()["object"]["sha"]

0 commit comments

Comments
 (0)