Skip to content

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented Jan 17, 2025

what

Fix the VCS combined status check from being set to pending twice when pre-workflow hooks are configured.

The CommitStatusUpdater.UpdateCombined function calls have been moved out of the RunPreHooks and plan/apply Run functions and adding to the upstream RunAutoplanCommand, RunCommentCommand , ApiPlan and ApiApply functions.

why

  • Removes status check update failure message from log.

tests

Logs Before
{"level":"info","ts":"2025-01-26T18:04:31.129Z","caller":"events/events_controller.go:692","msg":"Handling 'plan' comment","json":{"repo":"sheather/test","pull":31}}
{"level":"info","ts":"2025-01-26T18:04:32.285Z","caller":"events/events_controller.go:736","msg":"Running comment command 'plan' for user 'sheather'.","json":{"repo":"sheather/test","pull":31}}
{"level":"info","ts":"2025-01-26T18:04:33.538Z","caller":"events/pre_workflow_hooks_command_runner.go:53","msg":"Pre-workflow hooks configured, running...","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:04:33.579Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/plan' to 'running'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:04:33.740Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:04:33.933Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/pre_workflow_hook: Atlantis Setup' to 'running'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:04:34.225Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:05:04.812Z","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"Successfully ran 'bash -ce echo \"Terraform Version: $ATLANTIS_TERRAFORM_VERSION\"\nsleep 30\n' in '/root/.atlantis/repos/sheather/test/31/default'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:05:04.812Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/pre_workflow_hook: Atlantis Setup' to 'success'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:05:04.908Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:05:05.142Z","caller":"events/pre_workflow_hooks_command_runner.go:103","msg":"Pre-workflow hooks completed successfully","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:05:06.265Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/plan' to 'running'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:05:06.394Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"warn","ts":"2025-01-26T18:05:06.621Z","caller":"events/plan_command_runner.go:192","msg":"unable to update commit status: POST https://gitlab.lan/api/v4/projects/sheather/test/statuses/a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b: 400 {message: Cannot transition status via :run from :running (Reason(s): Status cannot transition via \"run\")}","json":{"repo":"sheather/test","pull":"31"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).run\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/plan_command_runner.go:192\ngithub.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).Run\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/plan_command_runner.go:307\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:383"}
Logs After
{"level":"info","ts":"2025-01-26T18:15:09.044Z","caller":"events/events_controller.go:692","msg":"Handling 'plan' comment","json":{"repo":"sheather/test","pull":31}}
{"level":"info","ts":"2025-01-26T18:15:09.605Z","caller":"events/events_controller.go:736","msg":"Running comment command 'plan' for user 'sheather'.","json":{"repo":"sheather/test","pull":31}}
{"level":"info","ts":"2025-01-26T18:15:10.520Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/plan' to 'running'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:10.807Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:11.100Z","caller":"events/pre_workflow_hooks_command_runner.go:53","msg":"Pre-workflow hooks configured, running...","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:11.115Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/pre_workflow_hook: Atlantis Setup' to 'running'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:11.822Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:42.359Z","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"Successfully ran 'bash -ce echo \"Terraform Version: $ATLANTIS_TERRAFORM_VERSION\"\nsleep 30\n' in '/root/.atlantis/repos/sheather/test/31/default'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:42.360Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/pre_workflow_hook: Atlantis Setup' to 'success'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:42.464Z","caller":"vcs/gitlab_client.go:436","msg":"Pipeline found for commit a1e2908f540bd9e0b9beb57ace6ebbdecf57bc9b, setting pipeline ID to 100","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-01-26T18:15:42.674Z","caller":"events/pre_workflow_hooks_command_runner.go:91","msg":"Pre-workflow hooks completed successfully","json":{"repo":"sheather/test","pull":"31"}}

references

@X-Guardian X-Guardian marked this pull request as ready for review January 26, 2025 18:24
@X-Guardian X-Guardian requested review from a team as code owners January 26, 2025 18:24
@X-Guardian X-Guardian requested review from GenPage, lukemassa and nitrocode and removed request for a team January 26, 2025 18:25
@dosubot dosubot bot added bug Something isn't working go Pull requests that update Go code labels Jan 26, 2025
@X-Guardian X-Guardian requested review from a team, jamengual, lukemassa and nitrocode and removed request for a team February 1, 2025 16:37
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 1, 2025
@X-Guardian X-Guardian merged commit be06063 into runatlantis:main Feb 1, 2025
39 checks passed
@X-Guardian X-Guardian deleted the pre-workflow-hook-status-check-fix branch February 1, 2025 19:12
bub3n pushed a commit to bub3n/atlantis that referenced this pull request Feb 3, 2025
bub3n pushed a commit to bub3n/atlantis that referenced this pull request Feb 4, 2025
jamengual added a commit that referenced this pull request Aug 15, 2025
…cts found

This fixes issue #5389 where PRs were getting stuck with pending status when
ATLANTIS_SILENCE_VCS_STATUS_NO_PLANS and ATLANTIS_SILENCE_VCS_STATUS_NO_PROJECTS
were enabled and no projects matched when_modified patterns.

Root cause:
- PR #5242 (commit be06063) introduced early pending status setting in command_runner.go
- When silence flags are enabled and no projects are found, the pending status was never cleared
- This left PRs stuck in pending state, blocking auto-merge functionality

Solution:
- Modified plan_command_runner.go to clear pending status even when silence flags are enabled
- Added else blocks to both autoplan and manual plan paths
- When silence is enabled but no projects found, update status to success (0/0) to clear pending
- Added comprehensive test to prevent regression

Testing:
- Updated existing test expectation for silence flag behavior
- Added new test TestPlanCommandRunner_SilenceFlagsClearsPendingStatus
- All existing tests continue to pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working go Pull requests that update Go code lgtm This PR has been approved by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VCS Combined Status Check is set to Pending twice when Pre-Workflow Hooks are Configured
2 participants