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/17 06:20:18 UTC

[incubator-devlake] 10/12: fix:apiurl&model error

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 8f3ff2c706b7cdb4ca6691b159bde4faeee3545b
Author: yuqiangabab <11...@qq.com>
AuthorDate: Sun Oct 2 11:20:52 2022 +0800

    fix:apiurl&model error
---
 plugins/zentao/models/archived/stories.go | 116 +++++++-----------------------
 plugins/zentao/models/stories.go          | 116 +++++++-----------------------
 plugins/zentao/tasks/stories_collector.go |  12 +++-
 plugins/zentao/tasks/stories_convertor.go |  18 ++---
 plugins/zentao/tasks/stories_extractor.go |   5 +-
 plugins/zentao/tasks/task_data.go         |   1 -
 plugins/zentao/zentao.go                  |   2 -
 7 files changed, 75 insertions(+), 195 deletions(-)

diff --git a/plugins/zentao/models/archived/stories.go b/plugins/zentao/models/archived/stories.go
index cd608682..d197e1fd 100644
--- a/plugins/zentao/models/archived/stories.go
+++ b/plugins/zentao/models/archived/stories.go
@@ -25,11 +25,16 @@ import (
 type ZentaoStories struct {
 	archived.NoPKModel
 	ConnectionId uint64 `gorm:"primaryKey;type:BIGINT  NOT NULL"`
-	ID           int    `json:"id"gorm:"primaryKey;type:BIGINT  NOT NULL"`
-	Vision       string `json:"vision"`
-	Parent       int    `json:"parent"`
+	ExecutionId  uint64 `json:"execution_id"`
+	Project      int    `json:"project"`
 	Product      int    `json:"product"`
 	Branch       int    `json:"branch"`
+	Story        int    `json:"story"`
+	Version      int    `json:"version"`
+	Order        int    `json:"order"`
+	ID           int    `json:"id" gorm:"primaryKey;type:BIGINT  NOT NULL" `
+	Vision       string `json:"vision"`
+	Parent       int    `json:"parent"`
 	Module       int    `json:"module"`
 	Plan         string `json:"plan"`
 	Source       string `json:"source"`
@@ -47,20 +52,20 @@ type ZentaoStories struct {
 	Color        string `json:"color"`
 	Stage        string `json:"stage"`
 	StagedBy     string `json:"stagedBy"`
-	//Mailto           []interface{} `json:"mailto" gorm:"-:all"`
-	Lib              int `json:"lib"`
-	FromStory        int `json:"fromStory"`
-	FromVersion      int `json:"fromVersion"`
-	OpenedBy         `json:"openedBy"`
-	OpenedDate       *helper.Iso8601Time `json:"openedDate"`
-	AssignedTo       `json:"assignedTo"`
-	AssignedDate     *helper.Iso8601Time `json:"assignedDate"`
-	ApprovedDate     string              `json:"approvedDate"`
-	LastEditedBy     `json:"lastEditedBy"`
-	LastEditedDate   *helper.Iso8601Time `json:"lastEditedDate"`
-	ChangedBy        string              `json:"changedBy"`
-	ChangedDate      string              `json:"changedDate"`
-	ReviewedBy       interface{}         `json:"reviewedBy" gorm:"-:all"`
+	//Mailto           []interface{} `json:"mailto"`
+	Lib            int `json:"lib"`
+	FromStory      int `json:"fromStory"`
+	FromVersion    int `json:"fromVersion"`
+	OpenedBy       `json:"openedBy"`
+	OpenedDate     *helper.Iso8601Time `json:"openedDate"`
+	AssignedTo     `json:"assignedTo"`
+	AssignedDate   *helper.Iso8601Time `json:"assignedDate"`
+	ApprovedDate   string              `json:"approvedDate"`
+	LastEditedBy   `json:"lastEditedBy"`
+	LastEditedDate *helper.Iso8601Time `json:"lastEditedDate"`
+	ChangedBy      string              `json:"changedBy"`
+	ChangedDate    string              `json:"changedDate"`
+	//ReviewedBy       interface{} `json:"reviewedBy"`
 	ReviewedDate     *helper.Iso8601Time `json:"reviewedDate"`
 	ClosedBy         `json:"closedBy"`
 	ClosedDate       *helper.Iso8601Time `json:"closedDate"`
@@ -71,81 +76,17 @@ type ZentaoStories struct {
 	LinkStories      string              `json:"linkStories"`
 	LinkRequirements string              `json:"linkRequirements"`
 	DuplicateStory   int                 `json:"duplicateStory"`
-	Version          int                 `json:"version"`
 	StoryChanged     string              `json:"storyChanged"`
 	FeedbackBy       string              `json:"feedbackBy"`
 	NotifyEmail      string              `json:"notifyEmail"`
 	URChanged        string              `json:"URChanged"`
 	Deleted          bool                `json:"deleted"`
-	Spec             string              `json:"spec"`
-	Verify           string              `json:"verify"`
-	Executions       Executions          `json:"executions" gorm:"-:all"`
-	Tasks            []Tasks             `json:"tasks" gorm:"-:all"`
-	//Stages           []interface{}       `json:"stages" gorm:"-:all"`
-	PlanTitle []string `json:"planTitle" gorm:"-:all"`
-	//Children         []interface{}       `json:"children" gorm:"-:all"`
-	//Files            []interface{}       `json:"files" gorm:"-:all"`
-	ProductName   string  `json:"productName"`
-	ProductStatus string  `json:"productStatus"`
-	ModuleTitle   string  `json:"moduleTitle"`
-	Bugs          []Bugs  `json:"bugs" gorm:"-:all"`
-	Cases         []Cases `json:"cases" gorm:"-:all"`
-	//Requirements  []interface{} `json:"requirements" gorm:"-:all"`
-	Actions    []Actions `json:"actions" gorm:"-:all"`
-	PreAndNext `json:"preAndNext"`
-}
-type Executions struct {
-	Num1 struct {
-		Project int    `json:"project"`
-		Name    string `json:"name"`
-		Status  string `json:"status"`
-		Type    string `json:"type"`
-	} `json:"1"`
-}
-type Tasks struct {
-	ID         int    `json:"id"`
-	Name       string `json:"name"`
-	Type       string `json:"type"`
-	Status     string `json:"status"`
-	AssignedTo struct {
-		ID       int    `json:"id"`
-		Account  string `json:"account"`
-		Avatar   string `json:"avatar"`
-		Realname string `json:"realname"`
-	} `json:"assignedTo"`
-}
-type Bugs struct {
-	ID       int    `json:"id"`
-	Title    string `json:"title"`
-	Status   string `json:"status"`
-	Pri      int    `json:"pri"`
-	Severity int    `json:"severity"`
-}
-type Cases struct {
-	ID     int    `json:"id"`
-	Title  string `json:"title"`
-	Pri    int    `json:"pri"`
-	Status string `json:"status"`
+	PriOrder         string              `json:"priOrder"`
+	ProductType      string              `json:"productType"`
+	PlanTitle        string              `json:"planTitle"`
+	ProductStatus    string              `json:"productStatus"`
 }
 
-type Actions struct {
-	ID         int    `json:"id"`
-	ObjectType string `json:"objectType"`
-	ObjectID   int    `json:"objectID"`
-	Product    string `json:"product"`
-	Project    int    `json:"project"`
-	Execution  int    `json:"execution"`
-	Actor      string `json:"actor"`
-	Action     string `json:"action"`
-	Date       string `json:"date"`
-	Comment    string `json:"comment"`
-	Extra      string `json:"extra"`
-	Read       string `json:"read"`
-	Vision     string `json:"vision"`
-	Efforted   int    `json:"efforted"`
-	//History    []interface{} `json:"history"`
-	Desc string `json:"desc"`
-}
 type AssignedTo struct {
 	ID       int    `json:"id"`
 	Account  string `json:"account"`
@@ -153,11 +94,6 @@ type AssignedTo struct {
 	Realname string `json:"realname"`
 }
 
-type PreAndNext struct {
-	Pre  string `json:"pre"`
-	Next string `json:"next"`
-}
-
 func (ZentaoStories) TableName() string {
 	return "_tool_zentao_stories"
 }
diff --git a/plugins/zentao/models/stories.go b/plugins/zentao/models/stories.go
index be198bbf..1d65c111 100644
--- a/plugins/zentao/models/stories.go
+++ b/plugins/zentao/models/stories.go
@@ -25,11 +25,16 @@ import (
 type ZentaoStories struct {
 	common.NoPKModel
 	ConnectionId uint64 `gorm:"primaryKey;type:BIGINT  NOT NULL"`
-	ID           int    `json:"id"gorm:"primaryKey;type:BIGINT  NOT NULL"`
-	Vision       string `json:"vision"`
-	Parent       int    `json:"parent"`
+	ExecutionId  uint64 `json:"execution_id"`
+	Project      int    `json:"project"`
 	Product      int    `json:"product"`
 	Branch       int    `json:"branch"`
+	Story        int    `json:"story"`
+	Version      int    `json:"version"`
+	Order        int    `json:"order"`
+	ID           int    `json:"id" gorm:"primaryKey;type:BIGINT  NOT NULL" `
+	Vision       string `json:"vision"`
+	Parent       int    `json:"parent"`
 	Module       int    `json:"module"`
 	Plan         string `json:"plan"`
 	Source       string `json:"source"`
@@ -47,20 +52,20 @@ type ZentaoStories struct {
 	Color        string `json:"color"`
 	Stage        string `json:"stage"`
 	StagedBy     string `json:"stagedBy"`
-	//Mailto           []interface{} `json:"mailto" gorm:"-:all"`
-	Lib              int `json:"lib"`
-	FromStory        int `json:"fromStory"`
-	FromVersion      int `json:"fromVersion"`
-	OpenedBy         `json:"openedBy"`
-	OpenedDate       *helper.Iso8601Time `json:"openedDate"`
-	AssignedTo       `json:"assignedTo"`
-	AssignedDate     *helper.Iso8601Time `json:"assignedDate"`
-	ApprovedDate     string              `json:"approvedDate"`
-	LastEditedBy     `json:"lastEditedBy"`
-	LastEditedDate   *helper.Iso8601Time `json:"lastEditedDate"`
-	ChangedBy        string              `json:"changedBy"`
-	ChangedDate      string              `json:"changedDate"`
-	ReviewedBy       interface{}         `json:"reviewedBy" gorm:"-:all"`
+	//Mailto           []interface{} `json:"mailto"`
+	Lib            int `json:"lib"`
+	FromStory      int `json:"fromStory"`
+	FromVersion    int `json:"fromVersion"`
+	OpenedBy       `json:"openedBy"`
+	OpenedDate     *helper.Iso8601Time `json:"openedDate"`
+	AssignedTo     `json:"assignedTo"`
+	AssignedDate   *helper.Iso8601Time `json:"assignedDate"`
+	ApprovedDate   string              `json:"approvedDate"`
+	LastEditedBy   `json:"lastEditedBy"`
+	LastEditedDate *helper.Iso8601Time `json:"lastEditedDate"`
+	ChangedBy      string              `json:"changedBy"`
+	ChangedDate    string              `json:"changedDate"`
+	//ReviewedBy       interface{} `json:"reviewedBy"`
 	ReviewedDate     *helper.Iso8601Time `json:"reviewedDate"`
 	ClosedBy         `json:"closedBy"`
 	ClosedDate       *helper.Iso8601Time `json:"closedDate"`
@@ -71,81 +76,17 @@ type ZentaoStories struct {
 	LinkStories      string              `json:"linkStories"`
 	LinkRequirements string              `json:"linkRequirements"`
 	DuplicateStory   int                 `json:"duplicateStory"`
-	Version          int                 `json:"version"`
 	StoryChanged     string              `json:"storyChanged"`
 	FeedbackBy       string              `json:"feedbackBy"`
 	NotifyEmail      string              `json:"notifyEmail"`
 	URChanged        string              `json:"URChanged"`
 	Deleted          bool                `json:"deleted"`
-	Spec             string              `json:"spec"`
-	Verify           string              `json:"verify"`
-	Executions       Executions          `json:"executions" gorm:"-:all"`
-	Tasks            []Tasks             `json:"tasks" gorm:"-:all"`
-	//Stages           []interface{}       `json:"stages" gorm:"-:all"`
-	PlanTitle []string `json:"planTitle" gorm:"-:all"`
-	//Children         []interface{}       `json:"children" gorm:"-:all"`
-	//Files            []interface{}       `json:"files" gorm:"-:all"`
-	ProductName   string  `json:"productName"`
-	ProductStatus string  `json:"productStatus"`
-	ModuleTitle   string  `json:"moduleTitle"`
-	Bugs          []Bugs  `json:"bugs" gorm:"-:all"`
-	Cases         []Cases `json:"cases" gorm:"-:all"`
-	//Requirements  []interface{} `json:"requirements" gorm:"-:all"`
-	Actions    []Actions `json:"actions" gorm:"-:all"`
-	PreAndNext `json:"preAndNext"`
-}
-type Executions struct {
-	Num1 struct {
-		Project int    `json:"project"`
-		Name    string `json:"name"`
-		Status  string `json:"status"`
-		Type    string `json:"type"`
-	} `json:"1"`
-}
-type Tasks struct {
-	ID         int    `json:"id"`
-	Name       string `json:"name"`
-	Type       string `json:"type"`
-	Status     string `json:"status"`
-	AssignedTo struct {
-		ID       int    `json:"id"`
-		Account  string `json:"account"`
-		Avatar   string `json:"avatar"`
-		Realname string `json:"realname"`
-	} `json:"assignedTo"`
-}
-type Bugs struct {
-	ID       int    `json:"id"`
-	Title    string `json:"title"`
-	Status   string `json:"status"`
-	Pri      int    `json:"pri"`
-	Severity int    `json:"severity"`
-}
-type Cases struct {
-	ID     int    `json:"id"`
-	Title  string `json:"title"`
-	Pri    int    `json:"pri"`
-	Status string `json:"status"`
+	PriOrder         string              `json:"priOrder"`
+	ProductType      string              `json:"productType"`
+	PlanTitle        string              `json:"planTitle"`
+	ProductStatus    string              `json:"productStatus"`
 }
 
-type Actions struct {
-	ID         int    `json:"id"`
-	ObjectType string `json:"objectType"`
-	ObjectID   int    `json:"objectID"`
-	Product    string `json:"product"`
-	Project    int    `json:"project"`
-	Execution  int    `json:"execution"`
-	Actor      string `json:"actor"`
-	Action     string `json:"action"`
-	Date       string `json:"date"`
-	Comment    string `json:"comment"`
-	Extra      string `json:"extra"`
-	Read       string `json:"read"`
-	Vision     string `json:"vision"`
-	Efforted   int    `json:"efforted"`
-	//History    []interface{} `json:"history"`
-	Desc string `json:"desc"`
-}
 type AssignedTo struct {
 	ID       int    `json:"id"`
 	Account  string `json:"account"`
@@ -153,11 +94,6 @@ type AssignedTo struct {
 	Realname string `json:"realname"`
 }
 
-type PreAndNext struct {
-	Pre  string `json:"pre"`
-	Next string `json:"next"`
-}
-
 func (ZentaoStories) TableName() string {
 	return "_tool_zentao_stories"
 }
diff --git a/plugins/zentao/tasks/stories_collector.go b/plugins/zentao/tasks/stories_collector.go
index 6ba58924..26c004c8 100644
--- a/plugins/zentao/tasks/stories_collector.go
+++ b/plugins/zentao/tasks/stories_collector.go
@@ -37,7 +37,9 @@ func CollectStories(taskCtx core.SubTaskContext) error {
 		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
 			Ctx: taskCtx,
 			Params: ZentaoApiParams{
-				StoriesId: data.Options.StoriesId,
+				ProductId:   data.Options.ProductId,
+				ExecutionId: data.Options.ExecutionId,
+				ProjectId:   data.Options.ProjectId,
 			},
 			Table: RAW_STORIES_TABLE,
 		},
@@ -45,7 +47,7 @@ func CollectStories(taskCtx core.SubTaskContext) error {
 		Incremental: false,
 		PageSize:    100,
 		// TODO write which api would you want request
-		UrlTemplate: "/stories/{{ .Params.StoriesId }}",
+		UrlTemplate: "/executions/{{ .Params.ExecutionId }}/stories",
 		Query: func(reqData *helper.RequestData) (url.Values, error) {
 			query := url.Values{}
 			query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
@@ -54,12 +56,16 @@ func CollectStories(taskCtx core.SubTaskContext) error {
 		},
 		GetTotalPages: GetTotalPagesFromResponse,
 		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Stories []json.RawMessage `json:"stories"`
+			}
 			body, err := io.ReadAll(res.Body)
+			json.Unmarshal(body, &data)
 			res.Body.Close()
 			if err != nil {
 				return nil, err
 			}
-			return []json.RawMessage{body}, nil
+			return data.Stories, nil
 		},
 	})
 	if err != nil {
diff --git a/plugins/zentao/tasks/stories_convertor.go b/plugins/zentao/tasks/stories_convertor.go
index a41a1868..b9d80724 100644
--- a/plugins/zentao/tasks/stories_convertor.go
+++ b/plugins/zentao/tasks/stories_convertor.go
@@ -44,8 +44,8 @@ func ConvertStories(taskCtx core.SubTaskContext) error {
 	boardIdGen := didgen.NewDomainIdGenerator(&models.ZentaoStories{})
 	cursor, err := db.Cursor(
 		dal.From(&models.ZentaoStories{}),
-		dal.Where(`_tool_zentao_stories.id = ? and 
-			_tool_zentao_stories.connection_id = ?`, data.Options.StoriesId, data.Options.ConnectionId),
+		dal.Where(`_tool_zentao_stories.execution_id = ? and 
+			_tool_zentao_stories.connection_id = ?`, data.Options.ExecutionId, data.Options.ConnectionId),
 	)
 	if err != nil {
 		return err
@@ -57,7 +57,9 @@ func ConvertStories(taskCtx core.SubTaskContext) error {
 		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
 			Ctx: taskCtx,
 			Params: ZentaoApiParams{
-				StoriesId: data.Options.StoriesId,
+				ProductId:   data.Options.ProductId,
+				ExecutionId: data.Options.ExecutionId,
+				ProjectId:   data.Options.ProjectId,
 			},
 			Table: RAW_STORIES_TABLE,
 		},
@@ -68,11 +70,11 @@ func ConvertStories(taskCtx core.SubTaskContext) error {
 				DomainEntity: domainlayer.DomainEntity{
 					Id: boardIdGen.Generate(toolStories.ConnectionId, toolStories.ID),
 				},
-				Url:                     "",
-				IconURL:                 "",
-				IssueKey:                "",
-				Title:                   toolStories.Title,
-				Description:             toolStories.Spec,
+				Url:      "",
+				IconURL:  "",
+				IssueKey: "",
+				Title:    toolStories.Title,
+				//Description:             toolStories.Spec,
 				EpicKey:                 "",
 				Type:                    toolStories.Type,
 				Status:                  toolStories.Status,
diff --git a/plugins/zentao/tasks/stories_extractor.go b/plugins/zentao/tasks/stories_extractor.go
index aaadfb84..a4d37db0 100644
--- a/plugins/zentao/tasks/stories_extractor.go
+++ b/plugins/zentao/tasks/stories_extractor.go
@@ -40,7 +40,9 @@ func ExtractStories(taskCtx core.SubTaskContext) error {
 		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
 			Ctx: taskCtx,
 			Params: ZentaoApiParams{
-				StoriesId: data.Options.StoriesId,
+				ProductId:   data.Options.ProductId,
+				ExecutionId: data.Options.ExecutionId,
+				ProjectId:   data.Options.ProjectId,
 			},
 			Table: RAW_STORIES_TABLE,
 		},
@@ -51,6 +53,7 @@ func ExtractStories(taskCtx core.SubTaskContext) error {
 				return nil, err
 			}
 			stories.ConnectionId = data.Options.ConnectionId
+			stories.ExecutionId = data.Options.ExecutionId
 			results := make([]interface{}, 0)
 			results = append(results, stories)
 			return results, nil
diff --git a/plugins/zentao/tasks/task_data.go b/plugins/zentao/tasks/task_data.go
index ae51908f..c522360e 100644
--- a/plugins/zentao/tasks/task_data.go
+++ b/plugins/zentao/tasks/task_data.go
@@ -27,7 +27,6 @@ type ZentaoApiParams struct {
 	ProductId   uint64
 	ExecutionId uint64
 	ProjectId   uint64
-	StoriesId   uint64
 }
 
 type ZentaoOptions struct {
diff --git a/plugins/zentao/zentao.go b/plugins/zentao/zentao.go
index 3768b5d9..32845c90 100644
--- a/plugins/zentao/zentao.go
+++ b/plugins/zentao/zentao.go
@@ -34,7 +34,6 @@ func main() {
 	executionId := cmd.Flags().IntP("executionId", "e", 8, "execution id")
 	productId := cmd.Flags().IntP("productId", "o", 8, "product id")
 	projectId := cmd.Flags().IntP("projectId", "p", 8, "project id")
-	storiesId := cmd.Flags().IntP("storiesId", "s", 1, "stories id")
 
 	cmd.Run = func(cmd *cobra.Command, args []string) {
 		runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
@@ -42,7 +41,6 @@ func main() {
 			"executionId":  *executionId,
 			"productId":    *productId,
 			"projectId":    *projectId,
-			"storiesId":    *storiesId,
 		})
 	}
 	runner.RunCmd(cmd)