fix: API Controller CommentCommand.Name defaults to Apply instead of Plan#6090
Merged
jamengual merged 8 commits intorunatlantis:mainfrom Jan 26, 2026
Merged
Conversation
… be applied Signed-off-by: Ricardo Silveira <ricardo.silveira@olx.com>
…anges to be applied" This reverts commit 84c676a.
Signed-off-by: Ricardo Silveira <ricardo.silveira@olx.com>
Signed-off-by: Ricardo Silveira <ricardo.silveira@olx.com>
Signed-off-by: Ricardo Silveira <ricardo.silveira@olx.com>
jamengual
approved these changes
Jan 26, 2026
Contributor
|
Thanks @rjmsilveira for the contribution |
Merged
aidansteele
pushed a commit
to aidansteele/atlantis
that referenced
this pull request
Mar 12, 2026
…Plan (runatlantis#6090) Signed-off-by: Ricardo Silveira <ricardo.silveira@olx.com> Co-authored-by: Ricardo Silveira <ricardo.silveira@olx.com> Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
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.
What
Fixed a bug in the API controller where
CommentCommand.Namewas not being set when creating commands, causing the command type to default toApply(value0) instead of the intended command type (PlanorApply).Changes:
cmdName command.Nameparameter to thegetCommands()functionName: cmdNameon eachCommentCommandstruct created for projects and pathsapiPlan()to passcommand.PlantogetCommands()apiApply()to passcommand.ApplytogetCommands()Why
The
command.Nametype is defined usingiota:When the API controller created
CommentCommandstructs, theNamefield was never set:Since Go initializes unset fields to their zero value,
Namedefaulted to0, which isApply. This caused:CommentCommand.Nameincorrectly set toApplyBuildPlanCommands()function received the wrong command name viacmd.CommandName()How the issue was detected
The bug was discovered when using
pre_workflow_hookswith thecommandsfilter set toplan:When calling the API
/api/planendpoint, the pre-workflow hook was not executing even though it should only run forplancommands. Investigation revealed that theCommentCommand.Namewas incorrectly set toApply(the zero value) instead ofPlan, causing thecommands: planfilter to skip the hook.Tests
Existing tests in
server/controllers/api_controller_test.gocover this functionality:TestAPIController_Plan- verifiesBuildPlanCommandsis called correctlyTestAPIController_Apply- verifiesBuildApplyCommandsis called correctlyNew tests added to specifically verify the
CommentCommand.Nameis correctly set for pre-workflow hooks:TestAPIController_Plan_PreWorkflowHooksReceiveCorrectCommand- verifies that when calling the Plan API endpoint, the pre-workflow hooks receive aCommentCommandwithNameset tocommand.PlanTestAPIController_Apply_PreWorkflowHooksReceiveCorrectCommand- verifies that when calling the Apply API endpoint, the pre-workflow hooks receive the correctCommentCommand.Namefor each phase (command.Planfor the plan phase,command.Applyfor the apply phase)These tests use pegomock's
GetCapturedArguments()to capture the actualCommentCommandpassed toRunPreHooks()and assert that theNamefield is correctly set.To run the tests:
References
command.Nameiota definition:server/events/command/name.goCommentCommandstruct:server/events/comment_command.goBuildPlanCommandsusescmd.CommandName():server/events/project_command_builder.go:279getCommands()function:server/controllers/api_controller.go:59commandsfilter:server/events/pre_workflow_hooks_command_runner.go