MCPcopy Create free account
hub / github.com/pollinations/pollinations / commit_gist

Function commit_gist

social/scripts/common.py:584–618  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

582
583
584def 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
621def read_gists_for_date(date_str: str, repo_root: str = None) -> List[Dict]:

Callers 1

mainFunction · 0.90

Calls 4

gist_path_for_prFunction · 0.85
_github_headersFunction · 0.85
get_file_shaFunction · 0.85
github_api_requestFunction · 0.85

Tested by

no test coverage detected