CodeIssuesPull RequestsActionsSecurityInsights
✨ AI
More
Settings

feat(api): implement the documented v2 PR merge endpoint (closes #194) #3525

MergedXLccantynz wants to mergefeat/api-v2-merge-endpointmainopened 25d ago
ccantynzcommented 25d ago

Closes #194.

POST /api/v2/repos/:owner/:repo/pulls/:number/merge was documented at /docs but never implemented � API callers (including AI agents when the MCP connector token expires) had no JSON merge path.

Approach � one gating chain, two transports. The full pre-merge policy chain lived inline in the MCP gluecron_merge_pr handler. It moves verbatim to src/lib/pr-merge-gated.ts (performGatedMerge) and both the MCP tool and the new REST endpoint delegate to it, so the two surfaces cannot drift:

  • open/draft guards ? M3 risk score (critical band soft-blocks unless {"confirmHighRisk": true} in the body) ? GateTest + AI-review hard gates ? D5 branch protection + CODEOWNERS (fail-open) ? ref update or AI conflict auto-resolve ? DB flip, J7 close-keywords, audit + activity + webhooks.
  • REST responses match the docs exactly: 200 {merged:true, sha} / 422 {merged:false, reason} (+ riskScore when relevant). Auth: requireApiAuth + repo scope + repo write-ACL via resolveRepoAccess.
  • Audit/activity metadata records source: "api" vs "mcp" so incidents can tell the paths apart.
  • Docs updated with the risk-block case and confirmHighRisk.

Tests: mcp-write.test.ts (34/34) now exercises the shared chain through the MCP tool; new 401 test for the REST route; tsc --noEmit clean; adjacent suites (mcp-tools-expanded, auto-merge, connect-claude) green. The 13 pre-existing api-v2.test.ts failures in a no-DB environment are untouched.

?? Generated with Claude Code

Cross-repo impact

See what breaks downstream if this PR merges.

Analyze →
Closing issues1
API docs advertise POST /api/v2/repos/:owner/:repo/pulls/:number/merge but no route implements it#194closed
⮌ Merged

This pull request was merged into main.

c comment · e edit title · m merge · a approve · r request changes · ? shortcuts