You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2023/02/16 02:42:01 UTC

[incubator-devlake] branch main updated: fix(sonarqube): fix remote api (#4425)

This is an automated email from the ASF dual-hosted git repository.

warren pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 8610564c4 fix(sonarqube): fix remote api (#4425)
8610564c4 is described below

commit 8610564c4151e9a9e79204522e8b9a77c982f789
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Thu Feb 16 10:41:56 2023 +0800

    fix(sonarqube): fix remote api (#4425)
---
 backend/plugins/sonarqube/api/remote.go | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/backend/plugins/sonarqube/api/remote.go b/backend/plugins/sonarqube/api/remote.go
index 90f15c596..3215f9ada 100644
--- a/backend/plugins/sonarqube/api/remote.go
+++ b/backend/plugins/sonarqube/api/remote.go
@@ -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"`
 }
 
@@ -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"`
@@ -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]
@@ -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)
@@ -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]
@@ -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) {