Files
atlantis/server/events/version_command_runner.go
Sarvar Muminov 90e92e3a13 chore: move CommandContext and CommandResult to models (#193) (#2093)
* Moved CommandContext and CommandResult to models (#193)

* Moved CommandContext and CommandResult to models

* move from models to command

rename CommandContext -> Context
rename CommandResult -> Result

* moved command related helpers into command package

* move ProjectCommandContext and ProjectResult to command/project package

* move project command context and project result

* revert unrelated code

* move tests

* fix left over

* fix linting

* fix tests

* remove unused import

* fix project context dependencies

* fix depenedecies

* fix typo
2022-03-21 10:36:13 -07:00

61 lines
1.7 KiB
Go

package events
import (
"github.com/runatlantis/atlantis/server/events/command"
)
func NewVersionCommandRunner(
pullUpdater *PullUpdater,
prjCmdBuilder ProjectVersionCommandBuilder,
prjCmdRunner ProjectVersionCommandRunner,
parallelPoolSize int,
silenceVCSStatusNoProjects bool,
) *VersionCommandRunner {
return &VersionCommandRunner{
pullUpdater: pullUpdater,
prjCmdBuilder: prjCmdBuilder,
prjCmdRunner: prjCmdRunner,
parallelPoolSize: parallelPoolSize,
silenceVCSStatusNoProjects: silenceVCSStatusNoProjects,
}
}
type VersionCommandRunner struct {
pullUpdater *PullUpdater
prjCmdBuilder ProjectVersionCommandBuilder
prjCmdRunner ProjectVersionCommandRunner
parallelPoolSize int
// SilenceVCSStatusNoProjects is whether any plan should set commit status if no projects
// are found
silenceVCSStatusNoProjects bool
}
func (v *VersionCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) {
var err error
var projectCmds []command.ProjectContext
projectCmds, err = v.prjCmdBuilder.BuildVersionCommands(ctx, cmd)
if err != nil {
ctx.Log.Warn("Error %s", err)
}
if len(projectCmds) == 0 {
ctx.Log.Info("no projects to run version in")
return
}
// Only run commands in parallel if enabled
var result command.Result
if v.isParallelEnabled(projectCmds) {
ctx.Log.Info("Running version in parallel")
result = runProjectCmdsParallel(projectCmds, v.prjCmdRunner.Version, v.parallelPoolSize)
} else {
result = runProjectCmds(projectCmds, v.prjCmdRunner.Version)
}
v.pullUpdater.updatePull(ctx, cmd, result)
}
func (v *VersionCommandRunner) isParallelEnabled(cmds []command.ProjectContext) bool {
return len(cmds) > 0 && cmds[0].ParallelPolicyCheckEnabled
}