Auto merge dev → main (#1274)
* 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 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,7 +48,7 @@ def verify_signature(payload: bytes, signature: str) -> bool:
|
|||||||
return hmac.compare_digest(expected, signature)
|
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."""
|
"""Pull latest changes from main and restart pm2 processes."""
|
||||||
try:
|
try:
|
||||||
# Change to repo directory
|
# 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()}")
|
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
|
# Determine which processes to restart based on changed files
|
||||||
processes_to_restart = []
|
processes_to_restart = []
|
||||||
|
|
||||||
@@ -242,6 +253,8 @@ def webhook():
|
|||||||
# Extract changed files from commits
|
# Extract changed files from commits
|
||||||
commits = payload.get('commits', [])
|
commits = payload.get('commits', [])
|
||||||
pusher = payload.get('pusher', {}).get('name', 'unknown')
|
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)")
|
logger.info(f"Push from {pusher} with {len(commits)} commit(s)")
|
||||||
|
|
||||||
changed_files = []
|
changed_files = []
|
||||||
@@ -253,7 +266,7 @@ def webhook():
|
|||||||
logger.info(f"Changed files: {changed_files}")
|
logger.info(f"Changed files: {changed_files}")
|
||||||
|
|
||||||
# Pull and restart
|
# Pull and restart
|
||||||
success, message = pull_and_restart(changed_files)
|
success, message = pull_and_restart(changed_files, before, after)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
logger.info(f"Webhook update successful: {message}")
|
logger.info(f"Webhook update successful: {message}")
|
||||||
|
|||||||
Reference in New Issue
Block a user