From 562a15172a06f63b052994322eb386f28a5fab71 Mon Sep 17 00:00:00 2001 From: Finn Arne Gangstad Date: Mon, 11 Dec 2023 20:08:38 +0100 Subject: [PATCH] set policy_check status to success when no changes (#3780) Autoplan would set the "policy_check" status to successful if there were no modified projects in a PR, but "atlantis plan" would not. Changed "atlantis plan" to behave like autoplan in this regard. --- server/events/plan_command_runner.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/events/plan_command_runner.go b/server/events/plan_command_runner.go index 8563cee13e..044a594233 100644 --- a/server/events/plan_command_runner.go +++ b/server/events/plan_command_runner.go @@ -229,6 +229,12 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) { if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.Plan, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.PolicyCheck, 0, 0); err != nil { + ctx.Log.Warn("unable to update commit status: %s", err) + } + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.Apply, 0, 0); err != nil { + ctx.Log.Warn("unable to update commit status: %s", err) + } } } return @@ -282,6 +288,14 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) { !(result.HasErrors() || result.PlansDeleted) { ctx.Log.Info("Running policy check for %s", cmd.String()) p.policyCheckCommandRunner.Run(ctx, policyCheckCmds) + } else if len(projectCmds) == 0 && !cmd.IsForSpecificProject() { + // If there were no projects modified, we set successful commit statuses + // with 0/0 projects planned/policy_checked/applied successfully because some users require + // the Atlantis status to be passing for all pull requests. + ctx.Log.Debug("setting VCS status to success with no projects found") + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.PolicyCheck, 0, 0); err != nil { + ctx.Log.Warn("unable to update commit status: %s", err) + } } }