Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/repo-json-file-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codacy/codacy-cloud-cli": minor
---

`codacy repo --output json` now includes a `fileCount` field on the repository object, plucked from `coverage.numberTotalFiles` on the existing `getRepositoryWithAnalysis` response. The field is present even on repos without coverage data, so no extra API call is needed. Lets consumers (e.g. the `configure-codacy-cloud` skill) read repo size without a separate roundtrip.
1 change: 1 addition & 0 deletions SPECS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ _No pending tasks._ All commands implemented.
| 2026-06-02 | `--reanalyze-and-wait` (`-w`) blocking variant for `repository` and `pull-request`: triggers reanalysis, polls to completion (10s interval, 20min cap), then prints issue deltas by pattern/severity/category. New `src/utils/reanalyze-wait.ts` + `formatDuration`/`isBeingAnalyzed` helpers (26 new tests, 356 total) |
| 2026-06-02 | `issues --overview` improvements: relabel False Positives buckets (`belowThreshold`/`equalOrAboveThreshold` → "Not a False Positive"/"Potential False Positive"), and a "Suggested actions to reduce noise" section that flags noisy patterns (≥10% of issues or ≥3× the average) with a runnable `codacy pattern … --disable` command, resolving the tool via its `prefix` (3 new tests, 360 total) |
| 2026-06-02 | Pattern config-file & coding-standard awareness: new `pattern <tool> <id>` **info mode** (same card as `patterns`); `pattern`/`patterns` skip listing and refuse updates when a tool uses a local config file; `pattern` refuses to modify coding-standard-enforced patterns; `issues --overview` noise suggestions now render a manual "update your config file / coding standard" step instead of a command when a pattern can't be disabled via CLI. `printPatternCard`/`PATTERN_JSON_FIELDS` moved to `utils/formatting.ts` (11 new tests, 371 total) |
| 2026-06-18 | `repo --output json` now includes `repository.fileCount`, plucked from `coverage.numberTotalFiles` on the existing `getRepositoryWithAnalysis` response (present even without coverage data — no extra API call). Unlocks repo-size visibility for downstream consumers like the `configure-codacy-cloud` skill (1 new test, 373 total) |
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/commands/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Instead of a dedicated "Visibility" column (wastes horizontal space), public rep
- Green if gate passes, red if gate fails; no coloring if no matching gate exists
- **Issues Overview**: three count tables — by category, severity level, and language — sorted descending by count within each group
- Shows pagination warning for pull requests if more exist
- JSON output bundles all three API responses into a single object
- JSON output bundles all three API responses into a single object, plus a `repository.fileCount` field plucked from `data.coverage.numberTotalFiles` (present on the existing `getRepositoryWithAnalysis` response even when the repo has no coverage data — no extra API call). Omitted when that field is absent
- **`--reanalyze` mode** (`-R`): fetches HEAD commit SHA, calls `RepositoryService.reanalyzeCommitById`; early return
- **`--reanalyze-and-wait` mode** (`-w`): blocking variant — see "Reanalyze and wait" below. Baseline comes from `issuesOverview`; polling reads the repo's first commit via `listRepositoryCommits(limit=1)` analysis timestamps

Expand Down
32 changes: 31 additions & 1 deletion src/commands/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const mockRepoData = {
addedState: "Added",
gatePolicyName: "Codacy recommended",
},
coverage: { coveragePercentage: 78 },
coverage: { coveragePercentage: 78, numberTotalFiles: 83 },
goals: {
maxComplexFilesPercentage: 25,
maxDuplicatedFilesPercentage: 10,
Expand Down Expand Up @@ -250,6 +250,36 @@ describe("repository command", () => {
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('"name": "test-repo"'),
);

const jsonCall = (console.log as ReturnType<typeof vi.fn>).mock.calls.find(
(c) => typeof c[0] === "string" && c[0].startsWith("{"),
);
const parsed = JSON.parse(jsonCall![0]);
expect(parsed.repository.fileCount).toBe(83);
});

it("omits fileCount from JSON when coverage.numberTotalFiles is absent", async () => {
vi.mocked(AnalysisService.getRepositoryWithAnalysis).mockResolvedValue({
data: { ...mockRepoData, coverage: {} } as any,
});
vi.mocked(AnalysisService.listRepositoryPullRequests).mockResolvedValue({
data: [],
});
vi.mocked(AnalysisService.issuesOverview).mockResolvedValue({
data: { counts: mockIssuesCounts },
});

const program = createProgram();
await program.parseAsync([
"node", "test", "--output", "json",
"repository", "gh", "test-org", "test-repo",
]);

const jsonCall = (console.log as ReturnType<typeof vi.fn>).mock.calls.find(
(c) => typeof c[0] === "string" && c[0].startsWith("{"),
);
const parsed = JSON.parse(jsonCall![0]);
expect(parsed.repository.fileCount).toBeUndefined();
});

it("should handle repository with no PRs and no issues", async () => {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ Examples:

if (format === "json") {
printJson(pickDeep({
repository: data,
repository: {
...data,
fileCount: data.coverage?.numberTotalFiles,
},
pullRequests,
issuesOverview: issuesCounts,
}, [
Expand All @@ -549,6 +552,7 @@ Examples:
// Metrics
"repository.issuesCount",
"repository.loc",
"repository.fileCount",
"repository.coverage.coveragePercentage",
"repository.complexFilesPercentage",
"repository.duplicationPercentage",
Expand Down
Loading