Initial commit: BLIGHT: CUE
Webhook listener that monitors Gitea repos for BLIGHT: triggers in markdown files, processes them via Gemini 2.5 Flash-Lite, and writes results back in-place. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
44
gitea_client.py
Normal file
44
gitea_client.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import base64
|
||||
import requests
|
||||
import config
|
||||
|
||||
|
||||
def _headers() -> dict:
|
||||
return {
|
||||
"Authorization": f"token {config.GITEA_TOKEN}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
|
||||
def get_file(owner: str, repo: str, path: str) -> tuple[str, str]:
|
||||
"""Fetch a file's decoded content and its SHA from Gitea.
|
||||
|
||||
Returns:
|
||||
(content, sha) where content is the decoded UTF-8 string and sha is
|
||||
required for the subsequent update call.
|
||||
"""
|
||||
url = f"{config.GITEA_URL}/api/v1/repos/{owner}/{repo}/contents/{path}"
|
||||
response = requests.get(url, headers=_headers(), timeout=30)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
content = base64.b64decode(data["content"]).decode("utf-8")
|
||||
return content, data["sha"]
|
||||
|
||||
|
||||
def update_file(
|
||||
owner: str,
|
||||
repo: str,
|
||||
path: str,
|
||||
content: str,
|
||||
sha: str,
|
||||
commit_message: str = "BLIGHT: process triggers",
|
||||
) -> None:
|
||||
"""Write updated file content back to Gitea."""
|
||||
url = f"{config.GITEA_URL}/api/v1/repos/{owner}/{repo}/contents/{path}"
|
||||
payload = {
|
||||
"message": commit_message,
|
||||
"content": base64.b64encode(content.encode("utf-8")).decode("ascii"),
|
||||
"sha": sha,
|
||||
}
|
||||
response = requests.put(url, headers=_headers(), json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
Reference in New Issue
Block a user