Skip to content

Commit

Permalink
Merge pull request #56 from datalad/defbranch
Browse files Browse the repository at this point in the history
GIN: Don't assume the default branch is "master"
  • Loading branch information
jwodder authored Feb 18, 2025
2 parents 95859e5 + b0e3007 commit 582614a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/find_datalad_repos/gin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, token: str) -> None:
retry_config=RetryConfig(retry_statuses=range(501, 600)),
)

def search_repositories(self) -> Iterator[GINRepo]:
def search_repositories(self) -> Iterator[dict[str, Any]]:
# TODO: Switch back to this simpler implementation (and remove the
# custom RetryConfig above) once
# <https://github.com/G-Node/gogs/issues/148> is resolved:
Expand All @@ -90,15 +90,16 @@ def search_repositories(self) -> Iterator[GINRepo]:
else:
raise
else:
repos = [GINRepo.from_data(datum) for datum in r.json()["data"]]
repos = r.json()["data"]
if not repos:
break
yield from repos
page += 1

def get_datalad_repos(self) -> Iterator[GINRepo]:
for repo in self.search_repositories():
if self.has_datalad_config(repo.name):
for datum in self.search_repositories():
repo = GINRepo.from_data(datum)
if self.has_datalad_config(repo.name, datum["default_branch"]):
log.info("Found DataLad repo on GIN: %r (ID: %d)", repo.name, repo.id)
yield repo
else:
Expand All @@ -108,9 +109,11 @@ def get_datalad_repos(self) -> Iterator[GINRepo]:
repo.id,
)

def has_datalad_config(self, repo: str) -> bool:
def has_datalad_config(self, repo: str, defbranch: str) -> bool:
try:
self.request("HEAD", f"/repos/{repo}/raw/master/.datalad/config", raw=True)
self.request(
"HEAD", f"/repos/{repo}/raw/{defbranch}/.datalad/config", raw=True
)
except PrettyHTTPError as e:
if e.response.status_code == 404:
return False
Expand Down

0 comments on commit 582614a

Please sign in to comment.