Skip to content

Add SonarQube remote scope flag and selection support#139

Merged
ewega merged 3 commits intomainfrom
codex/add-sonarqube-support
Mar 11, 2026
Merged

Add SonarQube remote scope flag and selection support#139
ewega merged 3 commits intomainfrom
codex/add-sonarqube-support

Conversation

@Codex
Copy link
Copy Markdown
Contributor

@Codex Codex AI commented Mar 11, 2026

SonarQube must be selectable in the CLI with remote project scopes and token-based auth.

  • Connection registry: declare SonarQube projects scope flag and keep AccessToken/token env keys (cmd/connection_types.go).
  • Scope UX: allow --projects to supply project keys non-interactively, validating against remote scopes before PUT; interactive selection unchanged and still paginates remote scopes (cmd/configure_scopes.go, cmd/configure_scope_add.go).
  • Tests: assert registry includes the SonarQube projects flag and cover the non-interactive --projects path with remote-scope validation and PUT payload checks (cmd/connection_types_test.go, cmd/configure_scopes_test.go).
  • Output: suppress the --projects info line when --json is used to keep stdout machine-readable (cmd/configure_scopes.go).

Example:

gh devlake configure scope add \
  --plugin sonarqube \
  --connection-id 3 \
  --projects proj-key-1,proj-key-2

@Codex Codex AI changed the title [WIP] Add SonarQube plugin support to CLI Add SonarQube remote scope flag and selection support Mar 11, 2026
@ewega ewega marked this pull request as ready for review March 11, 2026 22:07
Copilot AI review requested due to automatic review settings March 11, 2026 22:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds non-interactive SonarQube project scope selection to the gh devlake configure scope add workflow by introducing a --projects flag and wiring it through the plugin registry and scope handler.

Changes:

  • Declares a SonarQube projects ScopeFlag in the connection registry and asserts it in tests.
  • Extends ScopeOpts and configure scope add to accept --projects and pass it into the SonarQube scope handler.
  • Updates scopeSonarQubeHandler to parse and validate provided project keys against remote scopes before PUT.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
cmd/connection_types.go Adds SonarQube ScopeFlags entry for --projects.
cmd/configure_scopes.go Implements --projects parsing + validation + non-interactive selection path in SonarQube scope handler.
cmd/configure_scope_add.go Exposes --projects flag and documents it in command help text.
cmd/connection_types_test.go Adds test assertion that SonarQube registry entry includes the projects scope flag.

Comment on lines +1245 to +1266
var selectedProjects []*devlake.RemoteScopeChild
if opts != nil && opts.Projects != "" {
var keys []string
seenKeys := make(map[string]bool)
for _, key := range strings.Split(opts.Projects, ",") {
key = strings.TrimSpace(key)
if key == "" || seenKeys[key] {
continue
}
seenKeys[key] = true
keys = append(keys, key)
}
if len(keys) == 0 {
return nil, fmt.Errorf("no SonarQube projects provided via --projects")
}
for _, key := range keys {
child, ok := projectByKey[key]
if !ok {
return nil, fmt.Errorf("project key %q not found on connection %d", key, connID)
}
selectedProjects = append(selectedProjects, child)
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new non-interactive --projects path (parsing/deduping keys, validating against remote scopes, and building the PUT payload) isn’t covered by tests. Since cmd/configure_scopes_test.go already exists for this file, add unit tests that spin up an httptest DevLake server to (1) return remote scopes with known project keys, (2) assert invalid keys error, and (3) assert PutScopes is called with the expected set of SonarQube project scopes when keys are valid.

Copilot uses AI. Check for mistakes.
}
selectedProjects = append(selectedProjects, child)
}
fmt.Printf(" Projects from --projects: %s\n", strings.Join(keys, ", "))
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new stdout line makes the non-interactive --projects flow noisier for automation, and it also further violates the repo’s --json convention (stdout should stay machine-readable / clean when outputJSON is true). Consider suppressing this informational print in JSON mode (or sending it to stderr), consistent with how other commands keep stdout clean under --json (e.g., cmd/root.go:34, cmd/configure_connection_list.go:50-64).

Suggested change
fmt.Printf(" Projects from --projects: %s\n", strings.Join(keys, ", "))
if !outputJSON {
fmt.Printf(" Projects from --projects: %s\n", strings.Join(keys, ", "))
}

Copilot uses AI. Check for mistakes.
@ewega
Copy link
Copy Markdown
Contributor

ewega commented Mar 11, 2026

@codex[agent] Please address the two review comments on this PR: 1) add tests covering the non-interactive --projects path (valid keys, invalid keys, and expected PutScopes payload); 2) suppress the informational stdout line in JSON mode so machine-readable output stays clean. After updating, rerun build/test/vet and let the review agent re-check.

@Codex
Copy link
Copy Markdown
Contributor Author

Codex AI commented Mar 11, 2026

@codex[agent] Please address the two review comments on this PR: 1) add tests covering the non-interactive --projects path (valid keys, invalid keys, and expected PutScopes payload); 2) suppress the...

Added SonarQube --projects JSON guard and covered the non-interactive path with valid/invalid key tests plus PUT payload assertions (3e3fa3f).

Copy link
Copy Markdown
Contributor

@ewega ewega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed after follow-up fixes; safe to merge.

@ewega ewega merged commit fddf04c into main Mar 11, 2026
4 checks passed
@ewega ewega deleted the codex/add-sonarqube-support branch March 11, 2026 22:30
@ewega ewega mentioned this pull request Mar 12, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants