-
Notifications
You must be signed in to change notification settings - Fork 0
feat: auto-detect provider/organization/repository from git remote #11
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@codacy/codacy-cloud-cli": minor | ||
| --- | ||
|
|
||
| Auto-detect provider, organization, and repository from the git remote origin URL. All repository-scoped commands now work without explicitly passing `<provider> <organization> <repository>` — just run them inside a git repo with an `origin` remote pointing at GitHub, GitLab, or Bitbucket. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import ora from "ora"; | |
| import ansis from "ansis"; | ||
| import { checkApiToken } from "../utils/auth"; | ||
| import { handleError } from "../utils/error"; | ||
| import { detectRepoContext } from "../utils/git-remote"; | ||
| import { | ||
| getOutputFormat, | ||
| pickDeep, | ||
|
|
@@ -153,8 +154,8 @@ export function registerFindingsCommand(program: Command) { | |
| .command("findings") | ||
| .alias("find") | ||
| .description("Show security findings for a repository or an organization") | ||
| .argument("<provider>", "git provider (gh, gl, or bb)") | ||
| .argument("<organization>", "organization name") | ||
| .argument("[provider]", "git provider (gh, gl, or bb) — auto-detected from git remote if omitted") | ||
| .argument("[organization]", "organization name") | ||
| .argument( | ||
| "[repository]", | ||
| "repository name (omit to show organization-wide findings)", | ||
|
|
@@ -182,21 +183,58 @@ export function registerFindingsCommand(program: Command) { | |
| "after", | ||
| ` | ||
| Examples: | ||
| $ codacy findings # auto-detect from git remote | ||
| $ codacy findings gh my-org my-repo | ||
| $ codacy findings gh my-org | ||
| $ codacy findings gh my-org # organization-wide findings | ||
| $ codacy findings gh my-org --severities Critical,High | ||
| $ codacy findings gh my-org my-repo --statuses Overdue,DueSoon | ||
| $ codacy findings gh my-org my-repo --limit 500 | ||
| $ codacy findings gh my-org my-repo --output json`, | ||
| ) | ||
| .action(async function ( | ||
| this: Command, | ||
| provider: string, | ||
| organization: string, | ||
| repository: string | undefined, | ||
| providerArg?: string, | ||
| organizationArg?: string, | ||
| repositoryArg?: string, | ||
| ) { | ||
| try { | ||
| checkApiToken(); | ||
|
|
||
| const argCount = [providerArg, organizationArg, repositoryArg].filter( | ||
| (v) => v !== undefined, | ||
| ).length; | ||
| let provider: string; | ||
| let organization: string; | ||
| let repository: string | undefined; | ||
|
|
||
| if (argCount === 3) { | ||
| provider = providerArg!; | ||
| organization = organizationArg!; | ||
| repository = repositoryArg; | ||
| } else if (argCount === 2) { | ||
| provider = providerArg!; | ||
| organization = organizationArg!; | ||
| repository = undefined; | ||
| } else if (argCount === 0) { | ||
| const ctx = detectRepoContext(); | ||
| console.error( | ||
| ansis.dim( | ||
| ` Using ${ctx.provider} / ${ctx.organization} / ${ctx.repository} (from git remote)`, | ||
| ), | ||
| ); | ||
| provider = ctx.provider; | ||
| organization = ctx.organization; | ||
| repository = ctx.repository; | ||
| } else { | ||
| throw new Error( | ||
| "Ambiguous arguments for 'findings'. Expected 0, 2, or 3 positional arguments.\n\n" + | ||
| "Usage:\n" + | ||
| " codacy findings (auto-detect from git remote)\n" + | ||
| " codacy findings <provider> <organization> (organization-wide)\n" + | ||
| " codacy findings <provider> <organization> <repository> (repo-specific)", | ||
| ); | ||
| } | ||
|
Comment on lines
194
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 MEDIUM RISK The action handler for the 'findings' command (102 lines) exceeds the quality threshold. This is caused by manual argument resolution logic that is inconsistent with the 'resolveRepoArgs' utility used elsewhere. Refactor this to use the shared utility to reduce complexity and ensure maintainability. |
||
|
|
||
| const opts = this.opts(); | ||
| const format = getOutputFormat(this); | ||
|
|
||
|
|
||
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.
🔴 HIGH RISK
Lodash version '4.18.1' was not found in the public registry. This will cause installation failures. Please revert to the latest stable version (4.17.21).