You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by "warren830 (via GitHub)" <gi...@apache.org> on 2023/02/20 13:09:34 UTC

[GitHub] [incubator-devlake] warren830 opened a new pull request, #4460: feat(bamboo): add plan and job build

warren830 opened a new pull request, #4460:
URL: https://github.com/apache/incubator-devlake/pull/4460

   ### Summary
   This pr added job and plan builds.
   There is a trick, job and plan builds have the same url but different path pattern, and almost the same structs but different type. Yes, we can process them together and convert them to cicd_pipelines and cicd_tasks according to type, but I think if we process them separately, it will be easier for us to debug or modify.
   
   ### Does this close any open issues?
   part of #3322 
   
   ### Screenshots
   <img width="1082" alt="image" src="https://user-images.githubusercontent.com/39366025/220117600-de1cf482-ab48-44d0-860e-833add188eb8.png">
   
   <img width="1021" alt="image" src="https://user-images.githubusercontent.com/39366025/220117705-40fedc9a-7b8c-4701-a3e6-bf7c39948b4e.png">
   
   
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #4460: feat(bamboo): add plan and job build

Posted by "likyh (via GitHub)" <gi...@apache.org>.
likyh commented on code in PR #4460:
URL: https://github.com/apache/incubator-devlake/pull/4460#discussion_r1111977157


##########
backend/plugins/bamboo/tasks/plan_build_collector.go:
##########
@@ -0,0 +1,109 @@
+/*
+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"
+	"fmt"
+	"github.com/apache/incubator-devlake/core/dal"
+	"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"
+	"net/http"
+	"net/url"
+	"reflect"
+)
+
+const RAW_PLAN_BUILD_TABLE = "bamboo_plan_build"
+
+var _ plugin.SubTaskEntryPoint = CollectPlanBuild
+
+func CollectPlanBuild(taskCtx plugin.SubTaskContext) errors.Error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PLAN_BUILD_TABLE)
+	db := taskCtx.GetDal()
+	collectorWithState, err := helper.NewApiCollectorWithState(*rawDataSubTaskArgs, nil)
+	if err != nil {
+		return err
+	}
+	clauses := []dal.Clause{
+		dal.Select("plan_key"),
+		dal.From(models.BambooPlan{}.TableName()),
+		dal.Where("project_key = ? and connection_id=?", data.Options.ProjectKey, data.Options.ConnectionId),
+	}
+	cursor, err := db.Cursor(
+		clauses...,
+	)
+	if err != nil {
+		return err
+	}
+	iterator, err := helper.NewDalCursorIterator(db, cursor, reflect.TypeOf(SimplePlan{}))
+	if err != nil {
+		return err
+	}
+
+	err = collectorWithState.InitCollector(helper.ApiCollectorArgs{
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Input:       iterator,
+		UrlTemplate: "result/{{ .Input.PlanKey }}.json",
+		Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
+			query := url.Values{}
+			query.Set("showEmpty", fmt.Sprintf("%v", true))
+			query.Set("expand", "results.result.vcsRevisions")
+			query.Set("max-result", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("start-index", fmt.Sprintf("%v", (reqData.Pager.Page-1)*reqData.Pager.Size))

Review Comment:
   `(reqData.Pager.Page-1)*reqData.Pager.Size` -> `reqData.Pager.Skip`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] warren830 merged pull request #4460: feat(bamboo): add plan and job build

Posted by "warren830 (via GitHub)" <gi...@apache.org>.
warren830 merged PR #4460:
URL: https://github.com/apache/incubator-devlake/pull/4460


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #4460: feat(bamboo): add plan and job build

Posted by "likyh (via GitHub)" <gi...@apache.org>.
likyh commented on code in PR #4460:
URL: https://github.com/apache/incubator-devlake/pull/4460#discussion_r1111977761


##########
backend/plugins/bamboo/tasks/job_build_collector.go:
##########
@@ -0,0 +1,115 @@
+/*
+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"
+	"fmt"
+	"github.com/apache/incubator-devlake/core/dal"
+	"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"
+	"net/http"
+	"net/url"
+	"reflect"
+)
+
+const RAW_JOB_BUILD_TABLE = "bamboo_job_build"
+
+var _ plugin.SubTaskEntryPoint = CollectJobBuild
+
+type SimpleJob struct {
+	JobKey   string
+	PlanName string
+	PlanKey  string
+}
+
+func CollectJobBuild(taskCtx plugin.SubTaskContext) errors.Error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_JOB_BUILD_TABLE)
+	db := taskCtx.GetDal()
+	collectorWithState, err := helper.NewApiCollectorWithState(*rawDataSubTaskArgs, nil)
+	if err != nil {
+		return err
+	}
+	clauses := []dal.Clause{
+		dal.Select("job_key, plan_name, plan_key"),
+		dal.From(models.BambooJob{}.TableName()),
+		dal.Where("project_key = ? and connection_id=?", data.Options.ProjectKey, data.Options.ConnectionId),
+	}
+	cursor, err := db.Cursor(
+		clauses...,
+	)
+	if err != nil {
+		return err
+	}
+	iterator, err := helper.NewDalCursorIterator(db, cursor, reflect.TypeOf(SimpleJob{}))
+	if err != nil {
+		return err
+	}
+
+	err = collectorWithState.InitCollector(helper.ApiCollectorArgs{
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Input:       iterator,
+		UrlTemplate: "result/{{ .Input.JobKey }}.json",
+		Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
+			query := url.Values{}
+			query.Set("showEmpty", fmt.Sprintf("%v", true))
+			query.Set("expand", "results.result.vcsRevisions")
+			query.Set("max-result", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("start-index", fmt.Sprintf("%v", (reqData.Pager.Page-1)*reqData.Pager.Size))

Review Comment:
   same above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org