Skip to content

Commit 8cdf293

Browse files
CLI-77 Auto-install sonar-secrets during sonar integrate claude
1 parent bd2fdb7 commit 8cdf293

File tree

7 files changed

+115
-240
lines changed

7 files changed

+115
-240
lines changed

README.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,6 @@ sonar auth status
119119

120120
---
121121

122-
### `sonar install`
123-
124-
Install Sonar tools
125-
126-
#### `sonar install secrets`
127-
128-
Install sonar-secrets binary from https://binaries.sonarsource.com
129-
130-
**Options:**
131-
132-
| Option | Type | Required | Description | Default |
133-
| ---------- | ------- | -------- | ----------------------------------------------- | ------- |
134-
| `--force` | boolean | No | Force reinstall even if already installed | - |
135-
| `--status` | boolean | No | Check installation status instead of installing | - |
136-
137-
**Examples:**
138-
139-
Install latest sonar-secrets binary
140-
```bash
141-
sonar install secrets
142-
```
143-
144-
Reinstall sonar-secrets (overwrite existing)
145-
```bash
146-
sonar install secrets --force
147-
```
148-
149-
Check if sonar-secrets is installed and up to date
150-
```bash
151-
sonar install secrets --status
152-
```
153-
154-
---
155-
156122
### `sonar integrate`
157123

158124
Setup SonarQube integration for AI coding agents, git and others.

src/cli/command-tree.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { authLogin, type AuthLoginOptions } from './commands/auth/login';
2828
import { authLogout, type AuthLogoutOptions } from './commands/auth/logout';
2929
import { authPurge } from './commands/auth/purge';
3030
import { authStatus } from './commands/auth/status';
31-
import { installSecrets, type InstallSecretsOptions } from './commands/install/secrets';
3231
import { integrateClaude, type IntegrateClaudeOptions } from './commands/integrate/claude';
3332
import { integrateGit, type IntegrateGitOptions } from './commands/integrate/git/index';
3433
import { analyzeSecrets, type AnalyzeSecretsOptions } from './commands/analyze/secrets';
@@ -66,16 +65,6 @@ COMMAND_TREE.name('sonar')
6665
.addHelpText('beforeAll', getHelpBanner())
6766
.enablePositionalOptions();
6867

69-
// Install Sonar tools
70-
const install = COMMAND_TREE.command('install').description('Install Sonar tools');
71-
72-
install
73-
.command('secrets')
74-
.description('Install sonar-secrets binary from https://binaries.sonarsource.com')
75-
.option('--force', 'Force reinstall even if already installed')
76-
.option('--status', 'Check installation status instead of installing')
77-
.authenticatedAction((_auth, options: InstallSecretsOptions) => installSecrets(options));
78-
7968
// Setup SonarQube integration for AI coding agent
8069
const integrateCommand = COMMAND_TREE.command('integrate').description(
8170
'Setup SonarQube integration for AI coding agents, git and others.',

src/cli/commands/install/secrets.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function installSecrets(
6262
await installSecretsStatus();
6363
} else {
6464
text('\nInstalling sonar-secrets binary\n');
65-
const binaryPath = await performSecretInstall(options, { binDir });
65+
const { binaryPath } = await performSecretInstall(options, { binDir });
6666
logInstallationSuccess(binaryPath);
6767
}
6868
}
@@ -73,7 +73,7 @@ export async function installSecrets(
7373
export async function performSecretInstall(
7474
options: { force?: boolean },
7575
{ binDir }: { binDir?: string } = {},
76-
): Promise<string> {
76+
): Promise<{ binaryPath: string; freshlyInstalled: boolean }> {
7777
const platform = detectPlatform();
7878
const resolvedBinDir = ensureBinDirectory(binDir);
7979
const binaryPath = join(resolvedBinDir, buildLocalBinaryName(platform));
@@ -82,13 +82,12 @@ export async function performSecretInstall(
8282

8383
try {
8484
await performInstallation(options, platform, binaryPath);
85-
text(` sonar-secrets installed at ${binaryPath}`);
86-
return binaryPath;
85+
return { binaryPath, freshlyInstalled: true };
8786
} catch (err) {
8887
const isAlreadyUpToDate =
8988
(err as Error).message === 'Installation skipped - already up to date';
9089
if (isAlreadyUpToDate) {
91-
return binaryPath;
90+
return { binaryPath, freshlyInstalled: false };
9291
}
9392
throw err;
9493
}
@@ -265,7 +264,6 @@ async function checkExistingInstallation(binaryPath: string): Promise<boolean> {
265264

266265
if (existingVersion === pinnedVersion) {
267266
text(`sonar-secrets ${existingVersion} is already installed (latest)`);
268-
text(' Use --force to reinstall');
269267
return true;
270268
}
271269

src/cli/commands/integrate/claude/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { blank, info, intro, note, outro, success, text, warn } from '../../../.
2929
import type { DiscoveredProject } from '../../_common/discovery';
3030
import { discoverProject } from '../../_common/discovery';
3131
import { CommandFailedError } from '../../_common/error';
32+
import { performSecretInstall } from '../../install/secrets';
3233
import { runHealthChecks } from './health';
3334
import { installHooks } from './hooks';
3435
import { repairToken } from './repair';
@@ -70,6 +71,18 @@ export async function integrateClaude(
7071

7172
let token = config.token;
7273

74+
try {
75+
const { binaryPath, freshlyInstalled } = await performSecretInstall({ force: false });
76+
if (freshlyInstalled) {
77+
success(`sonar-secrets installed at ${binaryPath}`);
78+
}
79+
} catch (err) {
80+
warn(`sonar-secrets installation failed: ${(err as Error).message}`);
81+
warn(
82+
'Secrets scanning will not be available until installed. Re-run sonar integrate claude to retry.',
83+
);
84+
}
85+
7386
blank();
7487
text('Phase 2/3: Health Check & Repair');
7588
blank();

tests/integration/specs/install/install-secrets.test.ts

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)