Skip to content
Open
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/import-exclude-as-ignore-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codacy/codacy-cloud-cli": minor
---

`tools --import` now imports the config's `exclude` patterns, global and per tool, as ignore rules on Codacy, and lists every pattern it doesn't import with the reason. New `--dry-run` flag shows the whole import without changing anything.
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ codacy-cloud-cli/
- **Proxy / TLS:** never hand-roll this. Outbound HTTP configuration is delegated to `configureProxy()` from `@codacy/tooling`, wrapped by `configureProxyFromEnv()` in `src/utils/proxy.ts` and called once at the top of `src/index.ts`. It installs a global `undici` dispatcher, so every `fetch` — the generated client and the CVE lookup alike — is covered without touching generated code. Keeping the implementation upstream is what keeps the environment contract identical to the Codacy Analysis CLI; a local reimplementation would drift. If proxy behavior needs to change, change it in `analysis-cli`'s `packages/tooling/src/proxy.ts` and bump the dependency here.
- **Authentication — two token kinds.** Read `SPECS/repository-tokens.md` before touching auth or adding a command.
- An **account token** (`api-token` header) reaches everything its owner can see.
- A **repository token** (`project-token` header) is scoped to one repository. It is accepted only on a fixed whitelist of 13 operations; everywhere else Codacy rejects it as if no token had been sent.
- A **repository token** (`project-token` header) is scoped to one repository. It is accepted only on a fixed whitelist of 19 operations; everywhere else Codacy rejects it as if no token had been sent.
- Every command that calls the API resolves auth first, via `resolveAuth(this)` from `src/utils/auth.ts` (returns a `RemoteAuth` discriminated union), and declares `.addOption(repositoryTokenOption())` so `--repository-token` parses.
- **New commands must decide their token scope**, using the whitelist in `SPECS/repository-tokens.md`:
- account-only end to end → `resolveAccountAuth(this, "<why a repository token can't do it>")`
Expand Down
1 change: 1 addition & 0 deletions SPECS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This is the single source of truth for all project tasks and specs.

| Date | What was done |
|---|---|
| 2026-12-02 | (OD-1268) **`tools --import` imports `exclude` as ignore rules.** The global `exclude` becomes rules for every tool and each tool's `exclude` rules for that tool, grouped so a pattern on several tools is one rule. Literal paths with a `/` go as `file` rules without their escapes, everything else as `glob`. Patterns of unknown tools and with a leading `/` are skipped by the CLI, everything else is judged by the API. The preview checks the rules with `dryRun` and lists every pattern not imported with its reason. New **`--dry-run`** (with `--import` only) prints the whole preview and writes nothing. A repository with a Codacy configuration file (409) gets one line and the tools are still imported. API client pinned to codacy-api 58.11.0, and the repository-token whitelist re-verified against it (19 operations, the 5 ignore rules ones added) (35 new tests, 889 total) |
| 2026-11-10 | New **`file`** command (alias `fl`): the CLI counterpart of the UI's file view. Summary (grade, issues, complexity, clones + duplicated lines, coverage with covered/coverable lines), its clones (lines here → other occurrences), and its source with a green/red coverage gutter and each issue inline under its line. Without source, the issues are listed at the top as the same cards `issues` prints; with `--lines`, issues outside the range are listed at the top. `--lines <from-to>` narrows the source, `-N, --no-source` hides it. The path is resolved to a `fileId` by listing the parent folder and matching exactly (not `search`, which matches substrings); with an auto-detected repository it is relative to the cwd (an absolute path is resolved against the git root, and a path outside the repository is refused). Source is fetched at the analysed `commitSha` so line numbers match issues and coverage. `--output json` carries no source code (the content endpoint isn't called): `{ file, issues, clones, coverage }`, with per-line `coverage.lines` `{ line, hits }`. Account token only — none of the file endpoints are whitelisted (29 new tests, 854 total) |
| 2026-11-09 | (OD-1049) `findings` can narrow to container scanning. **`--scan-types` accepts `ContainerSCA`**, the API value (as the `SearchSRMItems.scanTypes` example in the spec lists it), not `ContainerScanning` as the ticket named it; `ContainerScanning` and `Container` are accepted as aliases, normalized like the other scan types. The normalized list is now de-duplicated, since several aliases resolve to one value. **`-i, --image <name>` and `-t, --image-tag <tag>`** map to the body's `containerImage` (`ContainerImageFilter`), through `parseImageFilter`: values are trimmed, `--image name:tag` is split (a registry port stays in the name), and empty values, a tag without a name, a digest reference or two different tags are refused before any request. An empty `--image` would otherwise be dropped by a truthiness check and silently widen the result to the whole org. **Container findings show `image:tag` in place of the repository** on the `findings` card (also in the single-repository view) and on the `finding` header, through the shared `formatImageReference`; both commands' JSON gains `imageName`/`imageTag` (25 new tests, 823 total) |
| 2026-11-03 | **Node.js engines raised for CVE-2026-111497** (Brotli decoder OOB write, bundled in Node). `engines` `>=20` → `^22.23.4 \|\| ^24.22.1 \|\| >=26.12.1`, the first patched release of each line; Node 20 is EOL and unpatched, so it is dropped. CI matrix `[20, 22]` → `[22, 24]`. No dependency change: the repo ships no Brotli package, but `fetch` (undici) decompresses `Content-Encoding: br` responses with Node's bundled decoder, so the runtime is the exposure. `engines` only warns on install; no runtime version check was added |
Expand Down
38 changes: 38 additions & 0 deletions SPECS/commands/tools-and-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,44 @@ Each group is a columnar table with columns:
| Via Standard | Coding standard name(s), or `Overwritten by file` if config file is used, or `—` |
| Notes | `Client-side tool` if applicable, otherwise `—` |

## Import (`--import [path]`)

Applies a `codacy.config.json` (default `.codacy/codacy.config.json`) to the repository: its tools and patterns, and,
since OD-1268, its `exclude` patterns as ignore rules. `-y` skips the confirmation, `--force` unlinks coding standards
first, and `--dry-run` prints the whole preview (tools and ignore rules) and exits without asking or writing. `--dry-run`
is refused without `--import`.

### `exclude` becomes ignore rules

Code in `src/utils/import-ignore-rules.ts`.

- The global `exclude` becomes rules for every tool. A tool's `exclude` becomes rules for that tool. The same pattern on
several tools becomes one rule with all of them, because the API refuses a second rule with the same path and type
whatever its tools. A tool pattern that is also global stays global only.
- A literal path with a `/` (no unescaped glob character, no leading `!`, `#` or `/`, no empty, `.` or `..` segment) is
sent as a `file` rule with its backslash escapes removed, so `pages/\[id\].tsx` becomes `pages/[id].tsx`, the way
stored single-file rules look. Everything else is sent as a `glob`, as written. A literal without `/`, like
`README.md`, stays a `glob`, because the Analysis CLI matches it in every folder.
- Rules go 100 per request, global rules first, in file order, with reason "Imported from <config file name>" and
source `user`.
- The CLI skips two kinds of pattern itself. Patterns of a tool that isn't on Codacy, and patterns with a leading `/`,
which the API would strip (so `/vendor/**` would ignore the root `vendor` folder in the cloud) while the Analysis CLI
matches nothing for them.
- Everything else is judged by the API. The preview sends every batch with `dryRun=true` and prints how many rules
would be added, how many are already on Codacy, and a table of every pattern that won't be imported with its reason.
The import prints the same after the real request.
- A dry run checks each batch against the stored rules only, so with more than 100 patterns a limit can show up one
batch late.
- A 409 means the repository has a Codacy configuration file, which decides the ignores. The rules step stops with one
yellow line and the tools are still imported.
- A batch that fails otherwise counts as an import error, and the next batch is still sent.
- The import only adds. It never deletes a cloud rule the config doesn't list, and never changes the tools of an
existing rule (that comes back as already on Codacy).
- A config without `exclude` makes no ignore rules call and prints nothing about them.

API: [`addRepositoryIgnoreRules`](https://api.codacy.com/api/api-docs#addrepositoryignorerules), with `dryRun` for the
preview.

## Tests

File: `src/commands/tools.test.ts` — 6 tests.
Expand Down
9 changes: 7 additions & 2 deletions SPECS/repository-tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ depends on it). Both flag and env values are trimmed.
> it. Source: Linear project *"Project token works in selected API v3
> (+expiration)"*.
>
> **Last verified against API `57.4.17`** (2026-09-09). Since `57.4.x` the spec
> **Last verified against API `58.11.0`** (2026-12-02). Since `57.4.x` the spec
> declares the `ProjectTokenAuth` security scheme (`project-token` header) on
> each supported operation, so the whitelist is now machine-checkable:
>
Expand All @@ -64,7 +64,7 @@ depends on it). Both flag and env values are trimmed.
> On `57.3.9` (the previously pinned build) the scheme was not declared
> anywhere, which is why this table was maintained by hand.

Codacy accepts a repository token on **exactly** these 14 operations. Everywhere
Codacy accepts a repository token on **exactly** these 19 operations. Everywhere
else it is rejected as if no token had been sent.

| operationId | Method | Used by this CLI |
Expand All @@ -78,11 +78,16 @@ else it is rejected as if no token had been sent.
| `listRepositoryCommits` | GET | `repository`, `repository --reanalyze*` |
| `configureTool` | PATCH | `tool`, `pattern`, `tools --import` |
| `updateRepositoryToolPatterns` | PATCH | `patterns`, `tools --import` |
| `addRepositoryIgnoreRules` | POST | `tools --import` |
| `reanalyzeCommitById` | POST | `repository --reanalyze*` |
| `getRepositoryLanguages` | GET | — |
| `getRepository` | GET | — |
| `listIgnoredFiles` | GET | — |
| `searchAiInventoryCategories` | POST | — |
| `listRepositoryIgnoreRules` | GET | — |
| `listRepositoryIgnoreRuleTools` | GET | — |
| `updateRepositoryIgnoreRule` | PATCH | — |
| `deleteRepositoryIgnoreRules` | POST | — |

`ToolsService.listTools` / `listPatterns` / `getPattern` are declared
`security: []` in the spec — unauthenticated, so they work with any token or
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prepublishOnly": "npm run update-api && npm run build",
"start": "npx ts-node src/index.ts",
"start:dist": "node dist/index.js",
"fetch-api": "curl https://artifacts.codacy.com/api/codacy-api/57.7.10/apiv3-bundled.yaml -o ./api-v3/api-swagger.yaml --create-dirs",
"fetch-api": "curl https://artifacts.codacy.com/api/codacy-api/58.11.0/apiv3-bundled.yaml -o ./api-v3/api-swagger.yaml --create-dirs",
"generate-api": "rm -rf ./src/api/client && openapi --input ./api-v3/api-swagger.yaml --output ./src/api/client --useUnionTypes --indent 2 --client fetch",
"update-api": "npm run fetch-api && npm run generate-api",
"check-types": "tsc --noEmit"
Expand Down
Loading
Loading