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/09/24 14:06:13 UTC

[incubator-devlake] branch feat-plugin-zentao updated (9b34e558 -> 3d881101)

This is an automated email from the ASF dual-hosted git repository.

warren pushed a change to branch feat-plugin-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


    from 9b34e558 feat:add zentao project extractor
     new f32f638d fix(zentao): fix minor issues
     new 8863a05f feat(zentao): add execution
     new 3d881101 feat(zentao): fix execution time

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plugins/helper/iso8601time.go                      |  31 +++++
 plugins/zentao/impl/impl.go                        |   3 +
 plugins/zentao/models/archived/execution.go        | 151 +++++++++++++++++++++
 plugins/zentao/models/archived/project.go          |  58 ++++----
 plugins/zentao/models/execution.go                 | 151 +++++++++++++++++++++
 .../migrationscripts/20220906_add_init_tables.go   |   5 +-
 plugins/zentao/models/{archived => }/project.go    |  56 ++++----
 ...project_collector.go => execution_collector.go} |  36 +++--
 .../tasks/execution_convertor.go}                  |  74 +++++-----
 ...project_extractor.go => execution_extractor.go} |  32 +++--
 plugins/zentao/tasks/project_extractor.go          |   4 +-
 11 files changed, 477 insertions(+), 124 deletions(-)
 create mode 100644 plugins/zentao/models/archived/execution.go
 create mode 100644 plugins/zentao/models/execution.go
 copy plugins/zentao/models/{archived => }/project.go (71%)
 copy plugins/zentao/tasks/{project_collector.go => execution_collector.go} (69%)
 copy plugins/{jira/tasks/board_convertor.go => zentao/tasks/execution_convertor.go} (50%)
 copy plugins/zentao/tasks/{project_extractor.go => execution_extractor.go} (65%)


[incubator-devlake] 01/03: fix(zentao): fix minor issues

Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

warren pushed a commit to branch feat-plugin-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit f32f638df815e5990abc92ab5e0a6b04c736cd0c
Author: Yingchu Chen <yi...@merico.dev>
AuthorDate: Sun Sep 18 21:40:57 2022 +0800

    fix(zentao): fix minor issues
---
 plugins/zentao/models/archived/project.go       | 54 ++++++++++++-------------
 plugins/zentao/models/{archived => }/project.go | 52 ++++++++++++------------
 plugins/zentao/tasks/project_extractor.go       |  4 +-
 3 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/plugins/zentao/models/archived/project.go b/plugins/zentao/models/archived/project.go
index db79cceb..63c498dd 100644
--- a/plugins/zentao/models/archived/project.go
+++ b/plugins/zentao/models/archived/project.go
@@ -18,12 +18,12 @@ limitations under the License.
 package archived
 
 import (
-	"github.com/apache/incubator-devlake/models/common"
+	"github.com/apache/incubator-devlake/models/migrationscripts/archived"
 	"time"
 )
 
 type ZentaoProject struct {
-	common.NoPKModel
+	archived.NoPKModel
 	ConnectionId  uint64 `gorm:"primaryKey;type:BIGINT  NOT NULL"`
 	ID            int    `json:"id"`
 	Project       int    `json:"project"`
@@ -56,31 +56,31 @@ type ZentaoProject struct {
 	PlanDuration  int    `json:"planDuration"`
 	RealDuration  int    `json:"realDuration"`
 	//OpenedBy       string    `json:"openedBy"`
-	OpenedDate     time.Time `json:"openedDate"`
-	OpenedVersion  string    `json:"openedVersion"`
-	LastEditedBy   string    `json:"lastEditedBy"`
-	LastEditedDate time.Time `json:"lastEditedDate"`
-	//ClosedBy       string    `json:"closedBy"`
-	//ClosedDate     string    `json:"closedDate"`
-	//CanceledBy string `json:"canceledBy"`
-	//CanceledDate   string    `json:"canceledDate"`
-	SuspendedDate string `json:"suspendedDate"`
-	PO            string `json:"PO"`
-	PM            `json:"PM"`
-	QD            string `json:"QD"`
-	RD            string `json:"RD"`
-	Team          string `json:"team"`
-	Acl           string `json:"acl"`
-	Whitelist     `json:"whitelist" gorm:"-"`
-	Order         int    `json:"order"`
-	Vision        string `json:"vision"`
-	DisplayCards  int    `json:"displayCards"`
-	FluidBoard    string `json:"fluidBoard"`
-	Deleted       bool   `json:"deleted"`
-	Delay         int    `json:"delay"`
-	Hours         `json:"hours"`
-	TeamCount     int    `json:"teamCount"`
-	LeftTasks     string `json:"leftTasks"`
+	OpenedDate     time.Time  `json:"openedDate"`
+	OpenedVersion  string     `json:"openedVersion"`
+	LastEditedBy   string     `json:"lastEditedBy"`
+	LastEditedDate *time.Time `json:"lastEditedDate"`
+	ClosedBy       string     `json:"closedBy"`
+	ClosedDate     *time.Time `json:"closedDate"`
+	CanceledBy     string     `json:"canceledBy"`
+	CanceledDate   *time.Time `json:"canceledDate"`
+	SuspendedDate  string     `json:"suspendedDate"`
+	PO             string     `json:"PO"`
+	PM             `json:"PM"`
+	QD             string `json:"QD"`
+	RD             string `json:"RD"`
+	Team           string `json:"team"`
+	Acl            string `json:"acl"`
+	Whitelist      `json:"whitelist" gorm:"-"`
+	Order          int    `json:"order"`
+	Vision         string `json:"vision"`
+	DisplayCards   int    `json:"displayCards"`
+	FluidBoard     string `json:"fluidBoard"`
+	Deleted        bool   `json:"deleted"`
+	Delay          int    `json:"delay"`
+	Hours          `json:"hours"`
+	TeamCount      int    `json:"teamCount"`
+	LeftTasks      string `json:"leftTasks"`
 	//TeamMembers   []interface{} `json:"teamMembers" gorm:"-"`
 	TotalEstimate int `json:"totalEstimate"`
 	TotalConsumed int `json:"totalConsumed"`
diff --git a/plugins/zentao/models/archived/project.go b/plugins/zentao/models/project.go
similarity index 73%
copy from plugins/zentao/models/archived/project.go
copy to plugins/zentao/models/project.go
index db79cceb..5a51d738 100644
--- a/plugins/zentao/models/archived/project.go
+++ b/plugins/zentao/models/project.go
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package archived
+package models
 
 import (
 	"github.com/apache/incubator-devlake/models/common"
@@ -56,31 +56,31 @@ type ZentaoProject struct {
 	PlanDuration  int    `json:"planDuration"`
 	RealDuration  int    `json:"realDuration"`
 	//OpenedBy       string    `json:"openedBy"`
-	OpenedDate     time.Time `json:"openedDate"`
-	OpenedVersion  string    `json:"openedVersion"`
-	LastEditedBy   string    `json:"lastEditedBy"`
-	LastEditedDate time.Time `json:"lastEditedDate"`
-	//ClosedBy       string    `json:"closedBy"`
-	//ClosedDate     string    `json:"closedDate"`
-	//CanceledBy string `json:"canceledBy"`
-	//CanceledDate   string    `json:"canceledDate"`
-	SuspendedDate string `json:"suspendedDate"`
-	PO            string `json:"PO"`
-	PM            `json:"PM"`
-	QD            string `json:"QD"`
-	RD            string `json:"RD"`
-	Team          string `json:"team"`
-	Acl           string `json:"acl"`
-	Whitelist     `json:"whitelist" gorm:"-"`
-	Order         int    `json:"order"`
-	Vision        string `json:"vision"`
-	DisplayCards  int    `json:"displayCards"`
-	FluidBoard    string `json:"fluidBoard"`
-	Deleted       bool   `json:"deleted"`
-	Delay         int    `json:"delay"`
-	Hours         `json:"hours"`
-	TeamCount     int    `json:"teamCount"`
-	LeftTasks     string `json:"leftTasks"`
+	OpenedDate     time.Time  `json:"openedDate"`
+	OpenedVersion  string     `json:"openedVersion"`
+	LastEditedBy   string     `json:"lastEditedBy"`
+	LastEditedDate *time.Time `json:"lastEditedDate,string"`
+	ClosedBy       string     `json:"closedBy"`
+	ClosedDate     *time.Time `json:"closedDate,string"`
+	CanceledBy     string     `json:"canceledBy"`
+	CanceledDate   *time.Time `json:"canceledDate,string"`
+	SuspendedDate  string     `json:"suspendedDate"`
+	PO             string     `json:"PO"`
+	PM             `json:"PM"`
+	QD             string `json:"QD"`
+	RD             string `json:"RD"`
+	Team           string `json:"team"`
+	Acl            string `json:"acl"`
+	Whitelist      `json:"whitelist" gorm:"-"`
+	Order          int    `json:"order"`
+	Vision         string `json:"vision"`
+	DisplayCards   int    `json:"displayCards"`
+	FluidBoard     string `json:"fluidBoard"`
+	Deleted        bool   `json:"deleted"`
+	Delay          int    `json:"delay"`
+	Hours          `json:"hours"`
+	TeamCount      int    `json:"teamCount"`
+	LeftTasks      string `json:"leftTasks"`
 	//TeamMembers   []interface{} `json:"teamMembers" gorm:"-"`
 	TotalEstimate int `json:"totalEstimate"`
 	TotalConsumed int `json:"totalConsumed"`
diff --git a/plugins/zentao/tasks/project_extractor.go b/plugins/zentao/tasks/project_extractor.go
index 6cc9d9e5..a1388efa 100644
--- a/plugins/zentao/tasks/project_extractor.go
+++ b/plugins/zentao/tasks/project_extractor.go
@@ -21,7 +21,7 @@ import (
 	"encoding/json"
 	"github.com/apache/incubator-devlake/plugins/core"
 	"github.com/apache/incubator-devlake/plugins/helper"
-	"github.com/apache/incubator-devlake/plugins/zentao/models/archived"
+	"github.com/apache/incubator-devlake/plugins/zentao/models"
 )
 
 var _ core.SubTaskEntryPoint = ExtractProjects
@@ -43,7 +43,7 @@ func ExtractProjects(taskCtx core.SubTaskContext) error {
 			Table:  RAW_PROJECT_TABLE,
 		},
 		Extract: func(row *helper.RawData) ([]interface{}, error) {
-			project := &archived.ZentaoProject{}
+			project := &models.ZentaoProject{}
 			err := json.Unmarshal(row.Data, project)
 			if err != nil {
 				return nil, err


[incubator-devlake] 02/03: feat(zentao): add execution

Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

warren pushed a commit to branch feat-plugin-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 8863a05ff2c22b00f69f0264bf0d6ae5abca0d5e
Author: Yingchu Chen <yi...@merico.dev>
AuthorDate: Mon Sep 19 10:38:53 2022 +0800

    feat(zentao): add execution
---
 plugins/zentao/impl/impl.go                        |   2 +
 plugins/zentao/models/archived/execution.go        | 151 +++++++++++++++++++++
 plugins/zentao/models/execution.go                 | 151 +++++++++++++++++++++
 .../migrationscripts/20220906_add_init_tables.go   |   5 +-
 plugins/zentao/tasks/execution_collector.go        |  79 +++++++++++
 plugins/zentao/tasks/execution_extractor.go        |  67 +++++++++
 6 files changed, 453 insertions(+), 2 deletions(-)

diff --git a/plugins/zentao/impl/impl.go b/plugins/zentao/impl/impl.go
index f24f6afe..920bced0 100644
--- a/plugins/zentao/impl/impl.go
+++ b/plugins/zentao/impl/impl.go
@@ -54,6 +54,8 @@ func (plugin Zentao) SubTaskMetas() []core.SubTaskMeta {
 	return []core.SubTaskMeta{
 		tasks.CollectProjectMeta,
 		tasks.ExtractProjectsMeta,
+		tasks.CollectExecutionMeta,
+		tasks.ExtractExecutionsMeta,
 	}
 }
 
diff --git a/plugins/zentao/models/archived/execution.go b/plugins/zentao/models/archived/execution.go
new file mode 100644
index 00000000..787527c1
--- /dev/null
+++ b/plugins/zentao/models/archived/execution.go
@@ -0,0 +1,151 @@
+package archived
+
+import (
+	"github.com/apache/incubator-devlake/models/migrationscripts/archived"
+	"time"
+)
+
+type ZentaoExecution struct {
+	ConnectionId   uint64 `gorm:"primaryKey"`
+	Id             uint64 `json:"id"`
+	Project        uint64 `json:"project"`
+	Model          string `json:"model"`
+	Type           string `json:"type"`
+	Lifetime       string `json:"lifetime"`
+	Budget         string `json:"budget"`
+	BudgetUnit     string `json:"budgetUnit"`
+	Attribute      string `json:"attribute"`
+	Percent        int    `json:"percent"`
+	Milestone      string `json:"milestone"`
+	Output         string `json:"output"`
+	Auth           string `json:"auth"`
+	Parent         int    `json:"parent"`
+	Path           string `json:"path"`
+	Grade          int    `json:"grade"`
+	Name           string `json:"name"`
+	Code           string `json:"code"`
+	Begin          string `json:"begin"`
+	End            string `json:"end"`
+	RealBegan      string `json:"realBegan"`
+	RealEnd        string `json:"realEnd"`
+	Days           int    `json:"days"`
+	Status         string `json:"status"`
+	SubStatus      string `json:"subStatus"`
+	Pri            string `json:"pri"`
+	Desc           string `json:"desc"`
+	Version        int    `json:"version"`
+	ParentVersion  int    `json:"parentVersion"`
+	PlanDuration   int    `json:"planDuration"`
+	RealDuration   int    `json:"realDuration"`
+	OpenedBy       `json:"openedBy"`
+	OpenedDate     time.Time `json:"openedDate"`
+	OpenedVersion  string    `json:"openedVersion"`
+	LastEditedBy   `json:"lastEditedBy"`
+	LastEditedDate time.Time `json:"lastEditedDate"`
+	ClosedBy       `json:"closedBy"`
+	ClosedDate     time.Time `json:"closedDate"`
+	CanceledBy     `json:"canceledBy"`
+	CanceledDate   time.Time `json:"canceledDate"`
+	SuspendedDate  string    `json:"suspendedDate"`
+	PO             `json:"PO"`
+	PM             `json:"PM"`
+	QD             `json:"QD"`
+	RD             `json:"RD"`
+	Team           string `json:"team"`
+	Acl            string `json:"acl"`
+	//Whitelist      []Whitelist  `json:"whitelist" gorm:"-:all"`
+	Order         int          `json:"order"`
+	Vision        string       `json:"vision"`
+	DisplayCards  int          `json:"displayCards"`
+	FluidBoard    string       `json:"fluidBoard"`
+	Deleted       bool         `json:"deleted"`
+	TotalHours    int          `json:"totalHours"`
+	TotalEstimate int          `json:"totalEstimate"`
+	TotalConsumed int          `json:"totalConsumed"`
+	TotalLeft     int          `json:"totalLeft"`
+	ProjectInfo   bool         `json:"projectInfo"`
+	Progress      int          `json:"progress"`
+	TeamMembers   []TeamMember `json:"teamMembers" gorm:"-:all"`
+	Products      []Product    `json:"products" gorm:"-:all"`
+	CaseReview    bool         `json:"caseReview"`
+	archived.NoPKModel
+}
+
+type OpenedBy struct {
+	OpenedByID       int    `json:"id"`
+	OpenedByAccount  string `json:"account"`
+	OpenedByAvatar   string `json:"avatar"`
+	OpenedByRealname string `json:"realname"`
+}
+
+type LastEditedBy struct {
+	LastEditedByID       int    `json:"id"`
+	LastEditedByAccount  string `json:"account"`
+	LastEditedByAvatar   string `json:"avatar"`
+	LastEditedByRealname string `json:"realname"`
+}
+
+type ClosedBy struct {
+	ClosedByID       int    `json:"id"`
+	ClosedByAccount  string `json:"account"`
+	ClosedByAvatar   string `json:"avatar"`
+	ClosedByRealname string `json:"realname"`
+}
+
+type CanceledBy struct {
+	CanceledByID       int    `json:"id"`
+	CanceledByAccount  string `json:"account"`
+	CanceledByAvatar   string `json:"avatar"`
+	CanceledByRealname string `json:"realname"`
+}
+
+type PO struct {
+	PoID       int    `json:"id"`
+	PoAccount  string `json:"account"`
+	PoAvatar   string `json:"avatar"`
+	PoRealname string `json:"realname"`
+}
+
+type QD struct {
+	ID       int    `json:"id"`
+	Account  string `json:"account"`
+	Avatar   string `json:"avatar"`
+	Realname string `json:"realname"`
+}
+
+type RD struct {
+	ID       int    `json:"id"`
+	Account  string `json:"account"`
+	Avatar   string `json:"avatar"`
+	Realname string `json:"realname"`
+}
+
+type Product struct {
+	ID    int           `json:"id"`
+	Name  string        `json:"name"`
+	Plans []interface{} `json:"plans"`
+}
+
+type TeamMember struct {
+	ID         int    `json:"id"`
+	Root       int    `json:"root"`
+	Type       string `json:"type"`
+	Account    string `json:"account"`
+	Role       string `json:"role"`
+	Position   string `json:"position"`
+	Limited    string `json:"limited"`
+	Join       string `json:"join"`
+	Days       int    `json:"days"`
+	Hours      int    `json:"hours"`
+	Estimate   string `json:"estimate"`
+	Consumed   string `json:"consumed"`
+	Left       string `json:"left"`
+	Order      int    `json:"order"`
+	TotalHours int    `json:"totalHours"`
+	UserID     int    `json:"userID"`
+	Realname   string `json:"realname"`
+}
+
+func (ZentaoExecution) TableName() string {
+	return "_tool_zentao_execution"
+}
diff --git a/plugins/zentao/models/execution.go b/plugins/zentao/models/execution.go
new file mode 100644
index 00000000..e51102cf
--- /dev/null
+++ b/plugins/zentao/models/execution.go
@@ -0,0 +1,151 @@
+package models
+
+import (
+	"github.com/apache/incubator-devlake/models/common"
+	"time"
+)
+
+type ZentaoExecution struct {
+	ConnectionId   uint64 `gorm:"primaryKey"`
+	Id             uint64 `json:"id"`
+	Project        uint64 `json:"project"`
+	Model          string `json:"model"`
+	Type           string `json:"type"`
+	Lifetime       string `json:"lifetime"`
+	Budget         string `json:"budget"`
+	BudgetUnit     string `json:"budgetUnit"`
+	Attribute      string `json:"attribute"`
+	Percent        int    `json:"percent"`
+	Milestone      string `json:"milestone"`
+	Output         string `json:"output"`
+	Auth           string `json:"auth"`
+	Parent         int    `json:"parent"`
+	Path           string `json:"path"`
+	Grade          int    `json:"grade"`
+	Name           string `json:"name"`
+	Code           string `json:"code"`
+	Begin          string `json:"begin"`
+	End            string `json:"end"`
+	RealBegan      string `json:"realBegan"`
+	RealEnd        string `json:"realEnd"`
+	Days           int    `json:"days"`
+	Status         string `json:"status"`
+	SubStatus      string `json:"subStatus"`
+	Pri            string `json:"pri"`
+	Desc           string `json:"desc"`
+	Version        int    `json:"version"`
+	ParentVersion  int    `json:"parentVersion"`
+	PlanDuration   int    `json:"planDuration"`
+	RealDuration   int    `json:"realDuration"`
+	OpenedBy       `json:"openedBy"`
+	OpenedDate     time.Time `json:"openedDate"`
+	OpenedVersion  string    `json:"openedVersion"`
+	LastEditedBy   `json:"lastEditedBy"`
+	LastEditedDate time.Time `json:"lastEditedDate"`
+	ClosedBy       `json:"closedBy"`
+	ClosedDate     time.Time `json:"closedDate"`
+	CanceledBy     `json:"canceledBy"`
+	CanceledDate   time.Time `json:"canceledDate"`
+	SuspendedDate  string    `json:"suspendedDate"`
+	PO             `json:"PO"`
+	PM             `json:"PM"`
+	QD             `json:"QD"`
+	RD             `json:"RD"`
+	Team           string `json:"team"`
+	Acl            string `json:"acl"`
+	//Whitelist      []Whitelist  `json:"whitelist" gorm:"-:all"`
+	Order         int          `json:"order"`
+	Vision        string       `json:"vision"`
+	DisplayCards  int          `json:"displayCards"`
+	FluidBoard    string       `json:"fluidBoard"`
+	Deleted       bool         `json:"deleted"`
+	TotalHours    int          `json:"totalHours"`
+	TotalEstimate int          `json:"totalEstimate"`
+	TotalConsumed int          `json:"totalConsumed"`
+	TotalLeft     int          `json:"totalLeft"`
+	ProjectInfo   bool         `json:"projectInfo"`
+	Progress      int          `json:"progress"`
+	TeamMembers   []TeamMember `json:"teamMembers" gorm:"-:all"`
+	Products      []Product    `json:"products" gorm:"-:all"`
+	CaseReview    bool         `json:"caseReview"`
+	common.NoPKModel
+}
+
+func (ZentaoExecution) TableName() string {
+	return "_tool_zentao_execution"
+}
+
+type OpenedBy struct {
+	OpenedByID       int    `json:"id"`
+	OpenedByAccount  string `json:"account"`
+	OpenedByAvatar   string `json:"avatar"`
+	OpenedByRealname string `json:"realname"`
+}
+
+type LastEditedBy struct {
+	LastEditedByID       int    `json:"id"`
+	LastEditedByAccount  string `json:"account"`
+	LastEditedByAvatar   string `json:"avatar"`
+	LastEditedByRealname string `json:"realname"`
+}
+
+type ClosedBy struct {
+	ClosedByID       int    `json:"id"`
+	ClosedByAccount  string `json:"account"`
+	ClosedByAvatar   string `json:"avatar"`
+	ClosedByRealname string `json:"realname"`
+}
+
+type CanceledBy struct {
+	CanceledByID       int    `json:"id"`
+	CanceledByAccount  string `json:"account"`
+	CanceledByAvatar   string `json:"avatar"`
+	CanceledByRealname string `json:"realname"`
+}
+
+type PO struct {
+	PoID       int    `json:"id"`
+	PoAccount  string `json:"account"`
+	PoAvatar   string `json:"avatar"`
+	PoRealname string `json:"realname"`
+}
+
+type QD struct {
+	ID       int    `json:"id"`
+	Account  string `json:"account"`
+	Avatar   string `json:"avatar"`
+	Realname string `json:"realname"`
+}
+
+type RD struct {
+	ID       int    `json:"id"`
+	Account  string `json:"account"`
+	Avatar   string `json:"avatar"`
+	Realname string `json:"realname"`
+}
+
+type Product struct {
+	ID    int           `json:"id"`
+	Name  string        `json:"name"`
+	Plans []interface{} `json:"plans"`
+}
+
+type TeamMember struct {
+	ID         int    `json:"id"`
+	Root       int    `json:"root"`
+	Type       string `json:"type"`
+	Account    string `json:"account"`
+	Role       string `json:"role"`
+	Position   string `json:"position"`
+	Limited    string `json:"limited"`
+	Join       string `json:"join"`
+	Days       int    `json:"days"`
+	Hours      int    `json:"hours"`
+	Estimate   string `json:"estimate"`
+	Consumed   string `json:"consumed"`
+	Left       string `json:"left"`
+	Order      int    `json:"order"`
+	TotalHours int    `json:"totalHours"`
+	UserID     int    `json:"userID"`
+	Realname   string `json:"realname"`
+}
diff --git a/plugins/zentao/models/migrationscripts/20220906_add_init_tables.go b/plugins/zentao/models/migrationscripts/20220906_add_init_tables.go
index 1a743c46..6635dda3 100644
--- a/plugins/zentao/models/migrationscripts/20220906_add_init_tables.go
+++ b/plugins/zentao/models/migrationscripts/20220906_add_init_tables.go
@@ -27,8 +27,9 @@ type addInitTables struct{}
 
 func (u *addInitTables) Up(ctx context.Context, db *gorm.DB) error {
 	return db.Migrator().AutoMigrate(
-		archived.ZentaoConnection{},
-		archived.ZentaoProject{},
+		//archived.ZentaoConnection{},
+		//archived.ZentaoProject{},
+		archived.ZentaoExecution{},
 	)
 }
 
diff --git a/plugins/zentao/tasks/execution_collector.go b/plugins/zentao/tasks/execution_collector.go
new file mode 100644
index 00000000..b012084f
--- /dev/null
+++ b/plugins/zentao/tasks/execution_collector.go
@@ -0,0 +1,79 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"io"
+	"net/http"
+	"net/url"
+)
+
+const RAW_EXECUTION_TABLE = "zentao_execution"
+
+var _ core.SubTaskEntryPoint = CollectExecution
+
+func CollectExecution(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*ZentaoTaskData)
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: ZentaoApiParams{
+				ProductId:   data.Options.ProductId,
+				ExecutionId: data.Options.ExecutionId,
+				ProjectId:   data.Options.ProjectId,
+			},
+			Table: RAW_EXECUTION_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		Incremental: false,
+		PageSize:    100,
+		// TODO write which api would you want request
+		UrlTemplate: "executions/{{ .Params.ExecutionId }}",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
+			query.Set("limit", fmt.Sprintf("%v", reqData.Pager.Size))
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			body, err := io.ReadAll(res.Body)
+			res.Body.Close()
+			if err != nil {
+				return nil, err
+			}
+			return []json.RawMessage{body}, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+
+	return collector.Execute()
+}
+
+var CollectExecutionMeta = core.SubTaskMeta{
+	Name:             "CollectExecution",
+	EntryPoint:       CollectExecution,
+	EnabledByDefault: true,
+	Description:      "Collect Execution data from Zentao api",
+}
diff --git a/plugins/zentao/tasks/execution_extractor.go b/plugins/zentao/tasks/execution_extractor.go
new file mode 100644
index 00000000..f8b42226
--- /dev/null
+++ b/plugins/zentao/tasks/execution_extractor.go
@@ -0,0 +1,67 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/zentao/models"
+)
+
+var _ core.SubTaskEntryPoint = ExtractExecutions
+
+var ExtractExecutionsMeta = core.SubTaskMeta{
+	Name:             "extractExecutions",
+	EntryPoint:       ExtractExecutions,
+	EnabledByDefault: true,
+	Description:      "extract Zentao executions",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET},
+}
+
+func ExtractExecutions(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*ZentaoTaskData)
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: ZentaoApiParams{
+				ProductId:   data.Options.ProductId,
+				ExecutionId: data.Options.ExecutionId,
+				ProjectId:   data.Options.ProjectId,
+			},
+			Table: RAW_EXECUTION_TABLE,
+		},
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			execution := &models.ZentaoExecution{}
+			err := json.Unmarshal(row.Data, execution)
+			if err != nil {
+				return nil, err
+			}
+			execution.ConnectionId = data.Options.ConnectionId
+			results := make([]interface{}, 0)
+			results = append(results, execution)
+			return results, nil
+		},
+	})
+
+	if err != nil {
+		return err
+	}
+
+	return extractor.Execute()
+}


[incubator-devlake] 03/03: feat(zentao): fix execution time

Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

warren pushed a commit to branch feat-plugin-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 3d8811013f3816a7c41670b58c0aeba85cd152bd
Author: Yingchu Chen <yi...@merico.dev>
AuthorDate: Mon Sep 19 11:05:59 2022 +0800

    feat(zentao): fix execution time
---
 plugins/helper/iso8601time.go               | 31 ++++++++++
 plugins/zentao/impl/impl.go                 |  1 +
 plugins/zentao/models/archived/execution.go | 78 ++++++++++++-------------
 plugins/zentao/models/archived/project.go   |  4 +-
 plugins/zentao/models/execution.go          | 78 ++++++++++++-------------
 plugins/zentao/models/project.go            |  4 +-
 plugins/zentao/tasks/execution_convertor.go | 91 +++++++++++++++++++++++++++++
 7 files changed, 205 insertions(+), 82 deletions(-)

diff --git a/plugins/helper/iso8601time.go b/plugins/helper/iso8601time.go
index 5b02e9c9..a69e9b4a 100644
--- a/plugins/helper/iso8601time.go
+++ b/plugins/helper/iso8601time.go
@@ -18,6 +18,7 @@ limitations under the License.
 package helper
 
 import (
+	"database/sql/driver"
 	"fmt"
 	"regexp"
 	"strings"
@@ -63,6 +64,10 @@ func init() {
 			Matcher: regexp.MustCompile(`[+-][\d]{2}:[\d]{2}$`),
 			Format:  "2006-01-02T15:04:05-07:00",
 		},
+		{
+			Matcher: regexp.MustCompile(`[+-][\d]{2}-[\d]{2}$`),
+			Format:  "2006-01-02",
+		},
 	}
 }
 
@@ -131,3 +136,29 @@ func Iso8601TimeToTime(iso8601Time *Iso8601Time) *time.Time {
 	t := iso8601Time.ToTime()
 	return &t
 }
+
+// Value FIXME ...
+func (jt *Iso8601Time) Value() (driver.Value, error) {
+	if jt == nil {
+		return nil, nil
+	}
+	var zeroTime time.Time
+	t := jt.time
+	if t.UnixNano() == zeroTime.UnixNano() {
+		return nil, nil
+	}
+	return t, nil
+}
+
+// Scan FIXME ...
+func (jt *Iso8601Time) Scan(v interface{}) error {
+	value, ok := v.(time.Time)
+	if ok {
+		*jt = Iso8601Time{
+			time:   value,
+			format: time.RFC3339,
+		}
+		return nil
+	}
+	return fmt.Errorf("can not convert %v to timestamp", v)
+}
diff --git a/plugins/zentao/impl/impl.go b/plugins/zentao/impl/impl.go
index 920bced0..b4004753 100644
--- a/plugins/zentao/impl/impl.go
+++ b/plugins/zentao/impl/impl.go
@@ -56,6 +56,7 @@ func (plugin Zentao) SubTaskMetas() []core.SubTaskMeta {
 		tasks.ExtractProjectsMeta,
 		tasks.CollectExecutionMeta,
 		tasks.ExtractExecutionsMeta,
+		tasks.ConvertExecutionsMeta,
 	}
 }
 
diff --git a/plugins/zentao/models/archived/execution.go b/plugins/zentao/models/archived/execution.go
index 787527c1..7fe6cd16 100644
--- a/plugins/zentao/models/archived/execution.go
+++ b/plugins/zentao/models/archived/execution.go
@@ -2,51 +2,51 @@ package archived
 
 import (
 	"github.com/apache/incubator-devlake/models/migrationscripts/archived"
-	"time"
+	"github.com/apache/incubator-devlake/plugins/helper"
 )
 
 type ZentaoExecution struct {
-	ConnectionId   uint64 `gorm:"primaryKey"`
-	Id             uint64 `json:"id"`
-	Project        uint64 `json:"project"`
-	Model          string `json:"model"`
-	Type           string `json:"type"`
-	Lifetime       string `json:"lifetime"`
-	Budget         string `json:"budget"`
-	BudgetUnit     string `json:"budgetUnit"`
-	Attribute      string `json:"attribute"`
-	Percent        int    `json:"percent"`
-	Milestone      string `json:"milestone"`
-	Output         string `json:"output"`
-	Auth           string `json:"auth"`
-	Parent         int    `json:"parent"`
-	Path           string `json:"path"`
-	Grade          int    `json:"grade"`
-	Name           string `json:"name"`
-	Code           string `json:"code"`
-	Begin          string `json:"begin"`
-	End            string `json:"end"`
-	RealBegan      string `json:"realBegan"`
-	RealEnd        string `json:"realEnd"`
-	Days           int    `json:"days"`
-	Status         string `json:"status"`
-	SubStatus      string `json:"subStatus"`
-	Pri            string `json:"pri"`
-	Desc           string `json:"desc"`
-	Version        int    `json:"version"`
-	ParentVersion  int    `json:"parentVersion"`
-	PlanDuration   int    `json:"planDuration"`
-	RealDuration   int    `json:"realDuration"`
+	ConnectionId   uint64              `gorm:"primaryKey"`
+	Id             uint64              `json:"id" gorm:"primaryKey"`
+	Project        uint64              `json:"project"`
+	Model          string              `json:"model"`
+	Type           string              `json:"type"`
+	Lifetime       string              `json:"lifetime"`
+	Budget         string              `json:"budget"`
+	BudgetUnit     string              `json:"budgetUnit"`
+	Attribute      string              `json:"attribute"`
+	Percent        int                 `json:"percent"`
+	Milestone      string              `json:"milestone"`
+	Output         string              `json:"output"`
+	Auth           string              `json:"auth"`
+	Parent         int                 `json:"parent"`
+	Path           string              `json:"path"`
+	Grade          int                 `json:"grade"`
+	Name           string              `json:"name"`
+	Code           string              `json:"code"`
+	Begin          *helper.Iso8601Time `json:"begin"`
+	End            *helper.Iso8601Time `json:"end"`
+	RealBegan      *helper.Iso8601Time `json:"realBegan"`
+	RealEnd        *helper.Iso8601Time `json:"realEnd"`
+	Days           int                 `json:"days"`
+	Status         string              `json:"status"`
+	SubStatus      string              `json:"subStatus"`
+	Pri            string              `json:"pri"`
+	Desc           string              `json:"desc"`
+	Version        int                 `json:"version"`
+	ParentVersion  int                 `json:"parentVersion"`
+	PlanDuration   int                 `json:"planDuration"`
+	RealDuration   int                 `json:"realDuration"`
 	OpenedBy       `json:"openedBy"`
-	OpenedDate     time.Time `json:"openedDate"`
-	OpenedVersion  string    `json:"openedVersion"`
+	OpenedDate     *helper.Iso8601Time `json:"openedDate"`
+	OpenedVersion  string              `json:"openedVersion"`
 	LastEditedBy   `json:"lastEditedBy"`
-	LastEditedDate time.Time `json:"lastEditedDate"`
+	LastEditedDate *helper.Iso8601Time `json:"lastEditedDate"`
 	ClosedBy       `json:"closedBy"`
-	ClosedDate     time.Time `json:"closedDate"`
+	ClosedDate     *helper.Iso8601Time `json:"closedDate"`
 	CanceledBy     `json:"canceledBy"`
-	CanceledDate   time.Time `json:"canceledDate"`
-	SuspendedDate  string    `json:"suspendedDate"`
+	CanceledDate   *helper.Iso8601Time `json:"canceledDate"`
+	SuspendedDate  *helper.Iso8601Time `json:"suspendedDate"`
 	PO             `json:"PO"`
 	PM             `json:"PM"`
 	QD             `json:"QD"`
@@ -147,5 +147,5 @@ type TeamMember struct {
 }
 
 func (ZentaoExecution) TableName() string {
-	return "_tool_zentao_execution"
+	return "_tool_zentao_executions"
 }
diff --git a/plugins/zentao/models/archived/project.go b/plugins/zentao/models/archived/project.go
index 63c498dd..94fcdfcb 100644
--- a/plugins/zentao/models/archived/project.go
+++ b/plugins/zentao/models/archived/project.go
@@ -25,7 +25,7 @@ import (
 type ZentaoProject struct {
 	archived.NoPKModel
 	ConnectionId  uint64 `gorm:"primaryKey;type:BIGINT  NOT NULL"`
-	ID            int    `json:"id"`
+	ID            int    `json:"id" gorm:"primaryKey;type:BIGINT  NOT NULL"`
 	Project       int    `json:"project"`
 	Model         string `json:"model"`
 	Type          string `json:"type"`
@@ -109,5 +109,5 @@ type Hours struct {
 }
 
 func (ZentaoProject) TableName() string {
-	return "_tool_zentao_project"
+	return "_tool_zentao_projects"
 }
diff --git a/plugins/zentao/models/execution.go b/plugins/zentao/models/execution.go
index e51102cf..054f21d7 100644
--- a/plugins/zentao/models/execution.go
+++ b/plugins/zentao/models/execution.go
@@ -2,51 +2,51 @@ package models
 
 import (
 	"github.com/apache/incubator-devlake/models/common"
-	"time"
+	"github.com/apache/incubator-devlake/plugins/helper"
 )
 
 type ZentaoExecution struct {
-	ConnectionId   uint64 `gorm:"primaryKey"`
-	Id             uint64 `json:"id"`
-	Project        uint64 `json:"project"`
-	Model          string `json:"model"`
-	Type           string `json:"type"`
-	Lifetime       string `json:"lifetime"`
-	Budget         string `json:"budget"`
-	BudgetUnit     string `json:"budgetUnit"`
-	Attribute      string `json:"attribute"`
-	Percent        int    `json:"percent"`
-	Milestone      string `json:"milestone"`
-	Output         string `json:"output"`
-	Auth           string `json:"auth"`
-	Parent         int    `json:"parent"`
-	Path           string `json:"path"`
-	Grade          int    `json:"grade"`
-	Name           string `json:"name"`
-	Code           string `json:"code"`
-	Begin          string `json:"begin"`
-	End            string `json:"end"`
-	RealBegan      string `json:"realBegan"`
-	RealEnd        string `json:"realEnd"`
-	Days           int    `json:"days"`
-	Status         string `json:"status"`
-	SubStatus      string `json:"subStatus"`
-	Pri            string `json:"pri"`
-	Desc           string `json:"desc"`
-	Version        int    `json:"version"`
-	ParentVersion  int    `json:"parentVersion"`
-	PlanDuration   int    `json:"planDuration"`
-	RealDuration   int    `json:"realDuration"`
+	ConnectionId   uint64              `gorm:"primaryKey"`
+	Id             uint64              `json:"id" gorm:"primaryKey"`
+	Project        uint64              `json:"project"`
+	Model          string              `json:"model"`
+	Type           string              `json:"type"`
+	Lifetime       string              `json:"lifetime"`
+	Budget         string              `json:"budget"`
+	BudgetUnit     string              `json:"budgetUnit"`
+	Attribute      string              `json:"attribute"`
+	Percent        int                 `json:"percent"`
+	Milestone      string              `json:"milestone"`
+	Output         string              `json:"output"`
+	Auth           string              `json:"auth"`
+	Parent         int                 `json:"parent"`
+	Path           string              `json:"path"`
+	Grade          int                 `json:"grade"`
+	Name           string              `json:"name"`
+	Code           string              `json:"code"`
+	Begin          *helper.Iso8601Time `json:"begin"`
+	End            *helper.Iso8601Time `json:"end"`
+	RealBegan      *helper.Iso8601Time `json:"realBegan"`
+	RealEnd        *helper.Iso8601Time `json:"realEnd"`
+	Days           int                 `json:"days"`
+	Status         string              `json:"status"`
+	SubStatus      string              `json:"subStatus"`
+	Pri            string              `json:"pri"`
+	Desc           string              `json:"desc"`
+	Version        int                 `json:"version"`
+	ParentVersion  int                 `json:"parentVersion"`
+	PlanDuration   int                 `json:"planDuration"`
+	RealDuration   int                 `json:"realDuration"`
 	OpenedBy       `json:"openedBy"`
-	OpenedDate     time.Time `json:"openedDate"`
-	OpenedVersion  string    `json:"openedVersion"`
+	OpenedDate     *helper.Iso8601Time `json:"openedDate"`
+	OpenedVersion  string              `json:"openedVersion"`
 	LastEditedBy   `json:"lastEditedBy"`
-	LastEditedDate time.Time `json:"lastEditedDate"`
+	LastEditedDate *helper.Iso8601Time `json:"lastEditedDate"`
 	ClosedBy       `json:"closedBy"`
-	ClosedDate     time.Time `json:"closedDate"`
+	ClosedDate     *helper.Iso8601Time `json:"closedDate"`
 	CanceledBy     `json:"canceledBy"`
-	CanceledDate   time.Time `json:"canceledDate"`
-	SuspendedDate  string    `json:"suspendedDate"`
+	CanceledDate   *helper.Iso8601Time `json:"canceledDate"`
+	SuspendedDate  *helper.Iso8601Time `json:"suspendedDate"`
 	PO             `json:"PO"`
 	PM             `json:"PM"`
 	QD             `json:"QD"`
@@ -72,7 +72,7 @@ type ZentaoExecution struct {
 }
 
 func (ZentaoExecution) TableName() string {
-	return "_tool_zentao_execution"
+	return "_tool_zentao_executions"
 }
 
 type OpenedBy struct {
diff --git a/plugins/zentao/models/project.go b/plugins/zentao/models/project.go
index 5a51d738..db9450bf 100644
--- a/plugins/zentao/models/project.go
+++ b/plugins/zentao/models/project.go
@@ -25,7 +25,7 @@ import (
 type ZentaoProject struct {
 	common.NoPKModel
 	ConnectionId  uint64 `gorm:"primaryKey;type:BIGINT  NOT NULL"`
-	ID            int    `json:"id"`
+	ID            int    `json:"id" gorm:"primaryKey;type:BIGINT  NOT NULL"`
 	Project       int    `json:"project"`
 	Model         string `json:"model"`
 	Type          string `json:"type"`
@@ -109,5 +109,5 @@ type Hours struct {
 }
 
 func (ZentaoProject) TableName() string {
-	return "_tool_zentao_project"
+	return "_tool_zentao_projects"
 }
diff --git a/plugins/zentao/tasks/execution_convertor.go b/plugins/zentao/tasks/execution_convertor.go
new file mode 100644
index 00000000..727ba92d
--- /dev/null
+++ b/plugins/zentao/tasks/execution_convertor.go
@@ -0,0 +1,91 @@
+/*
+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 (
+	"github.com/apache/incubator-devlake/models/domainlayer"
+	"github.com/apache/incubator-devlake/models/domainlayer/didgen"
+	"github.com/apache/incubator-devlake/models/domainlayer/ticket"
+	"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/zentao/models"
+	"reflect"
+)
+
+var _ core.SubTaskEntryPoint = ConvertExecutions
+
+var ConvertExecutionsMeta = core.SubTaskMeta{
+	Name:             "convertExecutions",
+	EntryPoint:       ConvertExecutions,
+	EnabledByDefault: true,
+	Description:      "convert Zentao executions",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET},
+}
+
+func ConvertExecutions(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*ZentaoTaskData)
+	db := taskCtx.GetDal()
+	boardIdGen := didgen.NewDomainIdGenerator(&models.ZentaoExecution{})
+	cursor, err := db.Cursor(
+		dal.From(&models.ZentaoExecution{}),
+		dal.Where(`_tool_zentao_executions.id = ? and 
+			_tool_zentao_executions.connection_id = ?`, data.Options.ExecutionId, data.Options.ConnectionId),
+	)
+	if err != nil {
+		return err
+	}
+	defer cursor.Close()
+	convertor, err := helper.NewDataConverter(helper.DataConverterArgs{
+		InputRowType: reflect.TypeOf(models.ZentaoExecution{}),
+		Input:        cursor,
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: ZentaoApiParams{
+				ProductId:   data.Options.ProductId,
+				ExecutionId: data.Options.ExecutionId,
+				ProjectId:   data.Options.ProjectId,
+			},
+			Table: RAW_EXECUTION_TABLE,
+		},
+		Convert: func(inputRow interface{}) ([]interface{}, error) {
+			toolExecution := inputRow.(*models.ZentaoExecution)
+
+			domainBoard := &ticket.Board{
+				DomainEntity: domainlayer.DomainEntity{
+					Id: boardIdGen.Generate(toolExecution.ConnectionId, toolExecution.Id),
+				},
+				Name:        toolExecution.Name,
+				Description: toolExecution.Desc,
+				Url:         toolExecution.Path,
+				CreatedDate: toolExecution.OpenedDate.ToNullableTime(),
+				Type:        toolExecution.Type,
+			}
+
+			results := make([]interface{}, 0)
+			results = append(results, domainBoard)
+			return results, nil
+		},
+	})
+
+	if err != nil {
+		return err
+	}
+
+	return convertor.Execute()
+}