Skip to content

Commit 03555ca

Browse files
committed
refactor(utils/crawl_github_files): deciding default branch
Previously the default branch name was considered to be "main", which was wrong. To fix this, dont put the ref param to query and let Github decide default branch.
1 parent ea524ef commit 03555ca

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

utils/crawl_github_files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ def check_tree(owner: str, repo: str, tree: str):
202202
part_index = 5 if '/' in ref else 4
203203
specific_path = join_parts(part_index) if part_index < len(path_parts) else ""
204204
else:
205-
ref = "main" # Default branch
205+
# Dont put the ref param to quiery
206+
# and let Github decide default branch
207+
ref = None
206208
specific_path = ""
207209

208210
# Dictionary to store path -> content mapping
@@ -212,7 +214,7 @@ def check_tree(owner: str, repo: str, tree: str):
212214
def fetch_contents(path):
213215
"""Fetch contents of the repository at a specific path and commit"""
214216
url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
215-
params = {"ref": ref}
217+
params = {"ref": ref} if ref != None else {}
216218

217219
response = requests.get(url, headers=headers, params=params)
218220

0 commit comments

Comments
 (0)