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 0fe9fa6a feat: add create_id for github; add create_name for domain 
layer (#2005)
0fe9fa6a is described below

commit 0fe9fa6af0b9fa4cb4663df0a19143169639b0fc
Author: likyh <[email protected]>
AuthorDate: Wed May 25 22:59:16 2022 +0800

    feat: add create_id for github; add create_name for domain layer (#2005)
    
    Co-authored-by: linyh <[email protected]>
---
 models/domainlayer/ticket/issue.go                 |  1 +
 models/migrationscripts/register.go                |  7 ++--
 .../{register.go => updateSchemas20220524.go}      | 35 +++++++++++++++++---
 plugins/github/github.go                           |  5 ++-
 plugins/github/models/issue.go                     |  2 ++
 .../migrationscripts/updateSchemas20220509.go      |  4 ---
 .../migrationscripts/updateSchemas20220524.go      | 38 +++++++++++++++++++---
 plugins/github/tasks/issue_convertor.go            |  2 ++
 plugins/github/tasks/issue_extractor.go            |  8 +++++
 plugins/jira/tasks/issue_convertor.go              |  7 +++-
 plugins/tapd/tasks/bug_converter.go                |  1 +
 plugins/tapd/tasks/story_converter.go              |  1 +
 plugins/tapd/tasks/task_converter.go               |  1 +
 13 files changed, 94 insertions(+), 18 deletions(-)

diff --git a/models/domainlayer/ticket/issue.go 
b/models/domainlayer/ticket/issue.go
index 19003b1a..ce391698 100644
--- a/models/domainlayer/ticket/issue.go
+++ b/models/domainlayer/ticket/issue.go
@@ -45,6 +45,7 @@ type Issue struct {
        TimeSpentMinutes        int64
        TimeRemainingMinutes    int64
        CreatorId               string `gorm:"type:varchar(255)"`
+       CreatorName             string `gorm:"type:varchar(255)"`
        AssigneeId              string `gorm:"type:varchar(255)"`
        AssigneeName            string `gorm:"type:varchar(255)"`
        Severity                string `gorm:"type:varchar(255)"`
diff --git a/models/migrationscripts/register.go 
b/models/migrationscripts/register.go
index e85a293d..9295fdf7 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/register.go
@@ -21,6 +21,9 @@ import "github.com/apache/incubator-devlake/migration"
 
 // RegisterAll register all the migration scripts of framework
 func RegisterAll() {
-       migration.Register([]migration.Script{new(initSchemas), 
new(updateSchemas20220505), new(updateSchemas20220507),
-               new(updateSchemas20220510), new(updateSchemas20220513)}, 
"Framework")
+       migration.Register([]migration.Script{
+               new(initSchemas),
+               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
+               new(updateSchemas20220513), new(updateSchemas20220524),
+       }, "Framework")
 }
diff --git a/models/migrationscripts/register.go 
b/models/migrationscripts/updateSchemas20220524.go
similarity index 54%
copy from models/migrationscripts/register.go
copy to models/migrationscripts/updateSchemas20220524.go
index e85a293d..9eb6a8f7 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/updateSchemas20220524.go
@@ -17,10 +17,35 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "context"
+       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
+       "gorm.io/gorm"
+)
 
-// RegisterAll register all the migration scripts of framework
-func RegisterAll() {
-       migration.Register([]migration.Script{new(initSchemas), 
new(updateSchemas20220505), new(updateSchemas20220507),
-               new(updateSchemas20220510), new(updateSchemas20220513)}, 
"Framework")
+type Issue20220524 struct {
+       archived.DomainEntity
+       CreatorName string `gorm:"type:varchar(255)"`
+}
+
+func (Issue20220524) TableName() string {
+       return "issues"
+}
+
+type updateSchemas20220524 struct{}
+
+func (*updateSchemas20220524) Up(ctx context.Context, db *gorm.DB) error {
+       err := db.Migrator().AddColumn(&Issue20220524{}, "creator_name")
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func (*updateSchemas20220524) Version() uint64 {
+       return 20220524000005
+}
+
+func (*updateSchemas20220524) Name() string {
+       return "Add creator_name column to Issue"
 }
diff --git a/plugins/github/github.go b/plugins/github/github.go
index 0b5437f7..765a4d28 100644
--- a/plugins/github/github.go
+++ b/plugins/github/github.go
@@ -111,7 +111,10 @@ func (plugin Github) RootPkgPath() string {
 }
 
 func (plugin Github) MigrationScripts() []migration.Script {
-       return []migration.Script{new(migrationscripts.InitSchemas), 
new(migrationscripts.UpdateSchemas20220509)}
+       return []migration.Script{
+               new(migrationscripts.InitSchemas), 
new(migrationscripts.UpdateSchemas20220509),
+               new(migrationscripts.UpdateSchemas20220524),
+       }
 }
 
 func (plugin Github) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
diff --git a/plugins/github/models/issue.go b/plugins/github/models/issue.go
index 6df07b6a..b99cfa46 100644
--- a/plugins/github/models/issue.go
+++ b/plugins/github/models/issue.go
@@ -32,6 +32,8 @@ type GithubIssue struct {
        Priority        string `gorm:"type:varchar(255)"`
        Type            string `gorm:"type:varchar(100)"`
        Status          string `gorm:"type:varchar(255)"`
+       AuthorId        int
+       AuthorName      string `gorm:"type:varchar(255)"`
        AssigneeId      int
        AssigneeName    string `gorm:"type:varchar(255)"`
        LeadTimeMinutes uint
diff --git a/plugins/github/models/migrationscripts/updateSchemas20220509.go 
b/plugins/github/models/migrationscripts/updateSchemas20220509.go
index 81dd0ad4..c4f76032 100644
--- a/plugins/github/models/migrationscripts/updateSchemas20220509.go
+++ b/plugins/github/models/migrationscripts/updateSchemas20220509.go
@@ -81,10 +81,6 @@ func (*UpdateSchemas20220509) Version() uint64 {
        return 20220509212344
 }
 
-func (*UpdateSchemas20220509) Owner() string {
-       return "Github"
-}
-
 func (*UpdateSchemas20220509) Name() string {
        return "Alter pr column `author_id` to int"
 }
diff --git a/models/migrationscripts/register.go 
b/plugins/github/models/migrationscripts/updateSchemas20220524.go
similarity index 51%
copy from models/migrationscripts/register.go
copy to plugins/github/models/migrationscripts/updateSchemas20220524.go
index e85a293d..2196cab2 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/github/models/migrationscripts/updateSchemas20220524.go
@@ -17,10 +17,38 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "context"
+       "gorm.io/gorm"
+)
 
-// RegisterAll register all the migration scripts of framework
-func RegisterAll() {
-       migration.Register([]migration.Script{new(initSchemas), 
new(updateSchemas20220505), new(updateSchemas20220507),
-               new(updateSchemas20220510), new(updateSchemas20220513)}, 
"Framework")
+type GithubIssue20220524 struct {
+       AuthorId   int
+       AuthorName string `gorm:"type:varchar(255)"`
+}
+
+func (GithubIssue20220524) TableName() string {
+       return "_tool_github_issues"
+}
+
+type UpdateSchemas20220524 struct{}
+
+func (*UpdateSchemas20220524) Up(ctx context.Context, db *gorm.DB) error {
+       err := db.Migrator().AddColumn(GithubIssue20220524{}, "author_id")
+       if err != nil {
+               return err
+       }
+       err = db.Migrator().AddColumn(GithubIssue20220524{}, "author_name")
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func (*UpdateSchemas20220524) Version() uint64 {
+       return 20220524000002
+}
+
+func (*UpdateSchemas20220524) Name() string {
+       return "Add column `author_id`/`author_name` in `GithubIssue`"
 }
diff --git a/plugins/github/tasks/issue_convertor.go 
b/plugins/github/tasks/issue_convertor.go
index 7f435295..06c3a51b 100644
--- a/plugins/github/tasks/issue_convertor.go
+++ b/plugins/github/tasks/issue_convertor.go
@@ -76,6 +76,8 @@ func ConvertIssues(taskCtx core.SubTaskContext) error {
                                Type:            issue.Type,
                                AssigneeId:      
userIdGen.Generate(issue.AssigneeId),
                                AssigneeName:    issue.AssigneeName,
+                               CreatorId:       
userIdGen.Generate(issue.AuthorId),
+                               CreatorName:     issue.AuthorName,
                                LeadTimeMinutes: issue.LeadTimeMinutes,
                                Url:             issue.Url,
                                CreatedDate:     &issue.GithubCreatedAt,
diff --git a/plugins/github/tasks/issue_extractor.go 
b/plugins/github/tasks/issue_extractor.go
index 6bc77fd7..f11a608e 100644
--- a/plugins/github/tasks/issue_extractor.go
+++ b/plugins/github/tasks/issue_extractor.go
@@ -53,6 +53,10 @@ type IssuesResponse struct {
                Login string
                Id    int
        }
+       User *struct {
+               Login string
+               Id    int
+       }
        ClosedAt        *helper.Iso8601Time `json:"closed_at"`
        GithubCreatedAt helper.Iso8601Time  `json:"created_at"`
        GithubUpdatedAt helper.Iso8601Time  `json:"updated_at"`
@@ -219,6 +223,10 @@ func convertGithubIssue(issue *IssuesResponse, 
repositoryId int) (*models.Github
                githubIssue.AssigneeId = issue.Assignee.Id
                githubIssue.AssigneeName = issue.Assignee.Login
        }
+       if issue.User != nil {
+               githubIssue.AuthorId = issue.User.Id
+               githubIssue.AuthorName = issue.User.Login
+       }
        if issue.ClosedAt != nil {
                githubIssue.LeadTimeMinutes = 
uint(issue.ClosedAt.ToTime().Sub(issue.GithubCreatedAt.ToTime()).Minutes())
        }
diff --git a/plugins/jira/tasks/issue_convertor.go 
b/plugins/jira/tasks/issue_convertor.go
index 3d83ac71..79b39c66 100644
--- a/plugins/jira/tasks/issue_convertor.go
+++ b/plugins/jira/tasks/issue_convertor.go
@@ -82,7 +82,6 @@ func ConvertIssues(taskCtx core.SubTaskContext) error {
                                OriginalStatus:          jiraIssue.StatusKey,
                                StoryPoint:              
jiraIssue.StdStoryPoint,
                                OriginalEstimateMinutes: 
jiraIssue.OriginalEstimateMinutes,
-                               CreatorId:               
userIdGen.Generate(data.Options.ConnectionId, jiraIssue.CreatorAccountId),
                                ResolutionDate:          
jiraIssue.ResolutionDate,
                                Priority:                jiraIssue.PriorityName,
                                CreatedDate:             &jiraIssue.Created,
@@ -90,6 +89,12 @@ func ConvertIssues(taskCtx core.SubTaskContext) error {
                                LeadTimeMinutes:         
jiraIssue.LeadTimeMinutes,
                                TimeSpentMinutes:        jiraIssue.SpentMinutes,
                        }
+                       if jiraIssue.CreatorAccountId != "" {
+                               issue.CreatorId = 
userIdGen.Generate(data.Options.ConnectionId, jiraIssue.CreatorAccountId)
+                       }
+                       if jiraIssue.CreatorDisplayName != "" {
+                               issue.CreatorName = jiraIssue.CreatorDisplayName
+                       }
                        if jiraIssue.AssigneeAccountId != "" {
                                issue.AssigneeId = 
userIdGen.Generate(data.Options.ConnectionId, jiraIssue.AssigneeAccountId)
                        }
diff --git a/plugins/tapd/tasks/bug_converter.go 
b/plugins/tapd/tasks/bug_converter.go
index 74365f71..ba8c5d06 100644
--- a/plugins/tapd/tasks/bug_converter.go
+++ b/plugins/tapd/tasks/bug_converter.go
@@ -69,6 +69,7 @@ func ConvertBug(taskCtx core.SubTaskContext) error {
                                ParentIssueId:  
IssueIdGen.Generate(toolL.ConnectionId, toolL.IssueID),
                                Priority:       toolL.Priority,
                                CreatorId:      
UserIdGen.Generate(data.Connection.ID, toolL.WorkspaceID, toolL.Reporter),
+                               CreatorName:    toolL.Reporter,
                                AssigneeId:     
UserIdGen.Generate(data.Connection.ID, toolL.WorkspaceID, toolL.CurrentOwner),
                                AssigneeName:   toolL.CurrentOwner,
                                Severity:       toolL.Severity,
diff --git a/plugins/tapd/tasks/story_converter.go 
b/plugins/tapd/tasks/story_converter.go
index 926aea4e..41824568 100644
--- a/plugins/tapd/tasks/story_converter.go
+++ b/plugins/tapd/tasks/story_converter.go
@@ -71,6 +71,7 @@ func ConvertStory(taskCtx core.SubTaskContext) error {
                                Priority:             toolL.Priority,
                                TimeRemainingMinutes: int64(toolL.Remain),
                                CreatorId:            
UserIdGen.Generate(data.Connection.ID, toolL.WorkspaceID, toolL.Creator),
+                               CreatorName:          toolL.Creator,
                                AssigneeId:           
UserIdGen.Generate(data.Connection.ID, toolL.WorkspaceID, toolL.Owner),
                                AssigneeName:         toolL.Owner,
                                Severity:             "",
diff --git a/plugins/tapd/tasks/task_converter.go 
b/plugins/tapd/tasks/task_converter.go
index c15d1e10..805acc13 100644
--- a/plugins/tapd/tasks/task_converter.go
+++ b/plugins/tapd/tasks/task_converter.go
@@ -70,6 +70,7 @@ func ConvertTask(taskCtx core.SubTaskContext) error {
                                ParentIssueId:  
IssueIdGen.Generate(toolL.ConnectionId, toolL.StoryID),
                                Priority:       toolL.Priority,
                                CreatorId:      
UserIdGen.Generate(data.Connection.ID, toolL.WorkspaceID, toolL.Creator),
+                               CreatorName:    toolL.Creator,
                                AssigneeId:     
UserIdGen.Generate(data.Connection.ID, toolL.WorkspaceID, toolL.Owner),
                                AssigneeName:   toolL.Owner,
                        }

Reply via email to