feat(automerge): merge scheduled PRs via cron with CI grace period #2

Merged
Fryuni merged 1 commit from t3code/pr-auto-merge-scheduled into forgejo 2026-09-13 18:20:12 +00:00
Owner

Summary

  • Add a check_scheduled_auto_merges cron task (every 1m by default) that re-queues open scheduled auto-merge PRs, so merges can proceed after the CI grace period without a new status event
  • Introduce actions.AreRunsReadyToMerge: all existing Actions runs for the head SHA must have succeeded/skipped and stopped at least 30 seconds ago; missing runs do not block, and branch protection still applies
  • Keep the auto-merge option available even when a PR can merge now, and persist the saved merge title/message and delete-branch choice for auto-merge (including rebase style)
  • Allow empty merge message for rebase merges and honor a supplied message in doMergeRebaseFastForward instead of always amending from the template
  • Fix auto-merge permission checks to use the base repo (not head repo), skip merging for archived base repos, serialize per-PR handling via a keyed mutex, and delete the schedule only after a successful merge
  • Mark expected waiting conditions (closed, WIP, dependencies, disallowed user, etc.) as trace-level instead of info

Testing

  • Added TestAreRunsReadyToMerge unit tests covering status/skip/grace-period boundaries, cross-commit/repo isolation, and retry success
  • Added integration tests: TestPeriodicAutoMergeActions (merge/squash/rebase styles with message, branch deletion, grace period and failure handling), TestPeriodicAutoMergeWithoutRuns (no runs, closed issue, archived repo), and TestPeriodicAutoMergeFromFork
  • Added Vitest cases confirming the merge form saves title/message and delete-branch choice for auto-merge across styles
  • Updated TestActionsAutomerge to sync the fixture PR ref and event payload with the head branch
  • Not run: full make test-sqlite, MySQL/PostgreSQL integration suites, and browser E2E
## Summary - Add a `check_scheduled_auto_merges` cron task (every 1m by default) that re-queues open scheduled auto-merge PRs, so merges can proceed after the CI grace period without a new status event - Introduce `actions.AreRunsReadyToMerge`: all existing Actions runs for the head SHA must have succeeded/skipped and stopped at least 30 seconds ago; missing runs do not block, and branch protection still applies - Keep the auto-merge option available even when a PR can merge now, and persist the saved merge title/message and delete-branch choice for auto-merge (including rebase style) - Allow empty merge message for rebase merges and honor a supplied message in `doMergeRebaseFastForward` instead of always amending from the template - Fix auto-merge permission checks to use the base repo (not head repo), skip merging for archived base repos, serialize per-PR handling via a keyed mutex, and delete the schedule only after a successful merge - Mark expected waiting conditions (closed, WIP, dependencies, disallowed user, etc.) as trace-level instead of info ## Testing - Added `TestAreRunsReadyToMerge` unit tests covering status/skip/grace-period boundaries, cross-commit/repo isolation, and retry success - Added integration tests: `TestPeriodicAutoMergeActions` (merge/squash/rebase styles with message, branch deletion, grace period and failure handling), `TestPeriodicAutoMergeWithoutRuns` (no runs, closed issue, archived repo), and `TestPeriodicAutoMergeFromFork` - Added Vitest cases confirming the merge form saves title/message and delete-branch choice for auto-merge across styles - Updated `TestActionsAutomerge` to sync the fixture PR ref and event payload with the head branch - Not run: full `make test-sqlite`, MySQL/PostgreSQL integration suites, and browser E2E
- Add check_scheduled_auto_merges cron task retrying pending auto-merges every minute
- Require Actions runs to succeed and finish >30s before merging; missing runs no longer block
- Allow scheduling auto-merge for any merge style, persisting custom title/message and branch deletion
- Support custom commit messages for rebase merges
- Skip auto-merge for closed PRs and archived repos; check base repo permissions
Fryuni merged commit 219b1acdb2 into forgejo 2026-09-13 18:20:12 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Fryuni/forgejo!2
No description provided.