@@ -45,7 +45,7 @@ def _client(token: str | None = None) -> Github:
4545
4646
4747def _default_org () -> str | None :
48- return os .getenv ("GITHUB_DEFAULT_ORG" ) or None
48+ return os .getenv ("GITHUB_DEFAULT_ORG" )
4949
5050
5151def _repo (g : Github , owner : str , repo : str ) -> Repository :
@@ -262,6 +262,11 @@ def search_code(query: str, repo: str | None = None) -> list[dict[str, Any]]:
262262
263263 Returns a list of result dicts.
264264 """
265+ if repo is not None :
266+ _REPO_RE = re .compile (r"^[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+$" )
267+ if not _REPO_RE .match (repo ):
268+ raise ValueError ("Invalid repo format: must be owner/repo" )
269+
265270 g = _client ()
266271 safe_query = _sanitise_query (query )
267272 full_query = f"{ safe_query } repo:{ repo } " if repo else safe_query
@@ -420,9 +425,9 @@ def get_weekly_digest(owner: str, repo: str) -> dict[str, Any]:
420425 {"login" : login , "commits" : commits } for login , commits in weekly [:5 ]
421426 ]
422427 except RateLimitExceededException :
423- pass # contributor stats are best-effort in the digest
428+ top_contributors = { "available" : False , "reason" : "stats_unavailable" }
424429 except GithubException :
425- pass # stats may not be ready on newly created repos
430+ top_contributors = { "available" : False , "reason" : "stats_unavailable" }
426431
427432 return {
428433 "period" : {"from" : since .isoformat (), "to" : now .isoformat ()},
0 commit comments