fix(api): populate PullRequestStatus so apply requirements are evaluated#6535
Merged
chenrui333 merged 8 commits intoJun 25, 2026
Merged
Conversation
The synthetic command.Context built in APIController.apiParseAndValidate never set PullRequestStatus, so MergeableRequirement and ApprovedRequirement always read the zero value and rejected every API plan/apply against repos that listed those requirements in apply_requirements. Inject vcs.PullReqStatusFetcher into APIController and, when the request includes a real PR number, populate ctx.PullRequestStatus before returning the context. This mirrors how PlanCommandRunner and ApplyCommandRunner already handle the same field for the comment-driven flow. The field is optional, so existing callers (including tests) keep compiling unchanged. Fixes runatlantis#6534 Assisted-by: Claude <noreply@anthropic.com> Signed-off-by: Guilherme Barczyszyn <guilherme.barczyszyn@maistodos.com.br>
|
Any chance of this PR landing? "mergeable" check seems to be entirely broken currently |
Member
it would happen today |
Keep PR-backed API plan/apply requests running when the optional pull request status lookup fails, matching the comment-runner behavior of warning and continuing with zero-valued status. Assisted-by: OpenAI <noreply@openai.com> Signed-off-by: Rui Chen <rui@chenrui.dev>
Refresh PR status after the API apply endpoint runs its built-in plan phase so mergeable and approved requirements use the VCS state produced by that plan. Assisted-by: OpenAI <noreply@openai.com> Signed-off-by: Rui Chen <rui@chenrui.dev>
Reset cached pull request status when a status refresh fails so API apply requirements cannot reuse stale pre-plan mergeability or approval state. Assisted-by: OpenAI <noreply@openai.com> Signed-off-by: Rui Chen <rui@chenrui.dev>
chenrui333
approved these changes
Jun 25, 2026
Member
|
@gBarczyszyn thanks for your first contribution to atlantis! |
chenrui333
added a commit
that referenced
this pull request
Jun 25, 2026
chenrui333
added a commit
that referenced
this pull request
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6534
Problem
POST /api/planandPOST /api/applyalways fail withPull request must be mergeable before running …(or the equivalent forapproved) when the target repo configuresapply_requirements: [mergeable]or[approved], even when the PR is in fact mergeable/approved on the VCS side.Root cause
APIController.apiParseAndValidatebuilds a syntheticcommand.Contextfrom the JSON body but never populatescommand.Context.PullRequestStatus. That zero value is propagated to everycommand.ProjectContext.PullReqStatusbyProjectCommandContextBuilder, so the checks inserver/events/command_requirement_handler.go:read
IsMergeable=false/IsApproved=falseand reject the command unconditionally. The comment-driven runners do not have this issue becausePlanCommandRunner/ApplyCommandRunnerexplicitly callpullReqStatusFetcher.FetchPullStatus(ctx.Log, pull)and assign the result before building project commands.Change
PullReqStatusFetcher vcs.PullReqStatusFetcherfield onAPIController(novalidate:"required"tag — existing direct callers still compile).apiParseAndValidate, whenrequest.PR > 0and the fetcher is wired, callFetchPullStatus(logger, pull)and assign the result toctx.PullRequestStatusbefore returning the context.pullReqStatusFetcherfromserver.gointoAPIController. The same fetcher already drives the comment flow, so no new dependency is introduced.MockPullReqStatusFetcher:TestAPIController_PlanFetchesPullReqStatus— whenPR > 0, fetcher is called exactly once.TestAPIController_PlanSkipsPullReqStatusWhenNoPR— whenPRis omitted, fetcher is never called (zero-PR callers keep their previous behavior).Because
PullReqStatuscarries bothMergeableStatusandApprovalStatus, this single change unblocks bothmergeableandapprovedrequirements via the API.Validation
go test ./server/controllers/... ./server/...passes locally.go vetclean./api/apply(and the equivalent MCP write tool I'm running on a fork) was returning themergeablefailure for a PR that GitHub reported asMERGEABLE. With this fix, the requirement is evaluated against actual VCS state,terraform applyruns to completion when the PR meets the requirements, and is properly rejected when it does not.Backwards compatibility
The new field is optional. If it isn't wired (e.g. in third-party code constructing
APIControllerdirectly), behavior is exactly as before.PR=0requests also skip the fetch, matching existing behavior for branch-only API calls.I'm happy to iterate on naming or split tests differently if you'd prefer. Thanks for taking a look!
Developed with assistance from Claude Opus 4.7 via Claude Code.