Skip to content

audit/fetch: GitLab large-monorepo tree walk returns 0 files (directories dominate the 2000-entry page cap) #518

Closed

Description

@lex00

Summary

fetchRepoFiles against a large GitLab monorepo (e.g. gitlab-org/gitlab) returns 0 files, producing an empty audit. The root cause is that GitLab's recursive tree endpoint returns all directory nodes before any blob nodes, so the 20-page × 100-entry cap (2000 entries) is exhausted on subdirectories before a single file is seen.

Repro

import { fetchRepoFiles } from "@intentius/chant/audit/fetch";
const files = await fetchRepoFiles("https://gitlab.com/gitlab-org/gitlab");
console.log(files.length); // → 0

Works fine for small repos (gitlab-org/gitlab-runner → 50 files).

Verified manually: fetching 20 pages of the recursive tree for gitlab-org/gitlab returns 2000 entries, all of type: "tree" (directories), zero type: "blob".

Total entries scanned: 2000
  blobs:          0
  trees (dirs):   2000

The first 2000 tree entries cover paths from .agents/ through app/assets/javascripts/vue_shared/components/timezone_dropdown/ — still mid-directory enumeration, never reaching .gitlab-ci.yml.

Root cause

packages/core/src/audit/fetch.ts, listTree, GitLab branch:

const MAX_PAGES = 20; // 20 * 100 = 2000 entries
for (let page = 1; page <= MAX_PAGES; page++) {
  const url = `…/repository/tree?recursive=true&per_page=100&page=${page}&ref=…`;
  const { body } = await getJsonAt(url, …);
  …
  for (const e of body) {
    if (e.type === "blob") out.push(…);  // never reached for big repos
  }
  if (body.length < 100) break;
}

GitLab's recursive tree API lists all nested directories first (depth-first directory traversal order), then files. For a repo with thousands of subdirectories, blobs only appear after page 2000+, well past the cap.

Suggested fix

Replace the flat recursive walk with a non-recursive BFS over a bounded directory frontier:

  1. GET /repository/tree?path=&recursive=false&per_page=100 — root level only, gives both blobs and trees.
  2. Collect root blobs (most candidate files live here: .gitlab-ci.yml, Dockerfile, etc.).
  3. Enqueue subdirectories whose names could contain candidate files (.github/, .gitlab/, ci/, deploy/, k8s/, etc. — the same prefix hints isCandidatePath already knows).
  4. Recurse into those directories (capped at some depth), skipping directories that can't yield candidates.

This finds root-level CI configs in 1-2 API calls regardless of repo size, and only recurses into directories that matter.

An alternative is GitLab's search API (GET /projects/:id/search?scope=blobs&search=.gitlab-ci.yml) to locate candidate files by name directly, though that's limited to a single search term per call.

Impact

Any GitLab repo with ~500+ subdirectories produces 0 audit findings, silently. Users see a successful response (scanned: 0) with no indication the repo was effectively skipped.

Affects: Blacklight hosted audit at blacklight.intentius.io for any large GitLab monorepo.

Version

@intentius/chant 0.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions