community: Fix branch not being considered when using GithubFileLoader (#20075)

- **Description:** Added `ref` query parameter so data is not loaded
only from the default branch but any branch passed

---------

Co-authored-by: Osama Mehdi <mehdi@hm.edu>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
mehdiosa 2024-08-30 23:47:11 +02:00 committed by GitHub
parent 54d2b861f6
commit c6f00e6bdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -206,7 +206,10 @@ class GithubFileLoader(BaseGitHubLoader, ABC):
]
def get_file_content_by_path(self, path: str) -> str:
base_url = f"{self.github_api_url}/repos/{self.repo}/contents/{path}"
queryparams = f"?ref={self.branch}" if self.branch else ""
base_url = (
f"{self.github_api_url}/repos/{self.repo}/contents/{path}{queryparams}"
)
response = requests.get(base_url, headers=self.headers)
response.raise_for_status()