Skip to content

Commit e561f0d

Browse files
committed
Handle blank contribution limit
1 parent 6c49633 commit e561f0d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

blog/06_fetch_contributions.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
from blog.pipeline_cache import write_cache, emit_gha_warnings # noqa: E402
2323

2424

25+
def env_int(name: str, default: int) -> int:
26+
raw = os.environ.get(name, "").strip()
27+
if not raw:
28+
return default
29+
try:
30+
return int(raw)
31+
except ValueError:
32+
print(f"::warning::{name}={raw!r} is not a valid integer; using {default}.")
33+
return default
34+
35+
2536
def main() -> None:
2637
repo = os.environ.get("GITHUB_REPOSITORY", "").strip()
2738
if not repo:
@@ -30,7 +41,7 @@ def main() -> None:
3041

3142
user = os.environ.get("GITHUB_CONTRIBUTIONS_USER", "").strip() or repo.split("/")[0]
3243
token = os.environ.get("GITHUB_TOKEN") or None
33-
limit = int(os.environ.get("GITHUB_CONTRIBUTIONS_LIMIT", "8"))
44+
limit = env_int("GITHUB_CONTRIBUTIONS_LIMIT", 8)
3445

3546
print(f"Fetching GitHub contributions for: {user}…")
3647
start = time.monotonic()

0 commit comments

Comments
 (0)