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

abeizn 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 6419a9954 fix: bamboo search-remote-scopes api (#6110)
6419a9954 is described below

commit 6419a99544fd5201a76faf2e1aa57a54a734d9d0
Author: abeizn <[email protected]>
AuthorDate: Tue Sep 19 16:36:07 2023 +0800

    fix: bamboo search-remote-scopes api (#6110)
    
    * fix: bamboo search-remote-scopes api
    
    * fix: bamboo search-remote-scopes api
---
 backend/plugins/bamboo/api/remote.go  | 16 +++++++++++++---
 backend/plugins/bamboo/models/plan.go | 35 +++++++++++++----------------------
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/backend/plugins/bamboo/api/remote.go 
b/backend/plugins/bamboo/api/remote.go
index b31dd40ce..c3ab38dd6 100644
--- a/backend/plugins/bamboo/api/remote.go
+++ b/backend/plugins/bamboo/api/remote.go
@@ -20,12 +20,13 @@ package api
 import (
        gocontext "context"
        "fmt"
+       "net/url"
+
        "github.com/apache/incubator-devlake/core/context"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
        "github.com/apache/incubator-devlake/plugins/bamboo/models"
-       "net/url"
 )
 
 // RemoteScopes list all available scope for users
@@ -65,21 +66,30 @@ func SearchRemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutp
                                return nil, errors.BadInput.Wrap(err, "failed 
to get create apiClient")
                        }
                        query := initialQuery(queryData)
+                       if len(queryData.Search) == 0 {
+                               return nil, errors.BadInput.New("empty search 
query")
+                       }
                        query.Set("searchTerm", queryData.Search[0])
                        // request search
                        res, err := apiClient.Get("search/plans.json", query, 
nil)
                        if err != nil {
                                return nil, err
                        }
+
                        resBody := models.ApiBambooSearchPlanResponse{}
                        err = api.UnmarshalResponse(res, &resBody)
                        if err != nil {
                                return nil, err
                        }
+
                        var apiBambooPlans []models.ApiBambooPlan
                        // append project to output
                        for _, apiResult := range resBody.SearchResults {
-                               apiBambooPlans = append(apiBambooPlans, 
apiResult.Entity)
+                               bambooPlan := models.ApiBambooPlan{
+                                       Key:  apiResult.SearchEntity.Key,
+                                       Name: apiResult.SearchEntity.PlanName,
+                               }
+                               apiBambooPlans = append(apiBambooPlans, 
bambooPlan)
                        }
                        return apiBambooPlans, err
                })
@@ -87,7 +97,7 @@ func SearchRemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutp
 
 func initialQuery(queryData *api.RemoteQueryData) url.Values {
        query := url.Values{}
-       query.Set("showEmpty", fmt.Sprintf("%v", true))
+       query.Set("showEmpty", fmt.Sprintf("%v", false))
        query.Set("max-result", fmt.Sprintf("%v", queryData.PerPage))
        query.Set("start-index", fmt.Sprintf("%v", 
(queryData.Page-1)*queryData.PerPage))
        return query
diff --git a/backend/plugins/bamboo/models/plan.go 
b/backend/plugins/bamboo/models/plan.go
index db29f5e23..76e892fb1 100644
--- a/backend/plugins/bamboo/models/plan.go
+++ b/backend/plugins/bamboo/models/plan.go
@@ -87,25 +87,6 @@ type ApiBambooPlan struct {
        } `json:"planKey"`
 }
 
-//type ApiBambooPlan struct {
-//     Expand                    string `json:"expand"`
-//     Description               string `json:"description"`
-//     ShortName                 string `json:"shortName"`
-//     BuildName                 string `json:"buildName"`
-//     ShortKey                  string `json:"shortKey"`
-//     Type                      string `json:"type"`
-//     Enabled                   bool   `json:"enabled"`
-//     ProjectKey                string `json:"projectKey"`
-//     ProjectName               string `json:"projectName"`
-//     ApiBambooLink             `json:"link"`
-//     IsFavourite               bool    `json:"isFavourite"`
-//     IsActive                  bool    `json:"isActive"`
-//     IsBuilding                bool    `json:"isBuilding"`
-//     AverageBuildTimeInSeconds float64 `json:"averageBuildTimeInSeconds"`
-//     Key                       string  `json:"key"`
-//     Name                      string  `json:"name"`
-//}
-
 func (p ApiBambooPlan) ConvertApiScope() plugin.ToolLayerScope {
        return &BambooPlan{
                PlanKey:   p.Key,
@@ -119,10 +100,20 @@ func (p ApiBambooPlan) ConvertApiScope() 
plugin.ToolLayerScope {
        }
 }
 
+type SearchEntity struct {
+       ID          string `json:"id"`
+       Key         string `json:"key"`
+       ProjectName string `json:"projectName"`
+       PlanName    string `json:"planName"`
+       BranchName  string `json:"branchName"`
+       Description string `json:"description"`
+       Type        string `json:"type"`
+}
+
 type ApiSearchResult struct {
-       Id         string        `json:"id"`
-       EntityType string        `json:"entityType"`
-       Entity     ApiBambooPlan `json:"entity"`
+       Id           string       `json:"id"`
+       Type         string       `json:"type"`
+       SearchEntity SearchEntity `json:"searchEntity"`
 }
 
 type ApiBambooSearchPlanResponse struct {

Reply via email to