This is an automated email from the ASF dual-hosted git repository.
zhangliang2022 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 96f426b9 feat(tapd): add story status last step (#3347)
96f426b9 is described below
commit 96f426b92fee938479666aa0ae9037f6753d9a2a
Author: Warren Chen <[email protected]>
AuthorDate: Sun Oct 9 19:22:33 2022 +0800
feat(tapd): add story status last step (#3347)
---
plugins/tapd/impl/impl.go | 2 +
.../tapd/tasks/story_status_last_step_collector.go | 64 ++++++++++++++++++
.../tapd/tasks/story_status_last_step_enricher.go | 78 ++++++++++++++++++++++
plugins/tapd/tasks/task_extractor.go | 4 +-
4 files changed, 146 insertions(+), 2 deletions(-)
diff --git a/plugins/tapd/impl/impl.go b/plugins/tapd/impl/impl.go
index bf18d0d4..e38c3537 100644
--- a/plugins/tapd/impl/impl.go
+++ b/plugins/tapd/impl/impl.go
@@ -111,6 +111,8 @@ func (plugin Tapd) SubTaskMetas() []core.SubTaskMeta {
tasks.ExtractStoryCategoriesMeta,
tasks.CollectStoryStatusMeta,
tasks.ExtractStoryStatusMeta,
+ tasks.CollectStoryStatusLastStepMeta,
+ tasks.EnrichStoryStatusLastStepMeta,
tasks.CollectBugStatusMeta,
tasks.ExtractBugStatusMeta,
tasks.CollectAccountsMeta,
diff --git a/plugins/tapd/tasks/story_status_last_step_collector.go
b/plugins/tapd/tasks/story_status_last_step_collector.go
new file mode 100644
index 00000000..63faec94
--- /dev/null
+++ b/plugins/tapd/tasks/story_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_STORY_STATUS_LAST_STEP_TABLE = "tapd_api_story_status_last_steps"
+
+var _ core.SubTaskEntryPoint = CollectStoryStatusLastStep
+
+func CollectStoryStatusLastStep(taskCtx core.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RAW_STORY_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", "story")
+ return query, nil
+ },
+ ResponseParser: GetRawMessageDirectFromResponse,
+ })
+ if err != nil {
+ logger.Error(err, "collect story workflow last steps")
+ return err
+ }
+ return collector.Execute()
+}
+
+var CollectStoryStatusLastStepMeta = core.SubTaskMeta{
+ Name: "collectStoryStatusLastStep",
+ EntryPoint: CollectStoryStatusLastStep,
+ EnabledByDefault: true,
+ Description: "collect Tapd bugStatus",
+ DomainTypes: []string{core.DOMAIN_TYPE_TICKET},
+}
diff --git a/plugins/tapd/tasks/story_status_last_step_enricher.go
b/plugins/tapd/tasks/story_status_last_step_enricher.go
new file mode 100644
index 00000000..9c5e7c4e
--- /dev/null
+++ b/plugins/tapd/tasks/story_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 = EnrichStoryStatusLastStep
+
+var EnrichStoryStatusLastStepMeta = core.SubTaskMeta{
+ Name: "enrichStoryStatusLastStep",
+ EntryPoint: EnrichStoryStatusLastStep,
+ EnabledByDefault: true,
+ Description: "Enrich raw data into tool layer table
_tool_tapd_story_status",
+ DomainTypes: []string{core.DOMAIN_TYPE_TICKET},
+}
+
+func EnrichStoryStatusLastStep(taskCtx core.SubTaskContext) errors.Error {
+ db := taskCtx.GetDal()
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RAW_STORY_STATUS_LAST_STEP_TABLE, false)
+ extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+ Extract: func(row *helper.RawData) ([]interface{},
errors.Error) {
+ var storyStatusLastStepRes struct {
+ Data map[string]string
+ }
+ err := errors.Convert(json.Unmarshal(row.Data,
&storyStatusLastStepRes))
+ if err != nil {
+ return nil, err
+ }
+ results := make([]interface{}, 0)
+ statusList := make([]*models.TapdStoryStatus, 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
storyStatusLastStepRes.Data[status.EnglishName] != "" {
+ status.IsLastStep = true
+ results = append(results, status)
+ }
+ }
+
+ return results, nil
+ },
+ })
+
+ if err != nil {
+ return err
+ }
+
+ return extractor.Execute()
+}
diff --git a/plugins/tapd/tasks/task_extractor.go
b/plugins/tapd/tasks/task_extractor.go
index 55deecaf..75b803da 100644
--- a/plugins/tapd/tasks/task_extractor.go
+++ b/plugins/tapd/tasks/task_extractor.go
@@ -41,7 +41,7 @@ var ExtractTaskMeta = core.SubTaskMeta{
func ExtractTasks(taskCtx core.SubTaskContext) errors.Error {
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RAW_TASK_TABLE, false)
- getStdStatus := func(statusKey string) string {
+ getTaskStdStatus := func(statusKey string) string {
if statusKey == "done" {
return ticket.DONE
} else if statusKey == "progressing" {
@@ -67,7 +67,7 @@ func ExtractTasks(taskCtx core.SubTaskContext) errors.Error {
toolL.ConnectionId = data.Options.ConnectionId
toolL.Type = "TASK"
toolL.StdType = "TASK"
- toolL.StdStatus = getStdStatus(toolL.Status)
+ toolL.StdStatus = getTaskStdStatus(toolL.Status)
if strings.Contains(toolL.Owner, ";") {
toolL.Owner = strings.Split(toolL.Owner, ";")[0]
}