Skip to content

Add configurable ecosystem allow/deny filters - #262

Merged
andrew merged 7 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/exclude-ecosystems-256
Jul 20, 2026
Merged

andrew merged 7 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/exclude-ecosystems-256

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #256

Summary

Adds repository-level ecosystem filtering through git config:

  • pkgs.ecosystems acts as an allow-list
  • pkgs.ignoredEcosystems acts as a deny-list
  • deny-list entries take precedence when both are configured

The filter is applied during indexing so excluded ecosystems are not written to dependency changes/snapshots, and command-time dependency loading also filters existing database results.

Changes

  • Add ecosystem filter config loading from git config
  • Apply filters in init, reindex, on-demand snapshots, working-tree diff, where, show and dependency query paths
  • Document allow-list and deny-list behavior
  • Add tests for config parsing and ignored ecosystem indexing behavior

Testing

go test ./...
go tool golangci-lint run ./...

@andrew andrew 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.

Thanks for the implementation. I think this needs another pass before merge because several user-facing direct DB query paths bypass the new repository ecosystem filter. In particular, search opens the DB directly and calls SearchDependencies with only the explicit --ecosystem flag, so ignored ecosystems can still appear from an existing DB. urls lookupPackage has the same direct DB search path and can still select an ignored ecosystem for URL generation. vulns sync reads GetLatestDependencies directly and only applies the explicit --ecosystem filter, so ignored ecosystems can still be sent through OSV sync/network work unless the DB has already been rebuilt; related vuln helpers that call GetDependenciesAtRef directly need the same treatment. Please apply the config filter to these direct DB paths and add regression coverage for search/urls/vulns behavior with pkgs.ignoredEcosystems or pkgs.ecosystems configured.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Thanks, fixed

The direct DB paths now load the repo ecosystem config and apply it after DB reads:

  • search filters SearchDependencies results with pkgs.ecosystems / pkgs.ignoredEcosystems
  • urls plain-name lookup filters DB search results before selecting the ecosystem for URL generation
  • vulns sync filters GetLatestDependencies before resolved dependency selection and OSV sync work
  • vuln helpers that call GetDependenciesAtRef now apply the config filter before cached vulnerability matching / history analysis

I also added regression coverage for search, urls and vuln ref behavior against an existing DB where pkgs.ignoredEcosystems is configured after indexing.

Verified with:

  • go test ./...
  • go tool golangci-lint run ./...

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds repository-scoped ecosystem allow/deny filtering via git config, and wires the filter through indexing and multiple query/output paths so excluded ecosystems are neither indexed into SQLite nor shown/used by commands reading from an existing database.

Changes:

  • Introduce internal/config.EcosystemFilter loaded from pkgs.ecosystems (allow-list) and pkgs.ignoredEcosystems (deny-list, takes precedence).
  • Apply ecosystem filtering during indexing (analyzer + incremental snapshot) and during command-time DB result loading (search, urls, tree, show, vulns, where, etc.).
  • Document the new config and add tests covering parsing and filtering behavior.

Reviewed changes

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

Show a summary per file
File Description
README.md Documents allow/deny ecosystem config and rebuild guidance.
internal/indexer/indexer.go Threads ecosystem filter into indexer/analyzer and filters incremental snapshots.
internal/git/repository.go Exposes Repository.EcosystemFilter() for command/index paths.
internal/git/query.go Applies ecosystem filtering to dependency loads and on-demand snapshot indexing.
internal/config/ecosystems.go Adds config-backed ecosystem allow/deny filter implementation.
internal/config/ecosystems_test.go Tests filter semantics and config value parsing.
internal/analyzer/analyzer.go Skips analysis/indexing of manifests in filtered ecosystems.
docs/internals.md Notes ecosystem filtering behavior in internals documentation.
cmd/where.go Applies ecosystem config filter during manifest scanning.
cmd/vulns.go Filters dependencies by ecosystem config across vuln commands/paths.
cmd/vulns_test.go Adds test ensuring vuln lookup respects ecosystem config filtering.
cmd/urls.go Filters URL lookup/search results by ecosystem config.
cmd/urls_test.go Adds test ensuring ignored ecosystems are excluded from URL name lookup.
cmd/tree.go Filters tree input dependencies by ecosystem config.
cmd/show.go Filters displayed changes by ecosystem config.
cmd/search.go Filters search results by ecosystem config.
cmd/reindex.go Passes ecosystem filter into reindex indexing options.
cmd/init.go Passes ecosystem filter into init indexing options.
cmd/init_test.go Adds init test ensuring ignored ecosystems aren’t indexed.
cmd/helpers.go Adds shared helpers for filtering deps/search results by config.
cmd/diff.go Applies ecosystem filter to working-tree analysis.
cmd/analysis_test.go Adds test ensuring search hides ignored ecosystems from existing DB.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/init_test.go Resolved

@andrew andrew 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.

Thanks for the update, the search/urls/vulns paths from the earlier review are all covered now and the new regression tests look good. A few small things before this lands:

repo.EcosystemFilter() shells out to git config --get-all twice on every call and isn't cached. Every current caller hits it once per command so it's fine today, but GetDependenciesWithDB and IndexCommitSnapshot both call it and those are the sort of thing that ends up in a loop later. Could you load it once in OpenRepository (or memoise on first access) and have EcosystemFilter() return the stored value?

filterDependenciesByConfig in cmd/helpers.go and filterDependencies in internal/git/query.go do the same thing with slightly different signatures. Since config.EcosystemFilter is already shared, can the cmd helper take the filter (or query.go export its version) so there's one implementation?

git pkgs info --ecosystems still reports whatever is in the DB, so on an existing database it will list an ignored ecosystem until the user reindexes. The README already mentions info --ecosystems right next to the new config keys, so it'd be good if that command reflected the configured filter (either by filtering the DB counts or by printing the allow/deny lists alongside them).

@andrew

andrew commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This is also 6 commits behind main now (#236, #251, #257, #263, #264, #265). I checked the merge locally and it's clean with tests passing, but please rebase so CI runs against the current base. cmd/replace.go from #236 doesn't touch dependency queries so no new filter wiring is needed there.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Thanks, fixed

  • Rebased the branch onto current main.
  • Memoized repo.EcosystemFilter() on the repository with sync.Once.
  • Removed the duplicate command-side dependency filter and updated callers to use the shared git.FilterDependenciesByEcosystemConfig helper.
  • Updated info --ecosystems so existing DB ecosystem counts respect pkgs.ecosystems / pkgs.ignoredEcosystems in both text and JSON output.
  • Added regression coverage for info --ecosystems with an ignored ecosystem configured after the DB already exists.

Tests and lint are passing:

  • go test ./cmd ./internal/git ./internal/config
  • go test ./...
  • go tool golangci-lint run ./...

@abhinavgautam01
abhinavgautam01 force-pushed the feature/exclude-ecosystems-256 branch from 55dd275 to 655d487 Compare July 8, 2026 15:01

@andrew andrew 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.

Thanks for the follow-up. The three items from the previous review are resolved: filter loading is memoized, dependency filtering is shared, and info --ecosystems now respects the config on an existing database. I found two remaining correctness issues before merge:

  1. The remaining historical and aggregate database query paths still bypass the repository filter. I reproduced this by indexing npm and RubyGems, then setting pkgs.ignoredEcosystems=npm: info and search hide npm, but log, history, stats, blame, and why still return npm data from the existing database. stale and bisect candidate selection follow the same direct-query pattern and should be audited as well. For limited or aggregate queries, please apply the filter before limits and totals are calculated so ignored commits do not consume the result limit or affect statistics.

  2. The go ecosystem alias does not match the stored golang ecosystem. normalizeEcosystem only calls purl.PURLTypeToEcosystem, which leaves go unchanged; the analyzer records Go manifests as golang. With pkgs.ignoredEcosystems=go, git pkgs init still indexes the Go dependency and info --ecosystems reports golang. Please canonicalize ecosystem aliases as well as PURL types and add a regression test for this case.

I verified that go test ./... passes both at the PR head and on a clean synthetic merge with the current main.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Fixed both remaining issues.

The repository allow/deny filter is now applied in the direct historical and aggregate database paths used by log, history, stats, blame, why, stale and bisect candidate selection. These predicates are applied within the SQL queries, so ignored ecosystems do not consume log/top-N limits or affect stats counts, totals, rankings or author aggregates.

I also canonicalized the go alias to golang, matching the analyzer’s stored ecosystem name. Added regression coverage for the affected command paths, bisect candidates and pkgs.ignoredEcosystems=go.

@andrew andrew 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.

Both items from the last round are resolved.

One more of the same class: printCulprit in cmd/bisect.go:704 calls db.GetChangesForCommit(sha) and prints every change without loading repo.EcosystemFilter(), so a mixed-ecosystem culprit lists ignored-ecosystem changes under "Dependencies changed:". Run the result through filterChangesByEcosystemConfig (from cmd/show.go) before printing.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

printCulprit now loads the repository ecosystem filter and runs GetChangesForCommit results through filterChangesByEcosystemConfig before rendering the dependency-change section.

Added end-to-end coverage that configures npm as ignored and verifies the culprit output does not print ignored dependency changes.

@andrew andrew 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.

The printCulprit fix and everything from the earlier rounds looks right. One remaining correctness issue in the SQL-side filter added for round 3.

config.normalizeEcosystem maps config input through purl.PURLTypeToEcosystem, so gem and rubygems both normalise to rubygems, and composer/packagist both to packagist. filter.Values() passes those to appendEcosystemConfigFilter, which builds ecosystem IN (...) / NOT IN (...). But git-pkgs/manifests registers Gemfile as "gem" and composer.json as "composer", and that is what the analyzer writes into dependency_changes.ecosystem and dependency_snapshots.ecosystem. The SQL predicate never matches the stored value.

Reproduced on a merge with current main:

$ git config pkgs.ignoredEcosystems rubygems
$ git pkgs search rails --format json   # Allows() normalises both sides
[]
$ git pkgs log --format json            # NOT IN ('rubygems') vs stored 'gem'
[... "ecosystem": "gem", "name": "rails" ...]

The allow-list direction is worse: with pkgs.ecosystems=rubygems, log/history/stats/blame/why/stale/GetBisectCandidates return nothing for RubyGems while list and search still show it. Allows() is fine because it normalises the DB value at call time; only the SQL path is affected. TestHistoricalCommandsRespectIgnoredEcosystems uses npm, which is an identity mapping, so it does not catch this.

Suggested fix: have databaseEcosystemFilterOptions (or filter.Values()) expand each configured value to its alias set so the IN/NOT IN list covers what manifests actually stored, e.g. rubygems -> {gem, rubygems}, packagist -> {composer, packagist}, github-actions -> {github-actions, githubactions}, alpine -> {alpine, apk}, arch -> {arch, alpm}. purl.EcosystemToPURLType and purl.NormalizeEcosystem give both directions. Please add a regression that seeds a Gemfile, sets pkgs.ignoredEcosystems=rubygems, and asserts log and stats exclude it.

The branch is also 8 commits behind main (#266-#271, #273, #274). I test-merged locally and go test ./... passes on the merged tree, but please rebase along with the fix so CI runs against the current base.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/exclude-ecosystems-256 branch from 2018daa to 0475974 Compare July 15, 2026 13:59
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Thanks @andrew
Rebased onto current main and fixed the SQL-side alias mismatch.

The database filter now expands configured canonical ecosystem values to include their PURL/manifest aliases before building IN/NOT IN predicates. For example, rubygems includes gem and the same expansion covers the other canonical/PURL alias pairs.

Added a regression that indexes a Gemfile, then sets pkgs.ignoredEcosystems=rubygems against the existing database and verifies both log and stats exclude the RubyGems dependency data.

@andrew andrew 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.

The alias-expansion fix is correct: StoredValues() now expands each configured value through purl.EcosystemToPURLType/PURLTypeToEcosystem so the SQL IN/NOT IN lists cover what git-pkgs/manifests actually stores (gem, composer, githubactions, apk, alpm). TestEcosystemFilterStoredValuesIncludesPURLAliases covers all five alias pairs and TestHistoricalCommandsRespectRubyGemsEcosystemAlias covers the end-to-end log/stats regression. go test ./... and lint pass on the PR head. No further code changes needed.

The branch now conflicts with main though. #277 (merged today as 53acfbf) added seven test functions to cmd/vulns_test.go immediately after TestSyncVulnerabilitiesForDeps_QuietMode, which is where this PR inserts TestGetVulnsAtRefAppliesEcosystemConfig. cmd/vulns.go auto-merges cleanly; the cmd/vulns_test.go conflict is purely additive, so resolution is keeping both blocks. Please rebase onto current main (53acfbf) and I will approve.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/exclude-ecosystems-256 branch from 0475974 to 50af3b2 Compare July 20, 2026 12:36
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Rebased onto current main at 53acfbf. The cmd/vulns_test.go conflict was purely additive, so I retained both the #277 OSV regression tests and TestGetVulnsAtRefAppliesEcosystemConfig.

@andrew andrew 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.

Rebased onto 53acfbf; git range-diff shows no content changes beyond moving the TestGetVulnsAtRefAppliesEcosystemConfig insertion point after the #277 tests. Both test sets present, CI green, merges cleanly.

@andrew
andrew merged commit 2a373da into git-pkgs:main Jul 20, 2026
4 checks passed
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.

Exclude ecosystem from consideration by git-pkgs, optionally with persistent setting

3 participants