lljz66 commited on
Commit
b73a22b
·
verified ·
1 Parent(s): f63afcf

github: add quota()probe

Browse files
Files changed (1) hide show
  1. src/devnet/sources/github.py +23 -0
src/devnet/sources/github.py CHANGED
@@ -1,6 +1,8 @@
1
  """GitHub public data. Anonymous works (60 req/hr per Space IP); GITHUB_TOKEN raises it."""
2
  from __future__ import annotations
3
 
 
 
4
  from ..core import Resource, UpstreamError, get, strip_html
5
 
6
  API = "https://api.github.com"
@@ -105,4 +107,25 @@ def issues(owner: str, name: str, state: str = "open", limit: int = 20) -> dict:
105
  "count": len(items),
106
  "pull_requests_filtered": filtered_prs,
107
  "items": items,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
 
1
  """GitHub public data. Anonymous works (60 req/hr per Space IP); GITHUB_TOKEN raises it."""
2
  from __future__ import annotations
3
 
4
+ import os
5
+
6
  from ..core import Resource, UpstreamError, get, strip_html
7
 
8
  API = "https://api.github.com"
 
107
  "count": len(items),
108
  "pull_requests_filtered": filtered_prs,
109
  "items": items,
110
+ }
111
+
112
+
113
+ def quota() -> dict:
114
+ """Report GitHub's current rate-limit bucket. 60/hr without a token."""
115
+ configured = bool(os.environ.get("GITHUB_TOKEN", "").strip())
116
+ try:
117
+ payload = get(f"{API}/rate_limit", ttl=60)
118
+ except UpstreamError as exc:
119
+ return {
120
+ "configured": configured,
121
+ "usable": False,
122
+ "error": str(exc)[:160],
123
+ }
124
+ core = (payload.get("resources") or {}).get("core") or {}
125
+ return {
126
+ "configured": configured,
127
+ "usable": True,
128
+ "limit": core.get("limit"),
129
+ "remaining": core.get("remaining"),
130
+ "reset_at": core.get("reset"),
131
  }