Skip to content

feat/drift filter block name #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented Jun 25, 2025

  • support additiona parsing arguments
  • propagate projectName to projects
  • filter out block names

Summary by CodeRabbit

  • New Features
    • Added support for filtering drift detection by block name using an environment variable.
    • Projects and configuration files now include a block name field for improved traceability.
  • Enhancements
    • Configuration files support new optional fields for more flexible project and block definitions.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Walkthrough

The changes introduce a new BlockName field to project and YAML configuration structures, propagate this field during configuration generation, and implement filtering of projects by block name in the GitHub CI drift detection logic. The updates enhance traceability and enable selective drift detection execution based on block filters.

Changes

File(s) Change Summary
cli/pkg/github/github.go Added logic to filter drift detection projects by block name using an environment variable.
libs/digger_config/config.go Added BlockName string field to the Project struct.
libs/digger_config/converters.go Updated copyProjects to initialize the new BlockName field in Project struct copies.
libs/digger_config/digger_config.go Modified hydrateDiggerConfigYamlWithTerragrunt to accept and propagate a blockName parameter.
libs/digger_config/yaml.go Added BlockName to ProjectYaml and TerragruntParsingConfig to BlockYaml; reformatted fields.

Sequence Diagram(s)

sequenceDiagram
    participant GitHubCI
    participant Env
    participant ProjectList

    GitHubCI->>Env: Read INPUT_DIGGER_BLOCK_FILTERS
    Env-->>GitHubCI: Return comma-separated block filters
    GitHubCI->>ProjectList: For each project in drift detection mode
    alt Filters specified
        GitHubCI->>ProjectList: Check if project's BlockName in filters
        alt BlockName not in filters
            GitHubCI-->>ProjectList: Skip project
        else BlockName in filters
            GitHubCI->>ProjectList: Process project for drift detection
        end
    else No filters
        GitHubCI->>ProjectList: Process all projects for drift detection
    end
Loading

Poem

In fields of config, blocks now have a name,
Drift detection listens, no two are the same.
Filters in the wind, a rabbit hops by,
"BlockName!" it cheers, with a twinkle in its eye.
Traceable trails, selective and neat—
These changes make drift detection sweet!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feat/drift-filter-block-name

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Implements block name filtering functionality for Terragrunt projects, allowing more granular control over drift detection and project configuration.

  • Added BlockName field to Project and ProjectYaml structs in libs/digger_config/config.go and yaml.go for block-level identification
  • Introduced INPUT_DIGGER_BLOCK_FILTERS environment variable in cli/pkg/github/github.go for filtering drift detection by specific block names
  • Enhanced hydrateDiggerConfigYamlWithTerragrunt function in libs/digger_config/digger_config.go to support block name propagation
  • Potential issue: Duplicate 'workspace' field assignment in libs/digger_config/converters.go needs review

5 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +185 to +186
blockFiltersStr := os.Getenv("INPUT_DIGGER_BLOCK_FILTERS")
blockFilters := strings.Split(blockFiltersStr, ",")
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider validating blockFiltersStr is not empty before splitting. Empty string will result in a slice with one empty string element.

Comment on lines +191 to +199
if len(blockFilters) > 0 {
projectInBlock := false
if lo.Contains(blockFilters, projectConfig.BlockName) {
projectInBlock = true
}
if !projectInBlock {
continue
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: This block can be simplified using lo.Contains(blockFilters, projectConfig.BlockName). No need for extra boolean variable.

Suggested change
if len(blockFilters) > 0 {
projectInBlock := false
if lo.Contains(blockFilters, projectConfig.BlockName) {
projectInBlock = true
}
if !projectInBlock {
continue
}
}
if len(blockFilters) > 0 && !lo.Contains(blockFilters, projectConfig.BlockName) {
continue
}

Copy link

delve-auditor bot commented Jun 25, 2025

No security or compliance issues detected. Reviewed everything up to 6e37c91.

Security Overview
  • 🔎 Scanned files: 5 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► github/github.go
    Add block filtering functionality
► digger_config/config.go
    Add BlockName field to Project struct
► digger_config/digger_config.go
    Update project generation with block name support
► digger_config/yaml.go
    Add BlockName and TerragruntParsingConfig fields to structs

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cli/pkg/github/github.go (1)

185-199: Consider handling empty filter case more explicitly.

The filtering logic is well-implemented, but there's a potential edge case: when INPUT_DIGGER_BLOCK_FILTERS is empty, strings.Split will return [""] instead of an empty slice, which could cause unintended filtering behavior.

Consider this improvement:

 blockFiltersStr := os.Getenv("INPUT_DIGGER_BLOCK_FILTERS")
-blockFilters := strings.Split(blockFiltersStr, ",")
+var blockFilters []string
+if blockFiltersStr != "" {
+    blockFilters = strings.Split(blockFiltersStr, ",")
+}
 for _, projectConfig := range diggerConfig.Projects {
     if !projectConfig.DriftDetection {
         continue
     }
-    if len(blockFilters) > 0 {
+    if len(blockFilters) > 0 && blockFiltersStr != "" {
         projectInBlock := false
         if lo.Contains(blockFilters, projectConfig.BlockName) {
             projectInBlock = true
         }
         if !projectInBlock {
             continue
         }
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2dec859 and 6e37c91.

📒 Files selected for processing (5)
  • cli/pkg/github/github.go (2 hunks)
  • libs/digger_config/config.go (1 hunks)
  • libs/digger_config/converters.go (1 hunks)
  • libs/digger_config/digger_config.go (5 hunks)
  • libs/digger_config/yaml.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (78)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: build-and-push-image
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: Build
  • GitHub Check: binary
  • GitHub Check: build-and-push-image
  • GitHub Check: Build
  • GitHub Check: build-and-push-image
  • GitHub Check: binary
  • GitHub Check: Build
  • GitHub Check: build-and-push-image
  • GitHub Check: binary
  • GitHub Check: build-and-push-image
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Security Check
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (10)
libs/digger_config/config.go (1)

45-45: LGTM! Clean addition of BlockName field.

The addition of the BlockName field to the Project struct is well-documented and appropriately placed. The comment clearly indicates its purpose for generated projects.

libs/digger_config/converters.go (1)

72-90: LGTM! Proper struct field initialization.

The Project struct initialization correctly includes the new BlockName field in the proper position, maintaining consistency with the struct definition and properly copying the value from the source ProjectYaml.

cli/pkg/github/github.go (1)

22-22: LGTM! Appropriate library import.

The addition of the lo import is appropriate for the filtering functionality being implemented.

libs/digger_config/yaml.go (2)

38-38: LGTM! Proper YAML field addition.

The BlockName field is correctly added to the ProjectYaml struct with the appropriate YAML tag block_name.


112-114: LGTM! Clean struct field additions and formatting.

The formatting improvements and addition of the TerragruntParsingConfig field are well-implemented and consistent with the overall changes.

libs/digger_config/digger_config.go (5)

702-702: LGTM! Function signature enhancement.

The addition of the blockName parameter to hydrateDiggerConfigYamlWithTerragrunt is well-designed and enables proper block name propagation during project generation.


332-332: LGTM! Consistent function call update.

The function call correctly passes an empty string for the blockName parameter when using deprecated top-level terragrunt configuration.


341-341: LGTM! Consistent function call update.

The function call correctly passes an empty string for the blockName parameter for the deprecated terragrunt configuration path.


412-423: LGTM! Proper terragrunt parsing configuration.

The terragrunt parsing configuration initialization and override logic is well-implemented. The code properly handles the case where no parsing config exists and appropriately sets the necessary fields for project generation.


809-809: LGTM! Correct BlockName assignment.

The BlockName field is properly assigned during project creation, ensuring the block name is propagated to generated projects for later filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant