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 2022/10/09 12:03:22 UTC

[incubator-devlake] branch main updated: feat(tapd): add bug status last step

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 22ebdd31 feat(tapd): add bug status last step
22ebdd31 is described below

commit 22ebdd31407bb5781c7fd97c782fbc9e2ef5d651
Author: Yingchu Chen <yi...@merico.dev>
AuthorDate: Sun Oct 9 19:22:20 2022 +0800

    feat(tapd): add bug status last step
---
 plugins/tapd/impl/impl.go                          |  2 +
 .../tapd/tasks/bug_status_last_step_collector.go   | 64 ++++++++++++++++++
 .../tapd/tasks/bug_status_last_step_enricher.go    | 78 ++++++++++++++++++++++
 3 files changed, 144 insertions(+)

diff --git a/plugins/tapd/impl/impl.go b/plugins/tapd/impl/impl.go
index e38c3537..89bcce32 100644
--- a/plugins/tapd/impl/impl.go
+++ b/plugins/tapd/impl/impl.go
@@ -115,6 +115,8 @@ func (plugin Tapd) SubTaskMetas() []core.SubTaskMeta {
 		tasks.EnrichStoryStatusLastStepMeta,
 		tasks.CollectBugStatusMeta,
 		tasks.ExtractBugStatusMeta,
+		tasks.CollectBugStatusLastStepMeta,
+		tasks.EnrichBugStatusLastStepMeta,
 		tasks.CollectAccountsMeta,
 		tasks.ExtractAccountsMeta,
 		tasks.CollectIterationMeta,
diff --git a/plugins/tapd/tasks/bug_status_last_step_collector.go b/plugins/tapd/tasks/bug_status_last_step_collector.go
new file mode 100644
index 00000000..da7cc573
--- /dev/null
+++ b/plugins/tapd/tasks/bug_status_last_step_collector.go
@@ -0,0 +1,64 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/errors"
+	"net/url"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+const RAW_BUG_STATUS_LAST_STEP_TABLE = "tapd_api_bug_status_last_steps"
+
+var _ core.SubTaskEntryPoint = CollectBugStatusLastStep
+
+func CollectBugStatusLastStep(taskCtx core.SubTaskContext) errors.Error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_BUG_STATUS_LAST_STEP_TABLE, false)
+	logger := taskCtx.GetLogger()
+	logger.Info("collect bugStatus")
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		ApiClient:          data.ApiClient,
+		PageSize:           100,
+		UrlTemplate:        "workflows/last_steps",
+		Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
+			query := url.Values{}
+			query.Set("workspace_id", fmt.Sprintf("%v", data.Options.WorkspaceId))
+			query.Set("system", "bug")
+			return query, nil
+		},
+		ResponseParser: GetRawMessageDirectFromResponse,
+	})
+	if err != nil {
+		logger.Error(err, "collect bug workflow last steps")
+		return err
+	}
+	return collector.Execute()
+}
+
+var CollectBugStatusLastStepMeta = core.SubTaskMeta{
+	Name:             "collectBugStatusLastStep",
+	EntryPoint:       CollectBugStatusLastStep,
+	EnabledByDefault: true,
+	Description:      "collect Tapd bugStatus",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET},
+}
diff --git a/plugins/tapd/tasks/bug_status_last_step_enricher.go b/plugins/tapd/tasks/bug_status_last_step_enricher.go
new file mode 100644
index 00000000..06f49ddb
--- /dev/null
+++ b/plugins/tapd/tasks/bug_status_last_step_enricher.go
@@ -0,0 +1,78 @@
+/*
+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/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/tapd/models"
+)
+
+var _ core.SubTaskEntryPoint = EnrichBugStatusLastStep
+
+var EnrichBugStatusLastStepMeta = core.SubTaskMeta{
+	Name:             "enrichBugStatusLastStep",
+	EntryPoint:       EnrichBugStatusLastStep,
+	EnabledByDefault: true,
+	Description:      "Enrich raw data into tool layer table _tool_tapd_bug_status",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET},
+}
+
+func EnrichBugStatusLastStep(taskCtx core.SubTaskContext) errors.Error {
+	db := taskCtx.GetDal()
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_BUG_STATUS_LAST_STEP_TABLE, false)
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		Extract: func(row *helper.RawData) ([]interface{}, errors.Error) {
+			var bugStatusLastStepRes struct {
+				Data map[string]string
+			}
+			err := errors.Convert(json.Unmarshal(row.Data, &bugStatusLastStepRes))
+			if err != nil {
+				return nil, err
+			}
+			results := make([]interface{}, 0)
+			statusList := make([]*models.TapdBugStatus, 0)
+			clauses := []dal.Clause{
+				dal.Where("connection_id = ? and workspace_id = ?", data.Options.ConnectionId, data.Options.WorkspaceId),
+			}
+			err = db.All(&statusList, clauses...)
+			if err != nil {
+				return nil, err
+			}
+
+			for _, status := range statusList {
+				if bugStatusLastStepRes.Data[status.EnglishName] != "" {
+					status.IsLastStep = true
+					results = append(results, status)
+				}
+			}
+
+			return results, nil
+		},
+	})
+
+	if err != nil {
+		return err
+	}
+
+	return extractor.Execute()
+}