Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion runatlantis.io/docs/command-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ patterns to perform a **targeted** divergence check. Instead of failing when **a
it only fails when files matching the project's `when_modified` patterns have changed. This is especially useful in
monorepos where unrelated changes to other projects should not block your applies.

If no `when_modified` patterns are configured (e.g. auto-discovered projects), `undiverged` falls back to checking all files.
Targeted `undiverged` checks also follow Atlantis project selection for:

* repo-configured projects affected through [module autoplanning](server-configuration.md#autoplan-modules)
* auto-discovered projects selected by the default `autoplan-file-list` rules

If Atlantis cannot determine project impact for a repository, `undiverged` falls back to checking all files.

**Example scenario:**

Expand Down
29 changes: 27 additions & 2 deletions server/events/command_requirement_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ type CommandRequirementHandler interface {
ValidateImportProject(repoDir string, ctx command.ProjectContext) (string, error)
}

type UndivergedProjectImpactResolver interface {
HasUndivergedImpact(ctx command.ProjectContext, repoDir string, workingDir WorkingDir) (handled bool, impacted bool, err error)
}

type DefaultCommandRequirementHandler struct {
WorkingDir WorkingDir
WorkingDir WorkingDir
ProjectImpactResolver UndivergedProjectImpactResolver
}

func (a *DefaultCommandRequirementHandler) ValidateProjectDependencies(ctx command.ProjectContext) (failure string, err error) {
Expand Down Expand Up @@ -72,11 +77,31 @@ func (a *DefaultCommandRequirementHandler) validateCommandRequirement(repoDir st
return fmt.Sprintf("Pull request must be mergeable before running %s%s.", cmd, suffix), nil
}
case raw.UnDivergedRequirement:
if a.WorkingDir.HasDiverged(ctx.Log, repoDir, ctx.RepoRelDir, ctx.AutoplanWhenModified, ctx.Pull) {
diverged, err := a.hasUndivergedImpact(repoDir, ctx)
if err != nil {
ctx.Log.Warn("evaluating undiverged requirement has failed, falling back to full divergence check: %s", err)
diverged = a.WorkingDir.HasDiverged(ctx.Log, repoDir, ctx.RepoRelDir, nil, ctx.Pull)
}
if diverged {
return fmt.Sprintf("Default branch must be rebased onto pull request before running %s.", cmd), nil
}
}
}
// Passed all requirements configured.
return "", nil
}

func (a *DefaultCommandRequirementHandler) hasUndivergedImpact(repoDir string, ctx command.ProjectContext) (bool, error) {
if a.ProjectImpactResolver == nil {
return a.WorkingDir.HasDiverged(ctx.Log, repoDir, ctx.RepoRelDir, ctx.AutoplanWhenModified, ctx.Pull), nil
}

handled, impacted, err := a.ProjectImpactResolver.HasUndivergedImpact(ctx, repoDir, a.WorkingDir)
if err != nil {
return false, err
}
if !handled {
return a.WorkingDir.HasDiverged(ctx.Log, repoDir, ctx.RepoRelDir, ctx.AutoplanWhenModified, ctx.Pull), nil
}
return impacted, nil
}
60 changes: 60 additions & 0 deletions server/events/mock_workingdir_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions server/events/mocks/mock_working_dir.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading