Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(agent/agentcontainers): respect ignore files#19016

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
DanielleMaywood merged 13 commits intomainfromdanielle/respect-ignore-files
Jul 24, 2025

Conversation

DanielleMaywood
Copy link
Contributor

@DanielleMaywoodDanielleMaywood commentedJul 23, 2025
edited
Loading

Closes#19011

We now usego-git'sgitignore plumbing implementation to parse the.gitignore files and match against the patterns generated. We use this to ignore any ignored files in the git repository.

Unfortunately I've had to slightly re-implement some of the interface exposed bygo-git because they usebilly.Filesystem instead ofafero.Fs.

@DanielleMaywoodDanielleMaywood marked this pull request as ready for reviewJuly 23, 2025 18:11
Copy link
Contributor

@CopilotCopilotAI 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

This PR implements respect for.gitignore files when discovering devcontainer configurations. The change ensures that files and directories specified in.gitignore patterns are excluded from devcontainer discovery, preventing ignored directories from being processed.

  • Adds gitignore pattern parsing and matching using the go-git library
  • Creates a new ignore package to handle gitignore pattern processing with afero filesystem compatibility
  • Updates devcontainer discovery logic to skip ignored files and directories

Reviewed Changes

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

Show a summary per file
FileDescription
go.modAdds go-git dependency and updates gliderlabs/ssh version
agent/agentcontainers/ignore/dir.goNew module for parsing gitignore patterns and converting file paths to components
agent/agentcontainers/ignore/dir_test.goUnit tests for the FilePathToParts function
agent/agentcontainers/api.goIntegrates gitignore pattern matching into devcontainer discovery
agent/agentcontainers/api_test.goTest cases verifying gitignore functionality

@DanielleMaywoodDanielleMaywoodforce-pushed thedanielle/respect-ignore-files branch froma913cf8 tof5d16eaCompareJuly 23, 2025 18:45
@DanielleMaywood
Copy link
ContributorAuthor

@coderabbitai review

coderabbitai[bot] reacted with eyes emoji

@coderabbitaicoderabbitai
Copy link

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitaicoderabbitai
Copy link

📝 Walkthrough

Walkthrough

The changes introduce.gitignore-aware devcontainer discovery by enhancing thediscoverDevcontainersInProject method to parse and respect ignore patterns during directory traversal. A newignore package is added to handle pattern parsing and matching. Corresponding tests verify correct exclusion of ignored paths, and dependencies forgo-git are added.

Changes

File(s)Change Summary
agent/agentcontainers/api.goEnhanced devcontainer discovery to use.gitignore patterns, skipping ignored files and directories during traversal.
agent/agentcontainers/api_test.goAdded test cases verifying that devcontainer discovery respects.gitignore and nested.gitignore files.
agent/agentcontainers/ignore/dir.goIntroduced new package for reading, parsing, and accumulating.gitignore patterns from a directory tree.
agent/agentcontainers/ignore/dir_test.goAdded unit tests for theFilePathToParts function in the newignore package.
go.modAddedgo-git and related dependencies to support.gitignore parsing. Updatedgliderlabs/ssh version.

Sequence Diagram(s)

sequenceDiagram    participant User    participant API (discoverDevcontainersInProject)    participant IgnorePkg    participant Filesystem    User->>API (discoverDevcontainersInProject): Request devcontainer discovery    API->>IgnorePkg: Read and parse .gitignore patterns    IgnorePkg->>Filesystem: Read .gitignore files recursively    IgnorePkg-->>API: Return ignore patterns    loop Walk project directory        API->>Filesystem: Read directory entry        API->>IgnorePkg: Check if path matches ignore pattern        alt Path is ignored            API-->>Filesystem: Skip directory or file        else Path is not ignored            API->>Filesystem: Check for devcontainer            alt Devcontainer found                API-->>User: Report devcontainer            end        end    end    API-->>User: Return discovered devcontainers
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested reviewers

  • mafredri
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • 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 oursupport 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 togenerate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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.

Documentation and Community

  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

Copy link

@coderabbitaicoderabbitaibot 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: 1

♻️ Duplicate comments (2)
agent/agentcontainers/ignore/dir.go (2)

21-21:Usestrings.Split for better Go version compatibility.

Thestrings.SplitSeq function was introduced in Go 1.23 and may not be available in older Go versions. Consider using the standardstrings.Split for better compatibility.

-for segment := range strings.SplitSeq(filepath.Clean(path), string(filepath.Separator)) {+for _, segment := range strings.Split(filepath.Clean(path), string(filepath.Separator)) {

38-38:Usestrings.Split for better Go version compatibility.

Thestrings.SplitSeq function was introduced in Go 1.23 and may not be available in older Go versions. Consider using the standardstrings.Split for better compatibility.

-for s := range strings.SplitSeq(string(data), "\n") {+for _, s := range strings.Split(string(data), "\n") {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between28789d7 andf5d16ea.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by!**/*.sum
📒 Files selected for processing (5)
  • agent/agentcontainers/api.go (2 hunks)
  • agent/agentcontainers/api_test.go (1 hunks)
  • agent/agentcontainers/ignore/dir.go (1 hunks)
  • agent/agentcontainers/ignore/dir_test.go (1 hunks)
  • go.mod (4 hunks)
🧰 Additional context used
🧠 Learnings (5)
agent/agentcontainers/api.go (4)

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*.go : Coder emphasizes clear error handling, with specific patterns required: Concise error messages that avoid phrases like "failed to"; Wrapping errors with%w to maintain error chains; Using sentinel errors with the "err" prefix (e.g.,errNotFound).

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : Follow Uber Go Style Guide

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*.go : The codebase is rigorously linted with golangci-lint to maintain consistent code quality.

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Never use hardcoded names in concurrent Go tests

agent/agentcontainers/ignore/dir_test.go (5)

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Never use hardcoded names in concurrent Go tests

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Use unique identifiers in concurrent Go tests to prevent race conditions (e.g., fmt.Sprintf with t.Name() and time.Now().UnixNano())

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*_test.go : All tests should run in parallel usingt.Parallel() to ensure efficient testing and expose potential race conditions.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*_test.go : All tests must uset.Parallel() to run concurrently, which improves test suite performance and helps identify race conditions.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to coderd/coderdtest/**/* : Thecoderdtest package incoderd/coderdtest/ provides utilities for creating test instances of the Coder server, setting up test users and workspaces, and mocking external components.

agent/agentcontainers/api_test.go (2)

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Never use hardcoded names in concurrent Go tests

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Use unique identifiers in concurrent Go tests to prevent race conditions (e.g., fmt.Sprintf with t.Name() and time.Now().UnixNano())

go.mod (4)

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*.go : The codebase is rigorously linted with golangci-lint to maintain consistent code quality.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*.go : Coder emphasizes clear error handling, with specific patterns required: Concise error messages that avoid phrases like "failed to"; Wrapping errors with%w to maintain error chains; Using sentinel errors with the "err" prefix (e.g.,errNotFound).

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : Follow Uber Go Style Guide

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : OAuth2-compliant error responses must use writeOAuth2Error in Go code

agent/agentcontainers/ignore/dir.go (2)

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : Follow Uber Go Style Guide

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*.go : Coder emphasizes clear error handling, with specific patterns required: Concise error messages that avoid phrases like "failed to"; Wrapping errors with%w to maintain error chains; Using sentinel errors with the "err" prefix (e.g.,errNotFound).

🔇 Additional comments (15)
go.mod (1)

487-487:✅ Approve go-git v5.16.2 – latest stable release with no known vulnerabilities

  • go.mod (line 487): addedgithub.com/go-git/go-git/v5 v5.16.2, which is the most recent tag (2025-06-09).
  • GitHub vulnerability alerts for go-git/go-git returned zero advisories.

This change cleanly supports the gitignore parsing functionality as intended.

agent/agentcontainers/api.go (6)

24-24:LGTM: Appropriate gitignore import for pattern matching.

The import ofgithub.com/go-git/go-git/v5/plumbing/format/gitignore correctly provides the gitignore pattern matching functionality described in the PR objectives.


30-30:LGTM: Internal ignore package import.

The import of the new internalignore package is correctly added to support the gitignore functionality.


474-479:LGTM: Well-structured gitignore pattern reading and matcher setup.

The implementation correctly separates pattern reading from matching, with proper error handling usingxerrors.Errorf with%w for error chain preservation.


487-487:LGTM: Proper path conversion for gitignore matching.

Converting file paths to parts usingignore.FilePathToParts is the correct approach for gitignore pattern matching, ensuring proper path normalization.


489-498:LGTM: Efficient directory skipping with gitignore support.

The implementation correctly usesfs.SkipDir to skip ignored directories entirely, which is both performant and follows Go file walking conventions. The logic properly handles directory traversal while respecting gitignore patterns.


500-502:LGTM: Complete file filtering with gitignore support.

The file filtering logic correctly usesmatcher.Match(pathParts, false) to identify ignored files and skip them, completing the gitignore integration for both directories and files.

agent/agentcontainers/ignore/dir_test.go (3)

1-10:LGTM: Proper test package structure and imports.

Using the external test packageignore_test is good practice for testing public APIs. The imports are minimal and appropriate, usingtestify/require which is consistent with the codebase patterns.


12-13:LGTM: Proper test structure with parallel execution.

The test function correctly usest.Parallel() as required by the coding guidelines, which improves test suite performance and helps identify race conditions.


15-47:LGTM: Comprehensive table-driven test with excellent coverage.

The test implementation excellently covers various path scenarios including:

  • Absolute and relative paths
  • Edge cases (empty, root paths)
  • Path normalization (removing.,.., multiple slashes)
  • Trailing slashes

The table-driven approach with parallel subtests follows Go best practices, and the test naming usingfmt.Sprintf creates unique identifiers as recommended for concurrent tests.

agent/agentcontainers/api_test.go (3)

3365-3387:LGTM! Excellent test coverage for nested gitignore functionality.

This test case properly validates that nested.gitignore files are respected during devcontainer discovery, ensuring that ignored paths are excluded while non-ignored paths are still discovered.


3348-3387:Well-implemented test cases for gitignore functionality.

These two test cases provide excellent coverage for the new gitignore-aware devcontainer discovery feature. They test both root-level and nested.gitignore files, ensuring that ignored paths are properly excluded during filesystem traversal.

The test structure follows the existing pattern and integrates well with theTestDevcontainerDiscovery test suite.


3348-3364:No change needed for devcontainer config file path format. The code intentionally supports both “.devcontainer/devcontainer.json” and “.devcontainer.json” (seedevcontainerConfigPaths in agent/agentcontainers/api.go), so the test’s use of “.devcontainer.json” is valid and exercises that alternate lookup.

agent/agentcontainers/ignore/dir.go (2)

47-68:LGTM! Well-structured recursive pattern collection.

The function correctly walks the filesystem to collect gitignore patterns from all directories. The error handling properly propagates errors, the logic is sound, and it integrates well with the afero filesystem abstraction.


1-12:LGTM! Clean package structure and appropriate dependencies.

The package is well-structured with appropriate imports. The integration ofgo-git for gitignore pattern parsing withafero filesystem abstraction aligns perfectly with the PR objectives.

github.com/fullsailor/pkcs7v0.0.0-20190404230743-d7302db945fa
github.com/gen2brain/beeepv0.11.1
github.com/gliderlabs/sshv0.3.4
github.com/gliderlabs/sshv0.3.8
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this is a result of addinggo-git as a dependency.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It happened when I addedgo-git, yeah, unfortunate as it feels unrelated.

Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

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

Awesome!

@DanielleMaywoodDanielleMaywood merged commit25d70ce intomainJul 24, 2025
26 checks passed
@DanielleMaywoodDanielleMaywood deleted the danielle/respect-ignore-files branchJuly 24, 2025 11:12
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 24, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Copilot code reviewCopilotCopilot left review comments

@mtojekmtojekmtojek approved these changes

@mafredrimafredriAwaiting requested review from mafredri

+1 more reviewer

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

Reviewers whose approvals may not affect merge requirements
Assignees

@DanielleMaywoodDanielleMaywood

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

bug: dev container project discovery looks in dependencies
3 participants
@DanielleMaywood@johnstcn@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp