Fix loop re-processing, branch awareness, and commit message clarity
- Sanitize AI responses by replacing BLIGHT: with BLIGHT: to prevent the service's own commits from triggering another processing cycle - Pass branch (extracted from refs/heads/<branch>) through to Gitea get/update calls so pushes to non-default branches are read and written correctly - Commit message now includes the file path: "BLIGHT: process triggers in <path>" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ def _headers() -> dict:
|
||||
}
|
||||
|
||||
|
||||
def get_file(owner: str, repo: str, path: str) -> tuple[str, str]:
|
||||
def get_file(owner: str, repo: str, path: str, branch: str) -> tuple[str, str]:
|
||||
"""Fetch a file's decoded content and its SHA from Gitea.
|
||||
|
||||
Returns:
|
||||
@@ -18,7 +18,7 @@ def get_file(owner: str, repo: str, path: str) -> tuple[str, str]:
|
||||
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 = requests.get(url, headers=_headers(), params={"ref": branch}, timeout=30)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
content = base64.b64decode(data["content"]).decode("utf-8")
|
||||
@@ -31,14 +31,16 @@ def update_file(
|
||||
path: str,
|
||||
content: str,
|
||||
sha: str,
|
||||
commit_message: str = "BLIGHT: process triggers",
|
||||
branch: str,
|
||||
commit_message: str | None = None,
|
||||
) -> None:
|
||||
"""Write updated file content back to Gitea."""
|
||||
url = f"{config.GITEA_URL}/api/v1/repos/{owner}/{repo}/contents/{path}"
|
||||
payload = {
|
||||
"message": commit_message,
|
||||
"message": commit_message or f"BLIGHT: process triggers in {path}",
|
||||
"content": base64.b64encode(content.encode("utf-8")).decode("ascii"),
|
||||
"sha": sha,
|
||||
"branch": branch,
|
||||
}
|
||||
response = requests.put(url, headers=_headers(), json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user