Repository navigation
GROW-703 Run onboard-ci gitlab on the server when available - #1325
alain-kermis-sonarsource wants to merge 1 commit into
Conversation
✅ Deploy Preview for sonarqube-cli canceled.
|
Code Review
|
| Auto-apply | Compact | Unblock |
|
|
|
Was this helpful? React with 👍 / 👎 | Gitar
| try { | ||
| return (await client.createRun(request).orThrow()).id; | ||
| } catch (error) { | ||
| if (error instanceof BadRequestError) { | ||
| const message = error.message.replaceAll(request.credential.token, '***'); | ||
| throw new CommandFailedError(message, { exitCode: EXIT_CODE_VALIDATION }); | ||
| } | ||
| throw translateAccessError(error); | ||
| } |
There was a problem hiding this comment.
💡 Security: GitLab token is redacted from 400 create errors only
createRun replaces the GitLab PAT with *** only when the error is a BadRequestError. For any other non-2xx POST response (409, 422, 500, ...), SonarHttpClient.buildStatusError builds the message as SonarQube API error: <status> <text> - ${errorText}, i.e. it includes the raw response body (http-client.ts:162-165). translateAccessError then passes that error through unchanged. So if the server echoes the request credential in a non-400 error body, the token reaches the terminal and the logs. That is the exact case the redaction and the 'never surfaces the GitLab token, even if the server echoes it' test are meant to guard against. Apply the redaction to every error that comes out of createRun, not just the 400 branch.
Redact the token from any error that comes out of the create call:
} catch (error) {
const redact = (text: string) => text.replaceAll(request.credential.token, '***');
if (error instanceof BadRequestError) {
throw new CommandFailedError(redact(error.message), { exitCode: EXIT_CODE_VALIDATION });
}
const translated = translateAccessError(error);
if (translated instanceof CommandFailedError) throw translated;
throw new CommandFailedError(redact(translated.message));
}
Was this helpful? React with 👍 / 👎
| report(run: CiConfigurationRun): void { | ||
| const { counts } = run; | ||
| const detail = formatRunCounts(counts, run.dryRun); | ||
| this.setTotal(counts.total); | ||
| this.skippedResolved = Math.max(0, counts.total - counts.queued - counts.running); | ||
| this.update(RUN_ROW, 'running', detail); | ||
| if (!this.isTTY && detail !== this.lastDetail) { | ||
| this.output.info(detail); | ||
| } | ||
| this.lastDetail = detail; | ||
| } | ||
|
|
||
| complete(run: CiConfigurationRun): void { | ||
| const failed = run.status === 'FAILED'; | ||
| // The row itself counts as one resolved item once done; keep the bar at exactly 100%. |
There was a problem hiding this comment.
💡 Edge Case: Progress bar shows N/0 when the first poll is already terminal
RunProgress.setTotal is only called from report(), and pollRun skips report() when the first getRun already returns a terminal status (a fast or small run, or a dry run). In that case complete() sets skippedResolved = counts.total - 1 and marks the row done while total is still 0. In TTY mode formatBar then renders 100% <counts.total>/0. The total can also be stale if the server's count changed after the last non-terminal poll. Call setTotal in complete() as well.
Set the total from the terminal run before finishing:
complete(run: CiConfigurationRun): void {
const failed = run.status === 'FAILED';
const total = Math.max(1, run.counts.total);
this.setTotal(total);
// The row itself counts as one resolved item once done; keep the bar at exactly 100%.
this.skippedResolved = total - 1;
this.update(RUN_ROW, failed ? 'failed' : 'done', formatRunCounts(run.counts, run.dryRun));
this.finish();
}
Was this helpful? React with 👍 / 👎
| const { httpClient } = connection; | ||
| const sqsClient = new OnboardCiSqsClient(httpClient); | ||
| if (!(await sqsClient.users.hasProvisionProjectsPermission().orThrow())) { | ||
| throw new CommandFailedError( |
There was a problem hiding this comment.
ℹ️ Cross-PR: Client-side preflight calls a permission API that #1318 removes
Breaks when both this PR and #1318 merge (in either order) and the GitLab client-side path runs, either through --client-side or because the capability probe fell back.
How
- This PR keeps
preflightcallingsqsClient.users.hasProvisionProjectsPermission()onOnboardCiSqsClientfrom./sqs-api.ts(src/commands/admin/onboard-ci/gitlab/index.ts:247-248). - #1318 moves the client to
src/commands/admin/onboard-ci/sqs-api.ts, which exposes onlybindingsandcomponentsand has nousersmember (sqs-api.ts:31). - #1318 moves the permission check into the command tree instead (
assertProvisionProjectsPermissionincommand-tree.ts), so the call kept inpreflightno longer compiles.
Fix
- This PR: Remove the
userspermission check frompreflightand rely on #1318's command-tree check. ImportOnboardCiSqsClientfrom../sqs-api.ts. - #1318: Nothing needed, beyond keeping
assertProvisionProjectsPermissionahead of the GitLab action so the client-side path is still guarded.
Compared b8c1171 with #1318 at 7e6eb6e
Was this helpful? React with 👍 / 👎
| repos?: string; | ||
| clientSide?: boolean; | ||
| serverSide?: boolean; |
There was a problem hiding this comment.
ℹ️ Cross-PR: #1318's GitLab options type lacks repos, clientSide, serverSide fields
Breaks when both this PR and #1318 merge and #1318's refactored OnboardCiGitlabOptions replaces the one this PR extends.
How
- This PR adds
repos,clientSideandserverSidetoOnboardCiGitlabOptions(src/commands/admin/onboard-ci/gitlab/types.ts:43-45).assertSelectionFlags,shouldRunServerSideandresolveSelectedRepoEntriesall read these fields. - In #1318,
OnboardCiGitlabOptions extends OnboardCiOptions, which declares onlybindingName,reposFileanddryRun?(src/commands/admin/onboard-ci/types.ts). None of the new fields is there. - #1318 also makes
dryRunoptional, butbuildCreateRunRequestassignsoptions.dryRuntoCreateCiConfigurationRunRequest.dryRun: boolean(server-side.ts:124).
Fix
- This PR: After rebasing, declare
repos?,clientSide?andserverSide?on the refactored interface (or on the sharedOnboardCiOptionsif GitHub should get--repostoo). SenddryRun: options.dryRun === true. - #1318: Nothing needed.
Compared b8c1171 with #1318 at 7e6eb6e
Was this helpful? React with 👍 / 👎
| function toResults(items: CiRunItem[]): OnboardCiResults { | ||
| const results: OnboardCiResults = { opened: [], skipped: [], failed: [] }; | ||
| for (const item of items) { | ||
| const repo = item.repository; | ||
| const skipReason = toSkipReason(item.skipReason); | ||
| if (item.status === 'OPENED') { | ||
| results.opened.push({ | ||
| repo, | ||
| projectKey: item.projectKey ?? '', | ||
| mrUrl: item.mergeRequestUrl ?? '', | ||
| }); | ||
| } else if (item.status === 'SKIPPED' && skipReason) { | ||
| results.skipped.push({ | ||
| repo, | ||
| reason: skipReason, |
There was a problem hiding this comment.
ℹ️ Cross-PR: Server-side results use mrUrl while #1318 shares prUrl
Breaks when both this PR and #1318 merge and onboardCiGitlabServerSide writes its report.
How
- This PR's
toResultsbuildsopened/skippedentries withmrUrl(src/commands/admin/onboard-ci/gitlab/server-side.ts:221-232) and passes them straight towriteReportFile(server-side.ts:268). - #1318 changes the shared
OpenedResult/SkippedResultto carryprUrl(src/commands/admin/onboard-ci/types.ts:32), so the server-side entries no longer type-check. - #1318 keeps the published
mrUrlreport key only through a mapping in the client-side live path (src/commands/admin/onboard-ci/gitlab/index.ts:400-404). Renaming the server-side fields toprUrlwithout that mapping changes the GitLab report key.
Fix
- This PR: Build results with
prUrl, then reuse a shared helper that mapsprUrlback tomrUrlbeforewriteReportFile. Also importwriteReportFilefrom #1318'sshared.ts. - #1318: Pull the
prUrl→mrUrlreport mapping out into an exported GitLab helper so both paths can share it.
Compared b8c1171 with #1318 at 7e6eb6e
Was this helpful? React with 👍 / 👎
|



Part of GROW-703
sonar admin onboard-ci gitlabnow asks the server forGET /api/v2/onboarding/ci-configuration/capabilitiesand, when runs are enabled, lets the server open the merge requests (same reports, exit codes and flags). Otherwise it keeps the existing client-side path.--server-side/--client-sideforce a mode.--repos a,b,c, exclusive with--repos-file.Backend: https://github.com/SonarSource/sonarqube-unification/pull/2648
Tested: typecheck, lint, unit tests, the
onboard-ci-gitlabintegration spec, and the server path end to end against a Server instance and GitLab.🤖 Generated with Claude Code