Only create merge history entries on the actual merge event #15
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/merge-history-on-edit"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The PR dispatch in
handleWebhookused to firehandlePRMergewheneverpr.Mergedwas true, without checking the webhook action. A merged PR staysmerged=trueforever, so any subsequent webhook event on it — a title change, a body edit, a label tweak, a comment — would re-fire the handler and insert another history row for the same merge.We noticed this while rewriting historical PR titles via the Forgejo API: each PATCH to a merged PR triggered an
editedwebhook, which produced a duplicate history entry. Seven PRs ended up with fourteen spurious rows in orbit's live DB before the pattern was clear. The duplicates were cleaned up manually via SQL, but the underlying bug remained.The fix
One-line guard on the dispatch. Require
action == "closed"alongsidepr.Merged, so the handler runs only on the actual merge event:The PR row itself still updates via
handlePREventon every webhook delivery — that runs unconditionally and is idempotent by design, so PR metadata in the store stays in sync with Forgejo regardless of which action fired.Regression test
TestWebhookPR_EditedAfterMergeinapi/webhooks_test.goexercises the bug directly: merge a PR, assert one history entry exists, send a follow-upeditedwebhook on the same (still-merged) PR, assert the history entry count is still one. The test also verifies the PR row picked up the edit viahandlePREvent— so we're confirming the fix doesn't over-correct and suppress legitimate state updates.Follow-ups
None. The fix is surgical and the test covers the exact scenario that produced the duplicates.