Skip to content

fix(ingestion): exclude vendored/generated files from authored git LOC (#1798) - #1826

Merged
cyberantonz merged 2 commits into
constructorfabric:mainfrom
cyberantonz:fix/exclude-vendored-git-loc
Jul 20, 2026
Merged

fix(ingestion): exclude vendored/generated files from authored git LOC (#1798)#1826
cyberantonz merged 2 commits into
constructorfabric:mainfrom
cyberantonz:fix/exclude-vendored-git-loc

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Closes #1798.

Problem

Git line-count metrics classify files by extension only, so machine-produced content — vendored deps (node_modules/, site-packages/, vendor/), build output (dist/, target/), and generated/minified files — is counted as authored code. A single commit adding a vendored tree inflates a person's LOC by hundreds of thousands of lines, and because peer standing is computed against a cohort median/quartiles, one such outlier skews the benchmark for everyone in the cohort.

Fix

Add a vendored category, checked first in both classifier call sites:

  • the shared git_file_category gold macro (src/ingestion/dbt/macros/git_file_category.sql), consumed by git_metric_observations
  • the inline classifier in fct_git_file_change (src/ingestion/silver/git/), consumed by mtr_git_person_*

Authored line-count metrics already filter to category = 'code' (code_lines_added, code_loc, clean_loc), so they now exclude vendored/generated files automatically. The total lines_added breakdown retains them under the vendored category, so the signal stays auditable rather than silently dropped (as the issue suggested).

Patterns are defined once — the new git_vendored_path_regex macro backed by the git_vendored_path_patterns dbt var (dbt_project.yml) — so the exclusion is applied upstream and evolvable via config without a code change.

Acceptance criteria

  • Vendored/generated files excluded from authored line-count metrics (code_lines_added / code_loc / clean_loc).
  • Exclusion patterns configurable (git_vendored_path_patterns var), not hard-coded per call site (shared git_vendored_path_regex macro).
  • Applied once upstream and reflected in every line-count metric + peer/cohort aggregation.
  • Coverage for representative vendored/generated path patterns (assert_git_file_category_vendored.sql, data-independent so it holds on a fresh cluster).

Notes

  • Escaping: var patterns are RE2 fragments embedded into a ClickHouse SQL string literal, so backslashes are doubled to match the existing hand-written regexes; verified end-to-end (YAML load → ClickHouse literal unescape → RE2) against vendored vs authored fixtures.
  • Extended the closed-taxonomy contract test (assert_git_observations_dimension_values.sql) with vendored.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added automatic classification of vendored and generated files in Git metrics.
    • Added configurable patterns covering dependencies, build outputs, generated files, and lock files.
    • Added a distinct “Vendored / Generated” category in file and line breakdowns.
  • Bug Fixes

    • Vendored content is now excluded from code-location metrics and code-line attribution.
  • Documentation

    • Updated Git metric definitions and category descriptions to explain vendored-file handling.

constructorfabric#1798)

Git line-count metrics classify files by extension only, so vendored deps
(node_modules, site-packages, vendor/), build output (dist/, target/) and
generated/minified files count as authored code — inflating per-person LOC
and skewing every peer cohort that person sits in.

Add a `vendored` category, checked first in both classifier call sites
(the shared `git_file_category` gold macro and the inline classifier in
`fct_git_file_change`). Authored line-count metrics already filter to
`category = 'code'` (`code_lines_added`, `code_loc`, `clean_loc`), so they
now drop vendored/generated files automatically. The total `lines_added`
breakdown retains them under the `vendored` category, keeping the signal
auditable rather than silently dropped.

Patterns live in one place — the new `git_vendored_path_regex` macro backed
by the `git_vendored_path_patterns` dbt var — so the exclusion is defined
once, applied upstream, and evolvable via config without a code change.

- extend the closed-taxonomy contract test with `vendored`
- add a data-independent macro fixture test covering representative
  vendored and authored paths (holds on a fresh, empty cluster)
- update schema.yml / README docs

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz requested a review from a team as a code owner July 20, 2026 04:27
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cyberantonz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 19fba990-6c81-4bd0-bb2e-96f50cfb59ff

📥 Commits

Reviewing files that changed from the base of the PR and between 7f82cf4 and 15ea04c.

📒 Files selected for processing (3)
  • src/ingestion/dbt/dbt_project.yml
  • src/ingestion/dbt/macros/git_file_category.sql
  • src/ingestion/dbt/tests/gold/assert_git_file_category_vendored.sql
📝 Walkthrough

Walkthrough

Adds configurable path-based detection for vendored/generated Git files, classifies them before existing categories, excludes them from authored code-location metrics, documents the taxonomy, and adds contract coverage.

Changes

Vendored Git metrics

Layer / File(s) Summary
Configurable vendored classification
src/ingestion/dbt/dbt_project.yml, src/ingestion/dbt/macros/git_file_category.sql
Adds configurable vendored path regex patterns, vendored-first classification, and the Vendored / Generated label.
Silver model metric integration
src/ingestion/silver/git/fct_git_file_change.sql, src/ingestion/silver/git/schema.yml, src/ingestion/silver/git/README.md
Classifies vendored paths before other categories and documents their exclusion from code-location metrics.
Classification and dimension validation
src/ingestion/dbt/tests/gold/assert_git_file_category_vendored.sql, src/ingestion/dbt/tests/gold/assert_git_observations_dimension_values.sql
Tests representative vendored and non-vendored paths and forbids vendored in invalid observation category tuples.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Git file changes
  participant fct_git_file_change
  participant git_file_category
  participant Line-count metrics
  Git file changes->>fct_git_file_change: provide file paths
  fct_git_file_change->>git_file_category: classify each path
  git_file_category-->>fct_git_file_change: return vendored or existing category
  fct_git_file_change->>Line-count metrics: provide categorized changes
  Line-count metrics-->>Line-count metrics: exclude vendored from authored code-location counts
Loading

Possibly related PRs

Suggested reviewers: aleksdotbar

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: excluding vendored/generated files from authored git LOC.
Linked Issues check ✅ Passed The changes satisfy #1798 with configurable path-based exclusion, upstream classification, separate vendored categorization, and test coverage.
Out of Scope Changes check ✅ Passed All changes align with the git LOC exclusion work and documentation updates; no unrelated scope is evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/ingestion/dbt/dbt_project.yml`:
- Around line 62-66: Add the missing lockfile patterns for package-lock.json,
yarn.lock, and poetry.lock to the lockfile classification list in
dbt_project.yml, alongside the existing go.sum and Cargo.lock entries, so they
are categorized as vendored rather than matched by the fallback config rule.

In `@src/ingestion/dbt/macros/git_file_category.sql`:
- Around line 17-19: Update the git_vendored_path_regex macro to safely handle
an empty git_vendored_path_patterns override: fetch the variable with an
appropriate default and emit a regex that matches nothing when the resulting
list is empty. Preserve the existing joined-pattern regex behavior when patterns
are configured.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16d3d6d7-c067-40b7-896d-67b5a98819ad

📥 Commits

Reviewing files that changed from the base of the PR and between 5ab0caa and 7f82cf4.

📒 Files selected for processing (7)
  • src/ingestion/dbt/dbt_project.yml
  • src/ingestion/dbt/macros/git_file_category.sql
  • src/ingestion/dbt/tests/gold/assert_git_file_category_vendored.sql
  • src/ingestion/dbt/tests/gold/assert_git_observations_dimension_values.sql
  • src/ingestion/silver/git/README.md
  • src/ingestion/silver/git/fct_git_file_change.sql
  • src/ingestion/silver/git/schema.yml

Comment thread src/ingestion/dbt/dbt_project.yml
Comment thread src/ingestion/dbt/macros/git_file_category.sql
Address CodeRabbit review on constructorfabric#1826:

- Empty `git_vendored_path_patterns` override previously made `join('|')`
  emit `(?i)()`, which matches every path and would flag ALL files as
  vendored. Guard it: emit an RE2-safe never-match `[^\s\S]` when the list
  is empty (RE2 has no lookahead, so `(?!)` is unavailable).
- Classify the remaining common lockfiles (package-lock.json, yarn.lock,
  poetry.lock, Pipfile.lock, gradle.lockfile, mix.lock, flake.lock, …) as
  vendored too, so all machine-managed lockfiles land in one auditable
  bucket instead of split between `vendored` and `config`.
- Extend the fixture test with lockfile cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz

Copy link
Copy Markdown
Contributor Author

Addressed CodeRabbit review in 15ea04c:

  • Major (empty-override): git_vendored_path_regex now emits an RE2-safe never-match [^\s\S] when git_vendored_path_patterns is empty, instead of (?i)() (which would have matched every path). Verified end-to-end.
  • Minor (lockfiles): added the remaining common lockfiles (package-lock.json, yarn.lock, poetry.lock, Pipfile.lock, gradle.lockfile, mix.lock, flake.lock, npm-shrinkwrap.json, packages.lock.json) so all machine-managed lockfiles classify as vendored consistently. Fixture test extended.

@cyberantonz
cyberantonz merged commit a86f92a into constructorfabric:main Jul 20, 2026
28 checks passed
@cyberantonz
cyberantonz deleted the fix/exclude-vendored-git-loc branch July 22, 2026 07:34
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 vendored and generated files from git line-count metrics

2 participants