fix: pass changed refs list to post-receive hook
This commit is contained in:
+5
-11
@@ -34,7 +34,7 @@ def _git(*args: str, timeout: int = 300, check: bool = True) -> str:
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
env={**os.environ, "LC_ALL": "C", "GITEA_PUSH_VERIFIED": "1"},
|
||||
env={**os.environ, "LC_ALL": "C"},
|
||||
)
|
||||
except FileNotFoundError:
|
||||
raise GiteaError("git not found on PATH")
|
||||
@@ -115,13 +115,12 @@ def push_to_gitea(mirror: Mirror) -> bool:
|
||||
return False
|
||||
|
||||
logger.info("Synced %d ref(s) to Gitea", len(changed))
|
||||
_trigger_gitea_post_receive(gitea_path, mirror.config.gitea)
|
||||
_trigger_gitea_post_receive(changed, mirror.config.gitea)
|
||||
return True
|
||||
|
||||
|
||||
def _trigger_gitea_post_receive(gitea_path: Path, gitea_cfg):
|
||||
def _trigger_gitea_post_receive(changed: list, gitea_cfg):
|
||||
"""Fire Gitea's post-receive hook so the UI refreshes immediately."""
|
||||
# Find the gitea hook binary
|
||||
candidates = ("/usr/local/bin/gitea", "/usr/bin/gitea", "gitea")
|
||||
hook_bin = None
|
||||
for c in candidates:
|
||||
@@ -134,15 +133,10 @@ def _trigger_gitea_post_receive(gitea_path: Path, gitea_cfg):
|
||||
|
||||
try:
|
||||
config_path = os.environ.get("GITEA_CONFIG", "/etc/gitea/app.ini")
|
||||
# Build stdin with the ref updates that would normally arrive
|
||||
# Format: "<old-hash> <new-hash> <refname>\n"
|
||||
data = _git("--git-dir", str(gitea_path), "for-each-ref",
|
||||
"--format=%(objectname) %(objectname) %(refname)",
|
||||
"refs/heads/", "refs/tags/",
|
||||
timeout=15, check=False)
|
||||
lines = "\n".join(f"{o} {n} {r}" for o, n, r in changed)
|
||||
r = subprocess.run(
|
||||
[hook_bin, "hook", "--config", config_path, "post-receive"],
|
||||
input=(data or "").encode(),
|
||||
input=lines.encode(),
|
||||
capture_output=True,
|
||||
timeout=60,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user