Skip to content

feat: extend autodiscover.ignore_paths to targeted -d commands#6466

Open
emanuelbesliu wants to merge 16 commits into
runatlantis:mainfrom
emanuelbesliu:feat/ignore-paths-targeted-commands
Open

feat: extend autodiscover.ignore_paths to targeted -d commands#6466
emanuelbesliu wants to merge 16 commits into
runatlantis:mainfrom
emanuelbesliu:feat/ignore-paths-targeted-commands

Conversation

@emanuelbesliu

Copy link
Copy Markdown

Summary

Extends autodiscover.ignore_paths to also filter targeted commands (atlantis plan -d <path>, atlantis apply -d <path>) when the path has no explicit project configuration.

Fixes #6460

Problem

In multi-instance setups where each Atlantis instance manages a different directory subtree (e.g., environments/prod/ vs environments/nonprod/), autodiscover.ignore_paths correctly prevents auto-discovery of projects in ignored paths. However, when a user runs a targeted command like atlantis apply -d environments/prod/test, both instances would react because the targeted command path bypassed ignore_paths filtering.

Solution

Added isAutoDiscoverPathIgnored checks in buildProjectPlanCommand and buildProjectCommand — the two functions that handle targeted -d commands. The check:

  1. Parses the repo config to determine if the targeted path has an explicit project entry
  2. If it does → allows the command (explicit config takes precedence)
  3. If it doesn't → checks ignore_paths and silently skips if matched

This mirrors the existing semantics in getMergedProjectCfgs and buildAllProjectCommandsByPlan, where ignore_paths only filters auto-discovered (non-configured) paths.

Why not in buildProjectCommandCtx?

The check is intentionally placed in the caller functions rather than the shared buildProjectCommandCtx because the latter is also called from buildAllProjectCommandsByPlan which has its own filtering logic that preserves explicitly-planned paths tracked in PullStatus. Putting the check there would break that behavior.

Tests

  • TestDefaultProjectCommandBuilder_BuildTargetedCommand_IgnorePaths — global config ignore_paths blocks targeted plan/apply
  • TestDefaultProjectCommandBuilder_BuildTargetedCommand_IgnorePathsRepoCfg — repo-level ignore_paths blocks targeted commands
  • TestDefaultProjectCommandBuilder_BuildTargetedCommand_IgnorePathsExplicitProjectAllowed — explicit project config overrides ignore_paths

Docs

Updated repo-level-atlantis-yaml.md and server-side-repo-config.md to document the broader scope of ignore_paths.

Copilot AI review requested due to automatic review settings May 12, 2026 08:49
@dosubot dosubot Bot added docs Documentation feature New functionality/enhancement go Pull requests that update Go code labels May 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends autodiscover.ignore_paths behavior so targeted -d plan/apply commands are ignored when the target dir has no explicit project configuration, helping multi-instance Atlantis deployments avoid reacting to out-of-scope paths.

Changes:

  • Added ignore_paths filtering for targeted plan -d and other targeted commands when there is no explicit project config for the target dir.
  • Added unit tests covering global and repo-level ignore_paths behavior and the “explicit project overrides ignore_paths” case.
  • Updated documentation to clarify that ignore_paths also applies to targeted -d commands when the path is not explicitly configured.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
server/events/project_command_builder.go Applies ignore_paths filtering to targeted command builders (plan + non-plan targeted commands).
server/events/project_command_builder_test.go Adds tests for targeted command behavior with global/repo-level ignore_paths and explicit-project override.
runatlantis.io/docs/server-side-repo-config.md Documents that ignore_paths also affects targeted -d commands when no explicit project config exists.
runatlantis.io/docs/repo-level-atlantis-yaml.md Expands ignore_paths docs to include targeted plan/apply -d semantics and multi-instance motivation.

Comment thread server/events/project_command_builder.go Outdated
Comment thread server/events/project_command_builder.go Outdated
Comment thread server/events/project_command_builder_test.go
emanuelbesliu added a commit to emanuelbesliu/atlantis that referenced this pull request May 12, 2026
…DiscoverModeEnabled

Address Copilot review feedback on PR runatlantis#6466:
- Extract duplicated ignore_paths logic into shouldIgnoreTargetedDir()
- Gate the check behind autoDiscoverModeEnabled() for consistency
- Add targeted apply -d assertions to repo-level config test

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
@emanuelbesliu emanuelbesliu requested a review from Copilot May 12, 2026 09:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread server/events/project_command_builder.go
Comment thread server/events/project_command_builder.go Outdated
Comment thread server/events/project_command_builder.go
Comment thread server/events/project_command_builder_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread server/events/project_command_builder.go Outdated
Comment thread runatlantis.io/docs/repo-level-atlantis-yaml.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread server/events/project_command_builder.go
Comment thread runatlantis.io/docs/repo-level-atlantis-yaml.md Outdated
Comment thread runatlantis.io/docs/server-side-repo-config.md Outdated
@emanuelbesliu emanuelbesliu requested a review from Copilot May 28, 2026 19:20
@gonzaloserrano

Copy link
Copy Markdown

Hey, this would help me a ton to reduce unwanted noise in atlantis-related PRs. Any chance to merge this?

@chenrui333

Copy link
Copy Markdown
Member

checking on this

@emanuelbesliu

Copy link
Copy Markdown
Author

Thank you everyone making this happen!

chenrui333 pushed a commit to emanuelbesliu/atlantis that referenced this pull request Jun 26, 2026
…DiscoverModeEnabled

Address Copilot review feedback on PR runatlantis#6466:
- Extract duplicated ignore_paths logic into shouldIgnoreTargetedDir()
- Gate the check behind autoDiscoverModeEnabled() for consistency
- Add targeted apply -d assertions to repo-level config test

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
@chenrui333 chenrui333 force-pushed the feat/ignore-paths-targeted-commands branch from ddc7409 to e467aee Compare June 26, 2026 05:48
@chenrui333

Copy link
Copy Markdown
Member

a bit late for me, I will continue checking tomorrow

emanuelbesliu and others added 15 commits June 26, 2026 12:48
Previously, autodiscover.ignore_paths only filtered projects during
auto-discovery (plan-all) and apply-all. Targeted commands like
'atlantis plan -d <path>' and 'atlantis apply -d <path>' bypassed
this filtering entirely, causing issues in multi-instance setups
where each Atlantis instance manages a different directory subtree.

This change adds ignore_paths checking to buildProjectPlanCommand and
buildProjectCommand (the targeted command handlers). When a user runs
a targeted command against a path that matches ignore_paths and has no
explicit project configuration in atlantis.yaml, the command is silently
skipped (returns no projects).

Paths with explicit project config are NOT affected — the ignore only
applies to paths that would otherwise be auto-discovered.

Fixes runatlantis#6460

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
…DiscoverModeEnabled

Address Copilot review feedback on PR runatlantis#6466:
- Extract duplicated ignore_paths logic into shouldIgnoreTargetedDir()
- Gate the check behind autoDiscoverModeEnabled() for consistency
- Add targeted apply -d assertions to repo-level config test

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
- Skip ignore_paths check when -d uses glob patterns
- Fix doc comment to reference repo config file generically
- Add apply assertions to ExplicitProjectAllowed test

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Update docs to reflect that ignore_paths filtering covers all targeted
-d commands (plan, apply, import, state rm, etc.), not just plan/apply.

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Signed-off-by: Emanuel Besliu <32497562+emanuelbesliu@users.noreply.github.com>
Run the autodiscover.ignore_paths guard before restrict-file-list validation for targeted plan -d commands so ignored directories remain no-op even when they are not in the modified file list.

Add regression coverage that verifies the ignored targeted dir returns no project contexts without calling the modified-file lookup.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Return a sentinel when targeted -d commands match autodiscover.ignore_paths so comment runners can distinguish ignored targets from ordinary zero-project results.

Skip comments, combined status updates, and post-workflow hooks for ignored targeted plan/apply commands, and let API request parsing skip those targets instead of failing.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Set the plan status to failed when autoplan stops on a pre-workflow hook error now that pending status is no longer set before command construction.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Classify ignored targeted dirs before plan review dismissal and apply lock handling, and make all targeted command runners treat the sentinel as a true skipped command.

Keep API command and hook lists aligned when ignored paths are dropped.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Classify ignored targeted dirs before comment pre-workflow hooks and before non-plan builders require an existing workspace.

Preserve skipped API requests as no-ops when every requested path is ignored.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Classify ignored targeted directory commands before comment validations that can publish user, var-file, fork, or closed-PR errors.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Autoplan uses the plan command runner for execution, so pre-workflow hook skip checks must look up the registered plan runner instead of the synthetic autoplan command.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Avoid API PR lock cleanup for all-ignored requests, let pre-workflow hooks generate explicit config before the final ignored-target skip, and keep expected ignored-target sentinels out of builder error metrics.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
Run normal command validations before pre-workflow hooks even for initially ignored targeted directories, while keeping ignored-target validation failures silent.

Prefer generated local repo config for the post-hook ignored-target recheck so explicit projects added by hooks are honored.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
@chenrui333 chenrui333 force-pushed the feat/ignore-paths-targeted-commands branch from 43c4985 to f61f28c Compare June 26, 2026 16:56
Use the local merged checkout config for targeted ignore checks when checkout-strategy=merge is enabled. If no merged checkout exists yet, fail open so commands can clone and evaluate the merged config instead of silently skipping from head-branch config.

Assisted-by: OpenAI <noreply@openai.com>
Signed-off-by: Rui Chen <rui@chenrui.dev>
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 provider/github

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autodiscover.ignore_paths should filter targeted -d commands, not just autodiscovery

4 participants