Skip to content

Commit

Permalink
fix: Line length, quoting, function comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jskrill committed Nov 2, 2023
1 parent 2375166 commit dcd5851
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ var stringFlags = map[string]stringFlag{
description: "URL that Atlantis can be reached at. Defaults to http://$(hostname):$port where $port is from --" + PortFlag + ". Supports a base path ex. https://example.com/basepath.",
},
AutoDiscoverModeFlag: {
description: "Auto discover mode controls whether projects in a repo are discovered by Atlantis. Defaults to \"auto\" which " +
"means projects will be discovered when no explicit projects are defined in repo config. Also supports \"enabled\" (always " +
"discover projects) and \"disabled\" (never discover projects).",
description: "Auto discover mode controls whether projects in a repo are discovered by Atlantis. Defaults to 'auto' which " +
"means projects will be discovered when no explicit projects are defined in repo config. Also supports 'enabled' (always " +
"discover projects) and 'disabled' (never discover projects).",
defaultValue: DefaultAutoDiscoverMode,
},
AutoplanModulesFromProjects: {
Expand Down
6 changes: 3 additions & 3 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ Values are chosen in this order:
# or
ATLANTIS_AUTODISCOVER_MODE="<auto|enabled|disabled>"
```
Sets auto discover mode, default is "auto". When set to "auto", projects in a repo will be discovered by
Sets auto discover mode, default is `auto`. When set to `auto`, projects in a repo will be discovered by
Atlantis when there are no projects configured in the repo config. If one or more projects are defined
in the repo config then auto discovery will be completely disabled.

When set to "enabled" projects will be discovered unconditionally. If an auto discovered project is already
When set to `enabled` projects will be discovered unconditionally. If an auto discovered project is already
defined in the projects section of the repo config, the project from the repo config will take precedence over
the auto discovered project.

When set to "disabled" projects will never be discovered, even if there are no projects configured in the repo config.
When set to `disabled` projects will never be discovered, even if there are no projects configured in the repo config.

### `--automerge`
```bash
Expand Down
3 changes: 3 additions & 0 deletions server/core/config/valid/global_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ func (g GlobalCfg) DefaultProjCfg(log logging.SimpleLogging, repoID string, repo
}
}

// RepoAutoDiscoverCfg returns the AutoDiscover config from the global config
// for the repo with id repoID. If no matching repo is found or there is no
// AutoDiscover config then this function returns nil.
func (g GlobalCfg) RepoAutoDiscoverCfg(repoID string) *AutoDiscover {
repo := g.MatchingRepo(repoID)
if repo != nil {
Expand Down
6 changes: 5 additions & 1 deletion server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,18 @@ func isRegexAllowed(name string, allowedRegexpPrefixes []string) bool {
return false
}

// This function returns a final true/false decision for whether AutoDiscover is enabled
// for a repo. It takes into account the defaultAutoDiscoverMode when there is no explicit
// repo config. The defaultAutoDiscoverMode param should be understood as the default
// AutoDiscover mode as may be set via CLI params or server side repo config.
func (r RepoCfg) AutoDiscoverEnabled(defaultAutoDiscoverMode AutoDiscoverMode) bool {
autoDiscoverMode := defaultAutoDiscoverMode
if r.AutoDiscover != nil {
autoDiscoverMode = r.AutoDiscover.Mode
}

if autoDiscoverMode == AutoDiscoverAutoMode {
// Autodiscover is enabled by default when no projects are defined
// AutoDiscover is enabled by default when no projects are defined
return len(r.Projects) == 0
}

Expand Down
1 change: 0 additions & 1 deletion server/core/config/valid/valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
package valid

const DefaultAutoPlanEnabled = true
const DefaultAutoDiscoverEnabled = true
24 changes: 12 additions & 12 deletions server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ const (
// DefaultWorkspace is the default Terraform workspace we run commands in.
// This is also Terraform's default workspace.
DefaultWorkspace = "default"
// DefaultAutomergeEnabled is the default for the automerge setting.
DefaultAutomergeEnabled = false
// DefaultAutoDiscoverEnabled is the default for the auto discover setting.
DefaultAutoDiscoverEnabled = true
// DefaultParallelApplyEnabled is the default for the parallel apply setting.
DefaultParallelApplyEnabled = false
// DefaultParallelPlanEnabled is the default for the parallel plan setting.
DefaultParallelPlanEnabled = false
// DefaultDeleteSourceBranchOnMerge being false is the default setting whether or not to remove a source branch on merge
DefaultDeleteSourceBranchOnMerge = false
// DefaultAbortOnExcecutionOrderFail being false is the default setting for abort on execution group failiures
Expand Down Expand Up @@ -433,7 +425,12 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
return nil, errors.Wrapf(err, "parsing %s", repoCfgFile)
}
ctx.Log.Info("successfully parsed %s file", repoCfgFile)
// This above condition to set this may not have been reached
// It's possible we've already set defaultAutoDiscoverMode
// from the config file while checking whether we can skip
// cloning. We still need to set it here in the case that
// we were not able to check whether we can skip cloning
// and thus were not able to previously fetch the repo
// config.
if repoCfg.AutoDiscover != nil {
defaultAutoDiscoverMode = repoCfg.AutoDiscover.Mode
}
Expand Down Expand Up @@ -504,8 +501,10 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
ctx.Log.Info("found no %s file", repoCfgFile)
}
// build a module index for projects that are explicitly included
allModifiedProjects := p.ProjectFinder.DetermineProjects(ctx.Log, modifiedFiles, ctx.Pull.BaseRepo.FullName, repoDir, p.AutoplanFileList, moduleInfo)
// If a project is already manually configured with the same dir as a discovered project, the manually configured project should take precedence
allModifiedProjects := p.ProjectFinder.DetermineProjects(
ctx.Log, modifiedFiles, ctx.Pull.BaseRepo.FullName, repoDir, p.AutoplanFileList, moduleInfo)
// If a project is already manually configured with the same dir as a discovered project, the manually configured
// project should take precedence
modifiedProjects := make([]models.Project, 0)
configuredProjDirs := make(map[string]bool)
// We compare against all configured projects instead of projects which match the modified files in case a
Expand All @@ -521,7 +520,8 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
modifiedProjects = append(modifiedProjects, mp)
}
}
ctx.Log.Info("automatically determined that there were %d additional projects modified in this pull request: %s", len(modifiedProjects), modifiedProjects)
ctx.Log.Info("automatically determined that there were %d additional projects modified in this pull request: %s",
len(modifiedProjects), modifiedProjects)
for _, mp := range modifiedProjects {
ctx.Log.Debug("determining config for project at dir: %q", mp.Path)
pWorkspace, err := p.ProjectFinder.DetermineWorkspaceFromHCL(ctx.Log, repoDir)
Expand Down

0 comments on commit dcd5851

Please sign in to comment.