Skip to content

fix: handle nested scope objects in ListScopes API response#51

Merged
ewega merged 1 commit intomainfrom
fix/list-scopes-response-shape
Feb 19, 2026
Merged

fix: handle nested scope objects in ListScopes API response#51
ewega merged 1 commit intomainfrom
fix/list-scopes-response-shape

Conversation

@ewega
Copy link
Copy Markdown
Contributor

@ewega ewega commented Feb 19, 2026

Bug found during live testing: the DevLake GET /scopes API returns scopes wrapped in a nested scope key, not flat scopeId/scopeName fields.

Before: ScopeListEntry expected { scopeId, scopeName } - parsed as empty.
After: ScopeListWrapper.Scope handles { scope: { githubId, id, fullName } } correctly.

Tested against a real DevLake instance with 231 GitHub scopes and 1 Copilot scope.

The DevLake GET /scopes API returns scopes wrapped in a 'scope' key:
  { count: N, scopes: [{ scope: { githubId: ..., fullName: ... } }] }

The previous ScopeListEntry assumed flat fields (scopeId, scopeName)
which don't exist. Fixed to:
- Added ScopeListWrapper type for the nesting
- ScopeListEntry now captures githubId (int, GitHub) and id (string, Copilot)
- listConnectionScopes resolves the ID field based on plugin type

Found during live testing against a real DevLake instance with 231 GitHub
scopes and 1 Copilot scope.
Copilot AI review requested due to automatic review settings February 19, 2026 20:39
@ewega ewega added this to the v0.3.7 milestone Feb 19, 2026
@ewega ewega merged commit d15b54d into main Feb 19, 2026
1 check passed
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

This PR fixes a critical bug in the scope listing functionality where the DevLake API returns scopes in a nested structure that wasn't properly parsed. The previous implementation expected flat scopeId/scopeName fields, but the actual API wraps each scope in a scope key with different field names (githubId/id, name, fullName).

Changes:

  • Introduced ScopeListWrapper to unwrap the nested scope object from API responses
  • Updated ScopeListEntry fields to match actual API structure (GithubID, ID, Name, FullName)
  • Added scope ID resolution logic to handle plugin-specific ID field differences (GitHub's int githubId vs Copilot's string id)

Reviewed changes

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

File Description
internal/devlake/types.go Added ScopeListWrapper type and updated ScopeListEntry/ScopeListResponse to match the nested API response structure
cmd/configure_projects.go Added unwrapping logic and plugin-specific scope ID/name resolution when processing scopes

Comment on lines +294 to +298
// Resolve scope ID: GitHub uses githubId (int), Copilot uses id (string)
scopeID := s.ID
if c.plugin == "github" && s.GithubID > 0 {
scopeID = fmt.Sprintf("%d", s.GithubID)
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

If both s.GithubID is 0 (or negative) and s.ID is empty, scopeID will be an empty string. This could lead to issues when creating BlueprintScope entries with empty IDs. Consider adding validation to ensure at least one ID field is populated, or log a warning when this occurs.

Copilot uses AI. Check for mistakes.
var bpScopes []devlake.BlueprintScope
var repos []string
for _, s := range resp.Scopes {
for _, w := range resp.Scopes {
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The ListScopes API call in client.go uses pageSize=100&page=1, which may not retrieve all scopes if more than 100 exist. The PR description mentions testing with 231 GitHub scopes. Consider verifying that all scopes were successfully retrieved, and if not, implement pagination logic or use a larger page size. The resp.Count field could be checked to warn if scopes were truncated.

Copilot uses AI. Check for mistakes.
@ewega ewega deleted the fix/list-scopes-response-shape branch March 4, 2026 14:10
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.

2 participants