From c7230819163fe544a13f12ed77a7e0b8c6509b03 Mon Sep 17 00:00:00 2001 From: NotSoToothless <67082114+FURRO404@users.noreply.github.com> Date: Wed, 27 May 2026 05:56:17 -0700 Subject: [PATCH] =?UTF-8?q?Auto=20merge=20dev=20=E2=86=92=20main=20(#1274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update homepage * fix webhook missing restarts on PR merge (empty commits payload) When GitHub fires a push event for a PR merge, the commits array is sometimes empty, leaving changed_files as [] and skipping all restarts. Fall back to git diff --name-only using the before/after SHAs from the payload so changed files are always derived correctly. Co-Authored-By: Claude Sonnet 4.6 --------- Co-authored-by: Claude Sonnet 4.6 --- github_webhook_updater.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/github_webhook_updater.py b/github_webhook_updater.py index 6c66d2d..99ea99e 100644 --- a/github_webhook_updater.py +++ b/github_webhook_updater.py @@ -48,7 +48,7 @@ def verify_signature(payload: bytes, signature: str) -> bool: return hmac.compare_digest(expected, signature) -def pull_and_restart(changed_files: list[str]) -> tuple[bool, str]: +def pull_and_restart(changed_files: list[str], before: str = '', after: str = '') -> tuple[bool, str]: """Pull latest changes from main and restart pm2 processes.""" try: # Change to repo directory @@ -79,6 +79,17 @@ def pull_and_restart(changed_files: list[str]) -> tuple[bool, str]: logger.info(f"Pull successful: {pull_result.stdout.strip()}") + # If the payload commits list was empty (e.g. GitHub PR merge), derive + # changed files from the before/after SHAs instead. + if not changed_files and before and after and before != '0' * 40: + diff_result = subprocess.run( + ['git', 'diff', '--name-only', before, after], + capture_output=True, text=True, timeout=15 + ) + if diff_result.returncode == 0: + changed_files = [f for f in diff_result.stdout.splitlines() if f] + logger.info(f"Derived changed files from git diff: {changed_files}") + # Determine which processes to restart based on changed files processes_to_restart = [] @@ -242,6 +253,8 @@ def webhook(): # Extract changed files from commits commits = payload.get('commits', []) pusher = payload.get('pusher', {}).get('name', 'unknown') + before = payload.get('before', '') + after = payload.get('after', '') logger.info(f"Push from {pusher} with {len(commits)} commit(s)") changed_files = [] @@ -253,7 +266,7 @@ def webhook(): logger.info(f"Changed files: {changed_files}") # Pull and restart - success, message = pull_and_restart(changed_files) + success, message = pull_and_restart(changed_files, before, after) if success: logger.info(f"Webhook update successful: {message}")