Skip to content

feat(repo): expose fileCount in --output json#16

Merged
manufacturist merged 2 commits into
mainfrom
feat/repo-json-file-count
Jun 18, 2026
Merged

feat(repo): expose fileCount in --output json#16
manufacturist merged 2 commits into
mainfrom
feat/repo-json-file-count

Conversation

@manufacturist

Copy link
Copy Markdown
Contributor

Adds repository.fileCount to the JSON output, derived from AnalysisService.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-cloud skill, which now reports both languageCount and fileCount in its summary without the harness needing repo-level access.

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>
Copilot AI review requested due to automatic review settings June 18, 2026 12:15
@codacy-production

codacy-production Bot commented Jun 18, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 duplication

Metric Results
Duplication 8

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@gemini-code-assist gemini-code-assist 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.

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.

@codacy-production codacy-production 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.

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

Comment thread src/commands/repository.test.ts Outdated
);
});

it("omits fileCount from JSON when no analysed commit exists", async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

See Clone in Codacy

Comment thread src/commands/repository.ts Outdated
const analysedSha = data.lastAnalysedCommit?.sha;
if (analysedSha) {
try {
const filesResponse = await AnalysisService.listCommitFiles(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Copilot AI 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.

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 fileCount lookup (via AnalysisService.listCommitFiles(..., limit=1) and pagination.total) when --output json is 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.

Comment thread src/commands/repository.ts Outdated
undefined,
1,
);
fileCount = (filesResponse as any).pagination?.total;
Comment thread .changeset/repo-json-file-count.md Outdated
"@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>
@manufacturist manufacturist merged commit 8f86866 into main Jun 18, 2026
4 checks passed
@manufacturist manufacturist deleted the feat/repo-json-file-count branch June 18, 2026 13:22
@github-actions github-actions Bot mentioned this pull request Jun 18, 2026
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.

3 participants