Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
feat: Add repository (project) token support OD-489#37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alerizzo
merged 5 commits into
main
from
cloud-cli-add-support-for-project-tokens-od-489Aug 11, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4daad5
feat: Add repository (project) token support OD-489
alerizzo 148baa0
fix: Address Codacy review feedback on OD-489
alerizzo 7fbfe51
chore: Split compound bullet in AGENTS.md guard exception
alerizzo 489c132
fix: Refuse an empty --repository-token instead of widening scope
alerizzo 3528d45
chore: Shorten the data-dependent guard exception in AGENTS.md
alerizzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| "@codacy/codacy-cloud-cli": minor | ||
| --- | ||
| Add repository (project) token support | ||
| You can now authenticate with a **repository token** — scoped to a single repository — instead of a personal account API token that reaches every organization and repository you can see. This is the right credential for CI and for the auto-configuration agent: if it leaks, the blast radius is one repository. | ||
| ```bash | ||
| codacy tools --repository-token <your-repository-token> | ||
| # or, for a whole CI job: | ||
| export CODACY_PROJECT_TOKEN=<your-repository-token> | ||
| ``` | ||
| Get one from **Codacy > Repository > Settings > Integrations > Project API token**. The new `--repository-token <token>` flag is accepted by every command, and `CODACY_PROJECT_TOKEN` is picked up automatically. | ||
| **Token precedence** (identical to the Codacy Analysis CLI): `--repository-token` > `CODACY_PROJECT_TOKEN` > `CODACY_API_TOKEN` > stored `codacy login`. An explicit `--repository-token` wins outright, so a deliberately scoped run is never silently widened. Note that `CODACY_PROJECT_TOKEN` outranks `CODACY_API_TOKEN` — unset it if you want your account token used. | ||
| **Not every command accepts a repository token**, because Codacy only honours them on a limited set of repository-scoped operations: | ||
| - **Fully supported:** `tools`, `tool`, `patterns`, `pattern`, `issues` (including `--overview`), `tools --import`, `repository --reanalyze` / `--reanalyze-and-wait`. | ||
| - **Partially supported:** `repository` works but omits the pull request and coverage sections. In `--output json`, `pullRequests` stays an empty array and a new `unavailable: ["pullRequests"]` field marks what couldn't be fetched. Output under an account token is unchanged. | ||
| - **Account token required:** `info`, `repositories`, `ls`, `directories`, `pull-request`, `pull-requests`, `issue`, `findings`, `finding`, `issues --ignore`/`--ignored`, `tools --import --force`, and `repository`'s `--add`/`--remove`/`--follow`/`--unfollow`/`--link-standard`/`--unlink-standard`. | ||
| Unsupported combinations now fail immediately with a message naming the operation, why a repository token can't perform it, and which token is in use — instead of sending a request that comes back as a bare `Unauthorized`. | ||
| `codacy login` continues to store account tokens only; repository tokens are passed per command or via the environment. | ||
| Also fixed: `codacy repository` no longer loses the entire dashboard when the pull request lookup fails, and `codacy login` no longer reports a repository token as "invalid" when it is rejected for being the wrong kind of token. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Codacy AI review instructions | ||
| Project-specific context for reviewing this repository. These notes exist to | ||
| prevent recurring false positives — they are not blanket exemptions, so still | ||
| flag a finding when it points at a concrete defect. | ||
| ## Repository shape | ||
| - Single-package Node.js + TypeScript CLI (`@codacy/codacy-cloud-cli`) wrapping | ||
| the Codacy API v3. Commander for the CLI, Vitest for tests. | ||
| - `src/api/client/` is **auto-generated** from the OpenAPI spec by | ||
| `npm run update-api`. Never flag findings there and never suggest edits to it. | ||
| - Conventions live in `AGENTS.md` (root) and `src/commands/AGENTS.md`; specs and | ||
| the backlog live in `SPECS/`. | ||
| ## Tests | ||
| - Test files are deliberately long and repetitive: fixtures are written out in | ||
| full rather than factored into builders, so each test reads standalone. **File-level | ||
| length and duplication findings on `*.test.ts` are expected** and should not be | ||
| reported. | ||
| - Each command test builds its own bare `new Command()` harness rather than | ||
| importing `src/index.ts`. That duplication is intentional — it keeps a command's | ||
| tests independent of global CLI wiring. | ||
| ## Complexity metrics | ||
| - Lizard's TypeScript parser sometimes **merges adjacent function declarations** | ||
| into a single span, reporting their combined cyclomatic complexity against the | ||
| first function's name. Before reporting a complexity finding, check that the | ||
| named function really contains that many branches; if the reported span covers | ||
| more than one declaration, the number is a parser artifact. | ||
| - Command action handlers are inherently branchy — they dispatch across mutually | ||
| exclusive flag modes with early returns. Prefer suggesting extraction of a | ||
| cohesive block (validation, rendering) over generic "reduce complexity" advice. | ||
| ## Authentication | ||
| - The CLI accepts two token kinds: an **account token** (`api-token` header) and a | ||
| **repository/project token** (`project-token` header). See | ||
| `SPECS/repository-tokens.md`. | ||
| - Codacy honours repository tokens on only a fixed set of operations. That | ||
| whitelist is **deliberately hardcoded** in the command guards — it mirrors a | ||
| server-side allowlist that the client cannot query, so don't suggest deriving it | ||
| dynamically. It carries a "re-verify after every `npm run update-api`" note. | ||
| - Guards intentionally refuse **before** issuing any request and before | ||
| `resolveRepoArgs()` runs, so an unsupported operation fails fast instead of | ||
| returning a bare `Unauthorized`. | ||
| ## Documentation | ||
| - Cross-references between `SPECS/*.md`, `AGENTS.md`, and `README.md` are often | ||
| added in the **same** pull request as the file they point at. Verify the target | ||
| is absent from the PR's own diff before reporting a broken reference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM RISK
Document a clear exception or escalation process alongside this absolute rule. Include criteria for when an exception might apply and who can authorize it.
See Issue in Codacy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair — the rule is absolute but the exception was left implicit. Added two sub-bullets: commands whose endpoints are all whitelisted need no guard at all (
tool,patterns,patternare the live examples), and when an operation's scope is genuinely unclear the escalation is to confirm against the API owners and record it inSPECS/repository-tokens.mdrather than guess a guard.🤖 Generated by /pr-fixup command