Skip to content

Commit 91834da

Browse files
committed
fall back for cont graph
1 parent e39f8d0 commit 91834da

1 file changed

Lines changed: 56 additions & 29 deletions

File tree

src/gitfetch/fetcher.py

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -542,42 +542,69 @@ def _fetch_contribution_graph(self, username: str) -> list:
542542
Returns:
543543
List of weeks with contribution data
544544
"""
545-
# GraphQL query for contribution calendar (inline username)
546-
query = f'''{{
547-
user(login: "{username}") {{
548-
contributionsCollection(includePrivate: true) {{
549-
contributionCalendar {{
550-
weeks {{
551-
contributionDays {{
552-
contributionCount
553-
date
545+
queries = [
546+
# Preferred query: include private contributions when available.
547+
f'''{{
548+
user(login: "{username}") {{
549+
contributionsCollection(includePrivate: true) {{
550+
contributionCalendar {{
551+
weeks {{
552+
contributionDays {{
553+
contributionCount
554+
date
555+
}}
556+
}}
554557
}}
555558
}}
556559
}}
557-
}}
558-
}}
559-
}}'''
560+
}}''',
561+
# Fallback query for auth/scope combinations where includePrivate
562+
# can fail.
563+
f'''{{
564+
user(login: "{username}") {{
565+
contributionsCollection {{
566+
contributionCalendar {{
567+
weeks {{
568+
contributionDays {{
569+
contributionCount
570+
date
571+
}}
572+
}}
573+
}}
574+
}}
575+
}}
576+
}}''',
577+
]
578+
579+
for query in queries:
580+
try:
581+
result = subprocess.run(
582+
['gh', 'api', 'graphql', '-f', f'query={query}'],
583+
capture_output=True,
584+
text=True,
585+
timeout=30,
586+
env=self._build_env()
587+
)
560588

561-
try:
562-
result = subprocess.run(
563-
['gh', 'api', 'graphql', '-f', f'query={query}'],
564-
capture_output=True,
565-
text=True,
566-
timeout=30,
567-
env=self._build_env()
568-
)
589+
if result.returncode != 0:
590+
continue
569591

570-
if result.returncode != 0:
571-
return []
592+
data = json.loads(result.stdout)
593+
weeks = data.get('data', {}).get('user', {}).get(
594+
'contributionsCollection', {}).get(
595+
'contributionCalendar', {}).get('weeks', None)
572596

573-
data = json.loads(result.stdout)
574-
weeks = data.get('data', {}).get('user', {}).get(
575-
'contributionsCollection', {}).get(
576-
'contributionCalendar', {}).get('weeks', [])
577-
return weeks
597+
if isinstance(weeks, list):
598+
if data.get('errors'):
599+
if weeks:
600+
return weeks
601+
continue
602+
return weeks
578603

579-
except (subprocess.TimeoutExpired, json.JSONDecodeError, KeyError):
580-
return []
604+
except (subprocess.TimeoutExpired, json.JSONDecodeError, KeyError):
605+
continue
606+
607+
return []
581608

582609

583610
class GitLabFetcher(BaseFetcher):

0 commit comments

Comments
 (0)