Add SonarQube remote scope flag and selection support#139
Conversation
There was a problem hiding this comment.
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
projectsScopeFlag in the connection registry and asserts it in tests. - Extends
ScopeOptsandconfigure scope addto accept--projectsand pass it into the SonarQube scope handler. - Updates
scopeSonarQubeHandlerto 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. |
| 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) | ||
| } |
There was a problem hiding this comment.
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.
cmd/configure_scopes.go
Outdated
| } | ||
| selectedProjects = append(selectedProjects, child) | ||
| } | ||
| fmt.Printf(" Projects from --projects: %s\n", strings.Join(keys, ", ")) |
There was a problem hiding this comment.
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).
| fmt.Printf(" Projects from --projects: %s\n", strings.Join(keys, ", ")) | |
| if !outputJSON { | |
| fmt.Printf(" Projects from --projects: %s\n", strings.Join(keys, ", ")) | |
| } |
|
@codex[agent] Please address the two review comments on this PR: 1) add tests covering the non-interactive |
Added SonarQube --projects JSON guard and covered the non-interactive path with valid/invalid key tests plus PUT payload assertions (3e3fa3f). |
ewega
left a comment
There was a problem hiding this comment.
Reviewed after follow-up fixes; safe to merge.
SonarQube must be selectable in the CLI with remote project scopes and token-based auth.
projectsscope flag and keep AccessToken/token env keys (cmd/connection_types.go).--projectsto 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).--projectspath with remote-scope validation and PUT payload checks (cmd/connection_types_test.go,cmd/configure_scopes_test.go).--projectsinfo line when--jsonis used to keep stdout machine-readable (cmd/configure_scopes.go).Example: