Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sonarqube): fix remote api #4425

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions backend/plugins/sonarqube/api/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type RemoteScopesChild struct {
Type string `json:"type"`
ParentId *string `json:"parentId"`
Id string `json:"id"`
Name string `json:"name"`
Data interface{} `json:"data"`
}

Expand All @@ -45,6 +46,12 @@ type RemoteScopesOutput struct {
NextPageToken string `json:"nextPageToken"`
}

type SearchRemoteScopesOutput struct {
Children []RemoteScopesChild `json:"children"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}

type PageData struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
Expand All @@ -60,8 +67,8 @@ const TypeProject string = "scope"
// @Tags plugins/sonarqube
// @Accept application/json
// @Param connectionId path int false "connection ID"
// @Param pageToken body string false "page Token"
// @Success 200 {object} []models.SonarqubeProject
// @Param pageToken query string false "page Token"
// @Success 200 {object} RemoteScopesOutput
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/sonarqube/connections/{connectionId}/remote-scopes [GET]
Expand Down Expand Up @@ -118,6 +125,7 @@ func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, er
child := RemoteScopesChild{
Type: TypeProject,
Id: project.ProjectKey,
Name: project.Name,
Data: tasks.ConvertProject(&project),
}
outputBody.Children = append(outputBody.Children, child)
Expand Down Expand Up @@ -152,9 +160,9 @@ func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, er
// @Tags plugins/sonarqube
// @Accept application/json
// @Param connectionId path int false "connection ID"
// @Param page body int false "page number"
// @Param pageSize body int false "page size per page"
// @Success 200 {object} []models.SonarqubeProject
// @Param page query int false "page number"
// @Param pageSize query int false "page size per page"
// @Success 200 {object} SearchRemoteScopesOutput
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/sonarqube/connections/{connectionId}/search-remote-scopes [GET]
Expand Down Expand Up @@ -222,12 +230,21 @@ func SearchRemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
}

// set projects return
var projects []models.SonarqubeProject
outputBody := &SearchRemoteScopesOutput{}
for _, project := range resBody.Data {
projects = append(projects, *tasks.ConvertProject(&project))
child := RemoteScopesChild{
Type: TypeProject,
Id: project.ProjectKey,
ParentId: nil,
Name: project.Name,
Data: tasks.ConvertProject(&project),
}
outputBody.Children = append(outputBody.Children, child)
}
outputBody.Page = p
outputBody.PageSize = ps

return &plugin.ApiResourceOutput{Body: projects, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: outputBody, Status: http.StatusOK}, nil
}

func GetPageTokenFromPageData(pageData *PageData) (string, errors.Error) {
Expand Down