From 55be1a1407bbccecd4023a421e751502b18df016 Mon Sep 17 00:00:00 2001 From: Julian Risch Date: Thu, 12 Jun 2025 16:38:12 +0200 Subject: [PATCH] check if branch is accessible --- .../connectors/github/repo_forker.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py b/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py index dc5188b90e..0ea763f59b 100644 --- a/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py +++ b/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py @@ -106,19 +106,37 @@ def _parse_github_url(self, url: str) -> tuple[str, str, str]: def _check_fork_status(self, fork_path: str) -> bool: """ - Check if a forked repository exists and is ready. + Check if a forked repository exists and is ready for branch operations. :param fork_path: Repository path in owner/repo format - :return: True if fork exists and is ready, False otherwise + :return: True if fork exists and branches are accessible, False otherwise """ - url = f"https://api.github.com/repos/{fork_path}" try: + # First check if repository exists + url = f"https://api.github.com/repos/{fork_path}" + response = requests.get( + url, + headers=self._get_request_headers(), + timeout=10, + ) + if response.status_code != 200: # noqa: PLR2004 + return False + + # Get default branch name + repo_data = response.json() + default_branch = repo_data.get("default_branch") + if not default_branch: + return False + + # Check if default branch is accessible via Git refs API + url = f"https://api.github.com/repos/{fork_path}/git/refs/heads/{default_branch}" response = requests.get( url, headers=self._get_request_headers(), timeout=10, ) return response.status_code == 200 # noqa: PLR2004 + except requests.RequestException: return False @@ -186,7 +204,7 @@ def _create_issue_branch(self, fork_path: str, issue_number: str) -> None: default_branch = response.json()["default_branch"] # Get the SHA of the default branch - url = f"https://api.github.com/repos/{fork_path}/git/ref/heads/{default_branch}" + url = f"https://api.github.com/repos/{fork_path}/git/refs/heads/{default_branch}" response = requests.get(url, headers=self._get_request_headers(), timeout=10) response.raise_for_status() sha = response.json()["object"]["sha"]