This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch feat#5640
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/feat#5640 by this push:
new afe7440c8 fix: bamboo search-remote-scopes api
afe7440c8 is described below
commit afe7440c8ee2080264fdc592e7c42267781ef7b2
Author: abeizn <[email protected]>
AuthorDate: Tue Sep 19 15:23:42 2023 +0800
fix: bamboo search-remote-scopes api
---
backend/plugins/bamboo/api/remote.go | 12 +++++++++---
backend/plugins/bamboo/models/plan.go | 25 +++----------------------
2 files changed, 12 insertions(+), 25 deletions(-)
diff --git a/backend/plugins/bamboo/api/remote.go
b/backend/plugins/bamboo/api/remote.go
index b31dd40ce..f11069850 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,26 @@ 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)
+ apiBambooPlans = append(apiBambooPlans,
apiResult.SearchEntity)
}
return apiBambooPlans, err
})
@@ -87,7 +93,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..b941e2903 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,
@@ -120,9 +101,9 @@ func (p ApiBambooPlan) ConvertApiScope()
plugin.ToolLayerScope {
}
type ApiSearchResult struct {
- Id string `json:"id"`
- EntityType string `json:"entityType"`
- Entity ApiBambooPlan `json:"entity"`
+ Id string `json:"id"`
+ Type string `json:"type"`
+ SearchEntity ApiBambooPlan `json:"searchEntity"`
}
type ApiBambooSearchPlanResponse struct {