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/rare-facts-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codacy/codacy-cloud-cli": patch
---

Adds possibility of using the cli againsta other environments
7 changes: 2 additions & 5 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/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { registerLogoutCommand } from "./commands/logout";

const program = new Command();

OpenAPI.BASE = "https://app.codacy.com/api/v3";
OpenAPI.BASE = (process.env.CODACY_API_BASE_URL || "https://app.codacy.com").replace(/\/$/, "") + "/api/v3";

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

To make the CODACY_API_BASE_URL configuration more robust, consider also stripping a potential API path suffix (e.g., /api/v3) from the provided URL. This would prevent a malformed final URL like .../api/v2/api/v3 if a user mistakenly includes an API path in the environment variable. This change would make the URL construction resilient to this common configuration error.

Suggested change
OpenAPI.BASE = (process.env.CODACY_API_BASE_URL || "https://app.codacy.com").replace(/\/$/, "") + "/api/v3";
OpenAPI.BASE = (process.env.CODACY_API_BASE_URL || "https://app.codacy.com").replace(/\/$/, "").replace(/\/api\/v\d+$/, "") + "/api/v3";

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 base URL construction will double-append the API version if it is already present in the environment variable. Use a regex to safely handle both the host-only and full-path cases.

Suggested change
OpenAPI.BASE = (process.env.CODACY_API_BASE_URL || "https://app.codacy.com").replace(/\/$/, "") + "/api/v3";
OpenAPI.BASE = (process.env.CODACY_API_BASE_URL || "https://app.codacy.com").replace(/\/+(api\/v3)?\/*$/, "") + "/api/v3";

OpenAPI.HEADERS = {
"api-token": process.env.CODACY_API_TOKEN || "",
"X-Codacy-Origin": "cli-cloud-tool",
Expand Down
Loading