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:
11
app.py
11
app.py
@@ -32,17 +32,17 @@ def _verify_signature(payload: bytes, signature_header: str | None) -> bool:
|
||||
return hmac.compare_digest(expected, signature_header.strip())
|
||||
|
||||
|
||||
def _handle_push(owner: str, repo: str, changed_files: list[str]) -> None:
|
||||
def _handle_push(owner: str, repo: str, branch: str, changed_files: list[str]) -> None:
|
||||
"""Process all changed markdown files in a push event."""
|
||||
for file_path in changed_files:
|
||||
if not file_path.endswith(".md"):
|
||||
continue
|
||||
logger.info("Checking %s/%s: %s", owner, repo, file_path)
|
||||
logger.info("Checking %s/%s@%s: %s", owner, repo, branch, file_path)
|
||||
try:
|
||||
content, sha = gitea_client.get_file(owner, repo, file_path)
|
||||
content, sha = gitea_client.get_file(owner, repo, file_path, branch)
|
||||
updated, changed = processor.process_document(content)
|
||||
if changed:
|
||||
gitea_client.update_file(owner, repo, file_path, updated, sha)
|
||||
gitea_client.update_file(owner, repo, file_path, updated, sha, branch)
|
||||
logger.info("Updated %s", file_path)
|
||||
else:
|
||||
logger.info("No BLIGHT triggers found in %s", file_path)
|
||||
@@ -65,6 +65,7 @@ def webhook():
|
||||
data = json.loads(payload)
|
||||
owner = data["repository"]["owner"]["login"]
|
||||
repo = data["repository"]["name"]
|
||||
branch = data.get("ref", "").removeprefix("refs/heads/")
|
||||
|
||||
# Collect unique file paths from all commits in the push
|
||||
seen: set[str] = set()
|
||||
@@ -81,7 +82,7 @@ def webhook():
|
||||
# Process in background so we return 200 to Gitea immediately
|
||||
thread = threading.Thread(
|
||||
target=_handle_push,
|
||||
args=(owner, repo, changed_files),
|
||||
args=(owner, repo, branch, changed_files),
|
||||
daemon=True,
|
||||
)
|
||||
thread.start()
|
||||
|
||||
Reference in New Issue
Block a user