You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ma...@apache.org on 2023/02/20 06:58:19 UTC
[incubator-devlake] branch main updated: feat(bamboo): change project to plan (#4452)
This is an automated email from the ASF dual-hosted git repository.
mappjzc 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 3f3e0ad75 feat(bamboo): change project to plan (#4452)
3f3e0ad75 is described below
commit 3f3e0ad75b734bdfd5d148bcef013a4aa909f76a
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Mon Feb 20 14:58:16 2023 +0800
feat(bamboo): change project to plan (#4452)
---
backend/plugins/bamboo/api/blueprint_v200.go | 10 +-
backend/plugins/bamboo/impl/impl.go | 8 +-
.../migrationscripts/20230216_add_init_tables.go | 3 +-
.../models/migrationscripts/archived/plan.go | 48 ++++++++
backend/plugins/bamboo/models/plan.go | 88 ++++++++++++++
backend/plugins/bamboo/models/project.go | 54 +++++----
.../{project_collector.go => plan_collector.go} | 42 ++++---
backend/plugins/bamboo/tasks/plan_extractor.go | 61 ++++++++++
...{projects_convertor.go => project_convertor.go} | 2 +
backend/plugins/bamboo/tasks/project_extractor.go | 127 ---------------------
backend/plugins/bamboo/tasks/shared.go | 23 +---
11 files changed, 267 insertions(+), 199 deletions(-)
diff --git a/backend/plugins/bamboo/api/blueprint_v200.go b/backend/plugins/bamboo/api/blueprint_v200.go
index 1ce6d404f..d627b0973 100644
--- a/backend/plugins/bamboo/api/blueprint_v200.go
+++ b/backend/plugins/bamboo/api/blueprint_v200.go
@@ -18,9 +18,7 @@ limitations under the License.
package api
import (
- "encoding/json"
"fmt"
- "io"
"net/http"
"github.com/apache/incubator-devlake/plugins/bamboo/models"
@@ -134,7 +132,7 @@ func GetprojectByConnectionIdAndscopeId(connectionId uint64, scopeId string) (*m
key := scopeId
project := &models.BambooProject{}
db := basicRes.GetDal()
- err := db.First(project, dal.Where("connection_id = ? AND key = ?", connectionId, key))
+ err := db.First(project, dal.Where("connection_id = ? AND project_key = ?", connectionId, key))
if err != nil {
if db.IsErrorNotFound(err) {
return nil, errors.Default.Wrap(err, fmt.Sprintf("can not find project by connection [%d] scope [%s]", connectionId, scopeId))
@@ -178,11 +176,7 @@ func GetApiProject(
if res.StatusCode != http.StatusOK {
return nil, errors.HttpStatus(res.StatusCode).New(fmt.Sprintf("unexpected status code when requesting project detail from %s", res.Request.URL.String()))
}
- body, err := errors.Convert01(io.ReadAll(res.Body))
- if err != nil {
- return nil, err
- }
- err = errors.Convert(json.Unmarshal(body, projectRes))
+ err = helper.UnmarshalResponse(res, projectRes)
if err != nil {
return nil, err
}
diff --git a/backend/plugins/bamboo/impl/impl.go b/backend/plugins/bamboo/impl/impl.go
index 2680319c0..734f6471e 100644
--- a/backend/plugins/bamboo/impl/impl.go
+++ b/backend/plugins/bamboo/impl/impl.go
@@ -81,8 +81,8 @@ func (p Bamboo) Description() string {
func (p Bamboo) SubTaskMetas() []plugin.SubTaskMeta {
// TODO add your sub task here
return []plugin.SubTaskMeta{
- tasks.CollectProjectMeta,
- tasks.ExtractProjectMeta,
+ tasks.CollectPlanMeta,
+ tasks.ExtractPlanMeta,
tasks.ConvertProjectsMeta,
}
}
@@ -115,7 +115,7 @@ func (p Bamboo) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i
// support v100 & advance mode
// If we still cannot find the record in db, we have to request from remote server and save it to db
db := taskCtx.GetDal()
- err = db.First(&scope, dal.Where("connection_id = ? AND key = ?", op.ConnectionId, op.ProjectKey))
+ err = db.First(&scope, dal.Where("connection_id = ? AND project_key = ?", op.ConnectionId, op.ProjectKey))
if err != nil && db.IsErrorNotFound(err) {
apiProject, err := api.GetApiProject(op.ProjectKey, apiClient)
if err != nil {
@@ -180,7 +180,7 @@ func (p Bamboo) ApiResources() map[string]map[string]plugin.ApiResourceHandler {
}
func (p Bamboo) MakePipelinePlan(connectionId uint64, scope []*plugin.BlueprintScopeV100) (plugin.PipelinePlan, errors.Error) {
- return nil, errors.Default.New("Bamboo don't support blueprint v100")
+ return nil, errors.Default.New("Bamboo does not support blueprint v100")
}
func (p Bamboo) Close(taskCtx plugin.TaskContext) errors.Error {
diff --git a/backend/plugins/bamboo/models/migrationscripts/20230216_add_init_tables.go b/backend/plugins/bamboo/models/migrationscripts/20230216_add_init_tables.go
index 1b208b546..61c335e79 100644
--- a/backend/plugins/bamboo/models/migrationscripts/20230216_add_init_tables.go
+++ b/backend/plugins/bamboo/models/migrationscripts/20230216_add_init_tables.go
@@ -31,11 +31,12 @@ func (u *addInitTables) Up(baseRes context.BasicRes) errors.Error {
baseRes,
&archived.BambooConnection{},
&archived.BambooProject{},
+ &archived.BambooPlan{},
)
}
func (*addInitTables) Version() uint64 {
- return 20230216205028
+ return 20230216205031
}
func (*addInitTables) Name() string {
diff --git a/backend/plugins/bamboo/models/migrationscripts/archived/plan.go b/backend/plugins/bamboo/models/migrationscripts/archived/plan.go
new file mode 100644
index 000000000..91b5b0c61
--- /dev/null
+++ b/backend/plugins/bamboo/models/migrationscripts/archived/plan.go
@@ -0,0 +1,48 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package archived
+
+import (
+ "github.com/apache/incubator-devlake/core/models/migrationscripts/archived"
+)
+
+type BambooPlan struct {
+ ConnectionId uint64 `gorm:"primaryKey"`
+ PlanKey string `json:"planKey" gorm:"primaryKey"`
+ Name string `json:"name"`
+ Expand string `json:"expand"`
+ ProjectKey string `json:"projectKey" gorm:"index"`
+ ProjectName string `json:"projectName"`
+ Description string `json:"description"`
+ ShortName string `json:"shortName"`
+ BuildName string `json:"buildName"`
+ ShortKey string `json:"shortKey"`
+ Type string `json:"type"`
+ Enabled bool `json:"enabled"`
+ Href string `json:"href"`
+ Rel string `json:"rel"`
+ IsFavourite bool `json:"isFavourite"`
+ IsActive bool `json:"isActive"`
+ IsBuilding bool `json:"isBuilding"`
+ AverageBuildTimeInSeconds float64 `json:"averageBuildTimeInSeconds"`
+ archived.NoPKModel
+}
+
+func (b *BambooPlan) TableName() string {
+ return "_tool_bamboo_plans"
+}
diff --git a/backend/plugins/bamboo/models/plan.go b/backend/plugins/bamboo/models/plan.go
new file mode 100644
index 000000000..fa1ecce92
--- /dev/null
+++ b/backend/plugins/bamboo/models/plan.go
@@ -0,0 +1,88 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package models
+
+import (
+ "github.com/apache/incubator-devlake/core/models/common"
+)
+
+type BambooPlan struct {
+ ConnectionId uint64 `gorm:"primaryKey"`
+ PlanKey string `json:"planKey" gorm:"primaryKey"`
+ Name string `json:"name"`
+ Expand string `json:"expand"`
+ ProjectKey string `json:"projectKey" gorm:"index"`
+ ProjectName string `json:"projectName"`
+ Description string `json:"description"`
+ ShortName string `json:"shortName"`
+ BuildName string `json:"buildName"`
+ ShortKey string `json:"shortKey"`
+ Type string `json:"type"`
+ Enabled bool `json:"enabled"`
+ Href string `json:"href"`
+ Rel string `json:"rel"`
+ IsFavourite bool `json:"isFavourite"`
+ IsActive bool `json:"isActive"`
+ IsBuilding bool `json:"isBuilding"`
+ AverageBuildTimeInSeconds float64 `json:"averageBuildTimeInSeconds"`
+ common.NoPKModel
+}
+
+func (b *BambooPlan) Convert(apiProject *ApiBambooPlan) {
+ b.PlanKey = apiProject.Key
+ b.Name = apiProject.Name
+ b.Expand = apiProject.Expand
+ b.ProjectKey = apiProject.ProjectKey
+ b.ProjectName = apiProject.ProjectName
+ b.Description = apiProject.Description
+ b.ShortName = apiProject.ShortName
+ b.BuildName = apiProject.BuildName
+ b.ShortKey = apiProject.ShortKey
+ b.Type = apiProject.Type
+ b.Enabled = apiProject.Enabled
+ b.Href = apiProject.Href
+ b.Rel = apiProject.Rel
+ b.IsFavourite = apiProject.IsFavourite
+ b.IsActive = apiProject.IsActive
+ b.IsBuilding = apiProject.IsBuilding
+ b.AverageBuildTimeInSeconds = apiProject.AverageBuildTimeInSeconds
+
+}
+
+func (b *BambooPlan) TableName() string {
+ return "_tool_bamboo_plans"
+}
+
+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"`
+}
diff --git a/backend/plugins/bamboo/models/project.go b/backend/plugins/bamboo/models/project.go
index c621aa8bc..d8b903351 100644
--- a/backend/plugins/bamboo/models/project.go
+++ b/backend/plugins/bamboo/models/project.go
@@ -17,29 +17,10 @@ limitations under the License.
package models
-import "github.com/apache/incubator-devlake/core/models/common"
-
-type ApiBambooProject struct {
- Key string `json:"key"`
- Expand string `json:"expand"`
- Name string `json:"name"`
- Description string `json:"description"`
- Link ApiBambooLink `json:"link"`
- Plans ApiBambooSizeData `json:"plans"`
-}
-
-type ApiBambooProjects struct {
- ApiBambooSizeData
- Expand string `json:"expand"`
- Link ApiBambooLink `json:"link"`
- Projects []ApiBambooProject `json:"project"`
-}
-
-type ApiBambooProjectResponse struct {
- Expand string `json:"expand"`
- Link ApiBambooLink `json:"link"`
- Projects ApiBambooProjects `json:"projects"`
-}
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/models/common"
+)
type BambooProject struct {
ConnectionId uint64 `json:"connectionId" mapstructure:"connectionId" gorm:"primaryKey"`
@@ -62,3 +43,30 @@ func (b *BambooProject) Convert(apiProject *ApiBambooProject) {
func (b *BambooProject) TableName() string {
return "_tool_bamboo_projects"
}
+
+type ApiBambooPlans struct {
+ ApiBambooSizeData `json:"squash"`
+ Plan []json.RawMessage `json:"plan"`
+}
+
+type ApiBambooProject struct {
+ Key string `json:"key"`
+ Expand string `json:"expand"`
+ Name string `json:"name"`
+ Description string `json:"description"`
+ Link ApiBambooLink `json:"link"`
+ Plans ApiBambooPlans `json:"plans"`
+}
+
+type ApiBambooProjects struct {
+ ApiBambooSizeData `json:"squash"`
+ Expand string `json:"expand"`
+ Link ApiBambooLink `json:"link"`
+ Projects []ApiBambooProject `json:"project"`
+}
+
+type ApiBambooProjectResponse struct {
+ Expand string `json:"expand"`
+ Link ApiBambooLink `json:"link"`
+ Projects ApiBambooProjects `json:"projects"`
+}
diff --git a/backend/plugins/bamboo/tasks/project_collector.go b/backend/plugins/bamboo/tasks/plan_collector.go
similarity index 66%
rename from backend/plugins/bamboo/tasks/project_collector.go
rename to backend/plugins/bamboo/tasks/plan_collector.go
index 108a142bf..1c06d43d5 100644
--- a/backend/plugins/bamboo/tasks/project_collector.go
+++ b/backend/plugins/bamboo/tasks/plan_collector.go
@@ -23,45 +23,53 @@ import (
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
- "io"
+ "github.com/apache/incubator-devlake/plugins/bamboo/models"
"net/http"
"net/url"
)
-const RAW_PROJECT_TABLE = "bamboo_project"
+const RAW_PLAN_TABLE = "bamboo_plan"
-var _ plugin.SubTaskEntryPoint = CollectProject
+var _ plugin.SubTaskEntryPoint = CollectPlan
-func CollectProject(taskCtx plugin.SubTaskContext) errors.Error {
- rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PROJECT_TABLE)
+func CollectPlan(taskCtx plugin.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PLAN_TABLE)
collectorWithState, err := helper.NewApiCollectorWithState(*rawDataSubTaskArgs, nil)
if err != nil {
return err
}
- incremental := collectorWithState.IsIncremental()
err = collectorWithState.InitCollector(helper.ApiCollectorArgs{
- Incremental: incremental,
ApiClient: data.ApiClient,
- // TODO write which api would you want request
+ PageSize: 100,
UrlTemplate: "project/{{ .Params.ProjectKey }}.json",
Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
query := url.Values{}
query.Set("showEmpty", fmt.Sprintf("%v", true))
+ query.Set("expand", "plans.plan")
+ query.Set("max-result", fmt.Sprintf("%v", reqData.Pager.Size))
+ query.Set("start-index", fmt.Sprintf("%v", (reqData.Pager.Page-1)*reqData.Pager.Size))
return query, nil
},
GetTotalPages: func(res *http.Response, args *helper.ApiCollectorArgs) (int, errors.Error) {
- return 1, nil
+ var body struct {
+ SizeInfo models.ApiBambooSizeData `json:"plans"`
+ }
+ err = helper.UnmarshalResponse(res, &body)
+ if err != nil {
+ return 0, err
+ }
+ return GetTotalPagesFromSizeInfo(&body.SizeInfo, args)
},
ResponseParser: func(res *http.Response) ([]json.RawMessage, errors.Error) {
- body, err := io.ReadAll(res.Body)
+ body := &models.ApiBambooProject{}
+ err = helper.UnmarshalResponse(res, body)
if err != nil {
- return nil, errors.Convert(err)
+ return nil, err
}
- res.Body.Close()
- return []json.RawMessage{body}, nil
+ return body.Plans.Plan, nil
},
})
if err != nil {
@@ -70,10 +78,10 @@ func CollectProject(taskCtx plugin.SubTaskContext) errors.Error {
return collectorWithState.Execute()
}
-var CollectProjectMeta = plugin.SubTaskMeta{
- Name: "CollectProject",
- EntryPoint: CollectProject,
+var CollectPlanMeta = plugin.SubTaskMeta{
+ Name: "CollectPlan",
+ EntryPoint: CollectPlan,
EnabledByDefault: true,
- Description: "Collect Project data from Bamboo api",
+ Description: "Collect Plan data from Bamboo api",
DomainTypes: []string{plugin.DOMAIN_TYPE_CICD},
}
diff --git a/backend/plugins/bamboo/tasks/plan_extractor.go b/backend/plugins/bamboo/tasks/plan_extractor.go
new file mode 100644
index 000000000..275060701
--- /dev/null
+++ b/backend/plugins/bamboo/tasks/plan_extractor.go
@@ -0,0 +1,61 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/apache/incubator-devlake/plugins/bamboo/models"
+)
+
+var _ plugin.SubTaskEntryPoint = ExtractPlan
+
+func ExtractPlan(taskCtx plugin.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PLAN_TABLE)
+
+ extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+
+ Extract: func(resData *helper.RawData) ([]interface{}, errors.Error) {
+ body := &models.BambooPlan{}
+ res := &models.ApiBambooPlan{}
+ err := errors.Convert(json.Unmarshal(resData.Data, res))
+ if err != nil {
+ return nil, err
+ }
+ body.Convert(res)
+ body.ConnectionId = data.Options.ConnectionId
+ return []interface{}{body}, nil
+ },
+ })
+ if err != nil {
+ return err
+ }
+
+ return extractor.Execute()
+}
+
+var ExtractPlanMeta = plugin.SubTaskMeta{
+ Name: "ExtractPlan",
+ EntryPoint: ExtractPlan,
+ EnabledByDefault: true,
+ Description: "Extract raw data into tool layer table bamboo_plan",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_CICD},
+}
diff --git a/backend/plugins/bamboo/tasks/projects_convertor.go b/backend/plugins/bamboo/tasks/project_convertor.go
similarity index 98%
rename from backend/plugins/bamboo/tasks/projects_convertor.go
rename to backend/plugins/bamboo/tasks/project_convertor.go
index 0db91aad3..36a575b85 100644
--- a/backend/plugins/bamboo/tasks/projects_convertor.go
+++ b/backend/plugins/bamboo/tasks/project_convertor.go
@@ -31,6 +31,8 @@ import (
bambooModels "github.com/apache/incubator-devlake/plugins/bamboo/models"
)
+const RAW_PROJECT_TABLE = "bamboo_project"
+
var ConvertProjectsMeta = plugin.SubTaskMeta{
Name: "convertProjects",
EntryPoint: ConvertProjects,
diff --git a/backend/plugins/bamboo/tasks/project_extractor.go b/backend/plugins/bamboo/tasks/project_extractor.go
deleted file mode 100644
index 4423a6402..000000000
--- a/backend/plugins/bamboo/tasks/project_extractor.go
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package tasks
-
-import (
- "encoding/json"
-
- "github.com/apache/incubator-devlake/core/errors"
- "github.com/apache/incubator-devlake/core/plugin"
- helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
- "github.com/apache/incubator-devlake/plugins/bamboo/models"
-)
-
-var _ plugin.SubTaskEntryPoint = ExtractProject
-
-func ExtractProject(taskCtx plugin.SubTaskContext) errors.Error {
- rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PROJECT_TABLE)
-
- extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
- RawDataSubTaskArgs: *rawDataSubTaskArgs,
-
- Extract: func(resData *helper.RawData) ([]interface{}, errors.Error) {
- res := &models.ApiBambooProject{}
- err := errors.Convert(json.Unmarshal(resData.Data, res))
- if err != nil {
- return nil, err
- }
- body := ConvertProject(res)
- body.ConnectionId = data.Options.ConnectionId
- return []interface{}{body}, nil
- },
- })
- if err != nil {
- return err
- }
-
- return extractor.Execute()
-}
-
-var ExtractProjectMeta = plugin.SubTaskMeta{
- Name: "ExtractProject",
- EntryPoint: ExtractProject,
- EnabledByDefault: true,
- Description: "Extract raw data into tool layer table bamboo_project",
- DomainTypes: []string{plugin.DOMAIN_TYPE_CICD},
-}
-
-// Convert the API response to our DB model instance
-func ConvertProject(bambooApiProject *models.ApiBambooProject) *models.BambooProject {
- bambooProject := &models.BambooProject{
- ProjectKey: bambooApiProject.Key,
- Name: bambooApiProject.Name,
- Description: bambooApiProject.Description,
- Href: bambooApiProject.Link.Href,
- Rel: bambooApiProject.Link.Rel,
- }
- return bambooProject
-}
-
-//type ApiProject struct {
-// ProjectKey string `json:"key"`
-// Name string `json:"name"`
-// Description string `json:"description"`
-// Link Link `json:"link"`
-//}
-//type ApiActions struct {
-// Size int `json:"size"`
-// StartIndex int `json:"start-index"`
-// MaxResult int `json:"max-result"`
-//}
-//type ApiStages struct {
-// Size int `json:"size"`
-// StartIndex int `json:"start-index"`
-// MaxResult int `json:"max-result"`
-//}
-//type ApiBranches struct {
-// Size int `json:"size"`
-// StartIndex int `json:"start-index"`
-// MaxResult int `json:"max-result"`
-//}
-//type ApiPlanKey struct {
-// ProjectKey string `json:"key"`
-//}
-//type ApiPlan struct {
-// Expand string `json:"expand"`
-// ProjectKey string `json:"projectKey"`
-// ProjectName string `json:"projectName"`
-// Description string `json:"description"`
-// ShortName string `json:"shortName"`
-// BuildName string `json:"buildName"`
-// ShortKey string `json:"shortKey"`
-// Type string `json:"type"`
-// Enabled bool `json:"enabled"`
-// ApiLink `json:"link"`
-// IsFavourite bool `json:"isFavourite"`
-// IsActive bool `json:"isActive"`
-// IsBuilding bool `json:"isBuilding"`
-// AverageBuildTimeInSeconds int `json:"averageBuildTimeInSeconds"`
-// Actions Actions `json:"actions"`
-// Stages Stages `json:"stages"`
-// Branches Branches `json:"branches"`
-// ProjectKey string `json:"key"`
-// Name string `json:"name"`
-// PlanKey PlanKey `json:"planKey"`
-//}
-//type ApiPlans struct {
-// Size int `json:"size"`
-// Expand string `json:"expand"`
-// StartIndex int `json:"start-index"`
-// MaxResult int `json:"max-result"`
-// Plan []ApiPlan `json:"plan"`
-//}
diff --git a/backend/plugins/bamboo/tasks/shared.go b/backend/plugins/bamboo/tasks/shared.go
index 3e89bc80d..c49a7f339 100644
--- a/backend/plugins/bamboo/tasks/shared.go
+++ b/backend/plugins/bamboo/tasks/shared.go
@@ -18,11 +18,10 @@ limitations under the License.
package tasks
import (
- "net/http"
-
"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"
)
func CreateRawDataSubTaskArgs(taskCtx plugin.SubTaskContext, rawTable string) (*api.RawDataSubTaskArgs, *BambooTaskData) {
@@ -42,24 +41,10 @@ func CreateRawDataSubTaskArgs(taskCtx plugin.SubTaskContext, rawTable string) (*
return rawDataSubTaskArgs, &filteredData
}
-func GetTotalPagesFromResponse(res *http.Response, args *api.ApiCollectorArgs) (int, errors.Error) {
- body := &BambooPagination{}
- err := api.UnmarshalResponse(res, body)
- if err != nil {
- return 0, err
- }
- pages := body.Paging.Total / args.PageSize
- if body.Paging.Total%args.PageSize > 0 {
+func GetTotalPagesFromSizeInfo(sizeInfo *models.ApiBambooSizeData, args *api.ApiCollectorArgs) (int, errors.Error) {
+ pages := sizeInfo.Size / args.PageSize
+ if sizeInfo.Size%args.PageSize > 0 {
pages++
}
return pages, nil
}
-
-type BambooPagination struct {
- Paging Paging `json:"paging"`
-}
-type Paging struct {
- PageIndex int `json:"pageIndex"`
- PageSize int `json:"pageSize"`
- Total int `json:"total"`
-}