feat(repo): expose fileCount in --output json#16
Conversation
Adds `repository.fileCount` to the JSON output, derived from `AnalysisService.listCommitFiles(lastAnalysedCommit.sha, limit=1)` — one extra API call per JSON invocation, omitted when the repo has no analysed commit or the call fails. Unblocks repo-size visibility for the `configure-codacy-cloud` skill, which now reports both `languageCount` and `fileCount` in its summary without the harness needing repo-level access. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 8 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Code Review
This pull request adds a fileCount field to the repository object in the JSON output of the repo command. This field is retrieved on a best-effort basis from the last analyzed commit using AnalysisService.listCommitFiles with a limit of 1. The changes include comprehensive unit tests covering success, missing commit, and failure scenarios, along with updated documentation and a changeset. I have no feedback to provide as the implementation is solid and well-tested.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull Request Overview
The PR correctly implements the addition of fileCount to the JSON output of the repository command. Most acceptance criteria are met, including graceful handling of missing commits and API errors.
However, the implementation introduces sequential API calls that increase latency for JSON output users. Additionally, there is a missing test scenario to verify that the extra API call is strictly limited to JSON output modes. Quality-wise, the test suite shows significant code duplication (12 clones) that should be refactored to maintainability.
Test suggestions
- fileCount is correctly included in JSON output when a last analysed commit is available.
- fileCount is omitted from JSON output when lastAnalysedCommit is undefined.
- fileCount is omitted from JSON output when listCommitFiles API call rejects with an error.
- The listCommitFiles API is not invoked when the output format is not JSON.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. The listCommitFiles API is not invoked when the output format is not JSON.
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
| ); | ||
| }); | ||
|
|
||
| it("omits fileCount from JSON when no analysed commit exists", async () => { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: The test suite setup for mocking repository responses is highly repetitive. Extracting a shared helper function would reduce boilerplate and make the tests more readable.
Refactor src/commands/repository.test.ts to create a shared helper function for mocking the standard RepositoryService and AnalysisService responses used across the repository command test suite.
| const analysedSha = data.lastAnalysedCommit?.sha; | ||
| if (analysedSha) { | ||
| try { | ||
| const filesResponse = await AnalysisService.listCommitFiles( |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: The listCommitFiles request is made sequentially after the initial Promise.all and after the spinner has stopped. This increases total latency for JSON output and can cause a perceived hang in the CLI if the network is slow.
Refactor the repository command logic to initiate the listCommitFiles request as soon as repoResponse resolves, allowing it to run in parallel with the remaining dashboard requests, and ensure the spinner remains active until all data is ready for printing.
There was a problem hiding this comment.
Pull request overview
This PR extends the repository / repo command’s JSON output to include a best-effort repository.fileCount field, allowing downstream consumers (notably configure-codacy-cloud) to read repository size without requiring additional repo-level access.
Changes:
- Adds a best-effort
fileCountlookup (viaAnalysisService.listCommitFiles(..., limit=1)andpagination.total) when--output jsonis used. - Updates repository command tests to cover: success, no analysed commit, and API failure cases.
- Updates command docs/spec changelog and adds a changeset for the user-facing output change.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/commands/repository.ts |
Adds repository.fileCount to JSON output by performing an additional best-effort API call when a last analysed commit exists. |
src/commands/repository.test.ts |
Adds/extends tests validating fileCount presence/omission and the listCommitFiles invocation. |
src/commands/AGENTS.md |
Documents the new JSON repository.fileCount field behavior and its best-effort fetching rules. |
SPECS/README.md |
Adds a changelog entry documenting the new JSON field and its behavior. |
package-lock.json |
Updates lockfile metadata/version to match the current package version. |
.changeset/repo-json-file-count.md |
Adds a changeset describing the new JSON field (needs a small wording tweak noted in comments). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| undefined, | ||
| 1, | ||
| ); | ||
| fileCount = (filesResponse as any).pagination?.total; |
| "@codacy/codacy-cloud-cli": minor | ||
| --- | ||
|
|
||
| `codacy repo --output json` now includes a `fileCount` field on the repository object, derived from the analysis of the last analysed commit. Lets consumers (e.g. the `configure-codacy-cloud` skill) read repo size without a separate API call. Returns `undefined` when the repo has no analysed commit. |
Switches `repository.fileCount` from a dedicated `listCommitFiles(limit=1)` call to plucking `data.coverage.numberTotalFiles` off the existing `getRepositoryWithAnalysis` response. The field is populated even when the repo has no coverage data, so we get the file count for free — no extra API roundtrip, no commit-SHA dance, no best-effort try/catch. Drops 2 tests that covered the removed error/missing-commit paths and the default `listCommitFiles` mock. Test count: 374 → 373. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds
repository.fileCountto the JSON output, derived fromAnalysisService.listCommitFiles(lastAnalysedCommit.sha, limit=1). This means one extra API call per JSON invocation, omitted when the repo has no analysed commit or the call fails.Unblocks repo-size visibility for the
configure-codacy-cloudskill, which now reports bothlanguageCountandfileCountin its summary without the harness needing repo-level access.