Skip to content

fix(events): make undiverged honor module autoplanning (#1)#6428

Open
krewenki wants to merge 1 commit intorunatlantis:mainfrom
krewenki:main
Open

fix(events): make undiverged honor module autoplanning (#1)#6428
krewenki wants to merge 1 commit intorunatlantis:mainfrom
krewenki:main

Conversation

@krewenki
Copy link
Copy Markdown

what

  • Make targeted undiverged checks use Atlantis project-impact resolution instead of only matching base branch changes against raw autoplan.when_modified patterns.
  • Reuse the existing configured-project and autodiscovery logic so default branch divergence is evaluated the same way Atlantis decides whether a project is impacted.
  • Add the WorkingDir.GetDivergedFiles() path needed to map base branch changes to impacted projects.
  • Update the undiverged docs and add focused coverage around module and autodiscovery cases.

why

  • The old targeted undiverged behavior could miss relevant base branch changes when a project was impacted through module autoplanning rather than a direct file match.
  • That made the undiverged gate less accurate than Atlantis's own project selection logic, which is not a great split.
  • This change keeps the gate aligned with the rest of Atlantis instead of reimplementing a simpler matcher in a separate path.
  • If project-impact resolution cannot determine the answer, it falls back to a full divergence check so the behavior stays conservative.

tests

  • I added unit coverage for configured-project module changes, autodiscovered project impacts, unrelated changes, and resolver-error fallback behavior.
  • I ran GOCACHE=/tmp/go-build go test ./server/events/...
  • I verified the server package still compiles with GOCACHE=/tmp/go-build go test ./server -run '^$'

references

  • No linked issue.
  • Docs updated in this PR: runatlantis.io/docs/command-requirements.md

* fix: make undiverged honor module autoplanning

Teach targeted undiverged checks to reuse Atlantis autoplanning impact resolution, including module dependencies and autodiscovered projects.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Warren Krewenki <19960+krewenki@users.noreply.github.com>

* chore(events): clarify diverged file logging

Signed-off-by: Warren Krewenki <19960+krewenki@users.noreply.github.com>

* fix(events): address PR review feedback\n\nSigned-off-by: Warren Krewenki <19960+krewenki@users.noreply.github.com>

* fix(events): fall back to full undiverged check on resolver errors\n\nSigned-off-by: Warren Krewenki <19960+krewenki@users.noreply.github.com>

---------

Signed-off-by: Warren Krewenki <19960+krewenki@users.noreply.github.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
Copilot AI review requested due to automatic review settings April 24, 2026 17:54
@dosubot dosubot Bot added feature New functionality/enhancement go Pull requests that update Go code labels Apr 24, 2026
@github-actions github-actions Bot added the docs Documentation label Apr 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns targeted undiverged command requirement behavior with Atlantis’s project selection logic so that default-branch divergence is evaluated based on actual project impact (including module autoplanning and autodiscovery), rather than only raw when_modified glob matching.

Changes:

  • Introduces an UndivergedProjectImpactResolver and wires it into DefaultCommandRequirementHandler for targeted undiverged checks.
  • Extends WorkingDir with GetDivergedFiles() and refactors targeted divergence checks to reuse that logic.
  • Adds focused unit tests for configured-project module impacts, autodiscovery impacts, unrelated changes, and resolver-error fallback; updates docs accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/server.go Reuses a shared DefaultProjectFinder and wires the new impact resolver into the command requirement handler.
server/events/working_dir.go Adds GetDivergedFiles() to WorkingDir and refactors targeted divergence checks to use shared diverged-file lookup.
server/events/command_requirement_handler.go Adds resolver hook for targeted undiverged, with conservative fallback to full divergence check on errors.
server/events/undiverged_project_impact.go Implements impact resolution mirroring Atlantis project selection (configured + autodiscovery + module autoplanning).
server/events/undiverged_project_impact_test.go Adds unit coverage for module/autodiscovery impact scenarios and fallback behavior.
server/events/mocks/mock_working_dir.go Updates generated mock to include GetDivergedFiles().
server/events/mock_workingdir_test.go Updates generated in-package mock to include GetDivergedFiles().
runatlantis.io/docs/command-requirements.md Documents updated targeted undiverged behavior and conservative fallback semantics.

Comment on lines +70 to +80
divergedFiles, err := workingDir.GetDivergedFiles(ctx.Log, repoDir, ctx.Pull)
if err != nil {
return true, false, err
}

impacted, err = r.impactedByModifiedFiles(ctx, repoDir, target, divergedFiles)
if err != nil {
return true, false, err
}

return true, impacted, nil
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasUndivergedImpact always calls impactedByModifiedFiles (which runs FindModuleProjects) even when GetDivergedFiles returns no changed files. This adds unnecessary module-scanning overhead on every command when the base branch hasn’t diverged (and also when CheckoutMerge is disabled and GetDivergedFiles returns nil). Consider early-returning handled=true, impacted=false when len(divergedFiles)==0 to avoid the extra work.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation feature New functionality/enhancement go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants