Commit a gist JSON file to the news branch via the GitHub Contents API. Returns True on success, False on failure.
(gist: Dict, github_token: str, owner: str, repo: str)
| 582 | |
| 583 | |
| 584 | def commit_gist(gist: Dict, github_token: str, owner: str, repo: str) -> bool: |
| 585 | """Commit a gist JSON file to the news branch via the GitHub Contents API. |
| 586 | Returns True on success, False on failure.""" |
| 587 | file_path = gist_path_for_pr(gist["pr_number"], gist["merged_at"]) |
| 588 | content = json.dumps(gist, indent=2, ensure_ascii=False) |
| 589 | |
| 590 | import base64 as _b64 |
| 591 | encoded = _b64.b64encode(content.encode()).decode() |
| 592 | |
| 593 | headers = _github_headers(github_token) |
| 594 | |
| 595 | # Check if file already exists (re-run / retry scenario) |
| 596 | sha = get_file_sha(github_token, owner, repo, file_path, GISTS_BRANCH) |
| 597 | |
| 598 | payload = { |
| 599 | "message": f"chore(news): add gist for PR #{gist['pr_number']}", |
| 600 | "content": encoded, |
| 601 | "branch": GISTS_BRANCH, |
| 602 | } |
| 603 | if sha: |
| 604 | payload["sha"] = sha |
| 605 | |
| 606 | resp = github_api_request( |
| 607 | "PUT", |
| 608 | f"{GITHUB_API_BASE}/repos/{owner}/{repo}/contents/{file_path}", |
| 609 | headers=headers, |
| 610 | json=payload, |
| 611 | ) |
| 612 | |
| 613 | if resp.status_code in [200, 201]: |
| 614 | print(f" Committed gist to {file_path} on {GISTS_BRANCH}") |
| 615 | return True |
| 616 | |
| 617 | print(f" Failed to commit gist: {resp.status_code} {resp.text[:200]}") |
| 618 | return False |
| 619 | |
| 620 | |
| 621 | def read_gists_for_date(date_str: str, repo_root: str = None) -> List[Dict]: |
no test coverage detected