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

abeizn 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 e43288e3 fix(tapd): modify changelo
e43288e3 is described below

commit e43288e37ddc45c0c27bb0606f650d25c32f82f6
Author: Yingchu Chen <[email protected]>
AuthorDate: Wed Aug 17 14:36:44 2022 +0800

    fix(tapd): modify changelo
---
 plugins/tapd/models/story_changelog.go          |  2 ++
 plugins/tapd/models/task_changelog.go           |  2 ++
 plugins/tapd/tasks/story_changelog_extractor.go | 33 ++++++++++++++++++------
 plugins/tapd/tasks/task_changelog_extractor.go  | 34 ++++++++++++++++++-------
 4 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/plugins/tapd/models/story_changelog.go 
b/plugins/tapd/models/story_changelog.go
index 28f58a30..1a04c6f9 100644
--- a/plugins/tapd/models/story_changelog.go
+++ b/plugins/tapd/models/story_changelog.go
@@ -45,6 +45,8 @@ type TapdStoryChangelogItemRes struct {
        Field             string          `json:"field" 
gorm:"primaryKey;type:varchar(255)"`
        ValueBeforeParsed json.RawMessage `json:"value_before_parsed"`
        ValueAfterParsed  json.RawMessage `json:"value_after_parsed"`
+       ValueBefore       json.RawMessage `json:"value_before"`
+       ValueAfter        json.RawMessage `json:"value_after"`
        IterationIdFrom   uint64
        IterationIdTo     uint64
        common.NoPKModel
diff --git a/plugins/tapd/models/task_changelog.go 
b/plugins/tapd/models/task_changelog.go
index 5177c85f..29df87e3 100644
--- a/plugins/tapd/models/task_changelog.go
+++ b/plugins/tapd/models/task_changelog.go
@@ -58,6 +58,8 @@ type TapdTaskChangelogItemRes struct {
        Field             string          `json:"field" 
gorm:"primaryKey;type:varchar(255)"`
        ValueBeforeParsed json.RawMessage `json:"value_before_parsed"`
        ValueAfterParsed  json.RawMessage `json:"value_after_parsed"`
+       ValueBefore       json.RawMessage `json:"value_before"`
+       ValueAfter        json.RawMessage `json:"value_after"`
        IterationIdFrom   uint64
        IterationIdTo     uint64
        common.NoPKModel
diff --git a/plugins/tapd/tasks/story_changelog_extractor.go 
b/plugins/tapd/tasks/story_changelog_extractor.go
index 5fd17cd1..64ce0889 100644
--- a/plugins/tapd/tasks/story_changelog_extractor.go
+++ b/plugins/tapd/tasks/story_changelog_extractor.go
@@ -56,22 +56,39 @@ func ExtractStoryChangelog(taskCtx core.SubTaskContext) 
error {
                        for _, fc := range storyChangelog.FieldChanges {
                                var item models.TapdStoryChangelogItem
                                var valueAfterMap interface{}
-                               if err = json.Unmarshal(fc.ValueAfterParsed, 
&valueAfterMap); err != nil {
-                                       return nil, err
+                               var valueBeforeMap interface{}
+                               if fc.ValueAfterParsed == nil {
+                                       if err = json.Unmarshal(fc.ValueAfter, 
&valueAfterMap); err != nil {
+                                               return nil, err
+                                       }
+                               } else {
+                                       if err = 
json.Unmarshal(fc.ValueAfterParsed, &valueAfterMap); err != nil {
+                                               return nil, err
+                                       }
                                }
-                               switch valueAfterMap.(type) {
-                               case map[string]interface{}:
-                                       valueBeforeMap := map[string]string{}
-                                       err = 
json.Unmarshal(fc.ValueBeforeParsed, &valueBeforeMap)
-                                       if err != nil {
+                               if fc.ValueBeforeParsed == nil {
+                                       if err = json.Unmarshal(fc.ValueBefore, 
&valueBeforeMap); err != nil {
+                                               return nil, err
+                                       }
+                               } else {
+                                       if err = 
json.Unmarshal(fc.ValueBeforeParsed, &valueBeforeMap); err != nil {
                                                return nil, err
                                        }
+                               }
+                               switch valueAfterMap.(type) {
+                               case map[string]interface{}:
                                        for k, v := range 
valueAfterMap.(map[string]interface{}) {
                                                item.ConnectionId = 
data.Options.ConnectionId
                                                item.ChangelogId = 
storyChangelog.Id
                                                item.Field = k
                                                item.ValueAfterParsed = 
v.(string)
-                                               item.ValueBeforeParsed = 
valueBeforeMap[k]
+                                               switch valueBeforeMap.(type) {
+                                               case map[string]interface{}:
+                                                       item.ValueBeforeParsed 
= valueBeforeMap.(map[string]interface{})[k].(string)
+                                               default:
+                                                       item.ValueBeforeParsed 
= valueBeforeMap.(string)
+                                               }
+                                               results = append(results, &item)
                                        }
                                default:
                                        item.ConnectionId = 
data.Options.ConnectionId
diff --git a/plugins/tapd/tasks/task_changelog_extractor.go 
b/plugins/tapd/tasks/task_changelog_extractor.go
index a081d2cb..a6d381e8 100644
--- a/plugins/tapd/tasks/task_changelog_extractor.go
+++ b/plugins/tapd/tasks/task_changelog_extractor.go
@@ -56,23 +56,39 @@ func ExtractTaskChangelog(taskCtx core.SubTaskContext) 
error {
                        for _, fc := range taskChangelog.FieldChanges {
                                var item models.TapdTaskChangelogItem
                                var valueAfterMap interface{}
-                               if err = json.Unmarshal(fc.ValueAfterParsed, 
&valueAfterMap); err != nil {
-                                       return nil, err
+                               var valueBeforeMap interface{}
+                               if fc.ValueAfterParsed == nil {
+                                       if err = json.Unmarshal(fc.ValueAfter, 
&valueAfterMap); err != nil {
+                                               return nil, err
+                                       }
+                               } else {
+                                       if err = 
json.Unmarshal(fc.ValueAfterParsed, &valueAfterMap); err != nil {
+                                               return nil, err
+                                       }
                                }
-                               switch valueAfterMap.(type) {
-                               case map[string]interface{}:
-                                       valueBeforeMap := map[string]string{}
-                                       err = 
json.Unmarshal(fc.ValueBeforeParsed, &valueBeforeMap)
-                                       if err != nil {
+                               if fc.ValueBeforeParsed == nil {
+                                       if err = json.Unmarshal(fc.ValueBefore, 
&valueBeforeMap); err != nil {
+                                               return nil, err
+                                       }
+                               } else {
+                                       if err = 
json.Unmarshal(fc.ValueBeforeParsed, &valueBeforeMap); err != nil {
                                                return nil, err
                                        }
+                               }
+                               switch valueAfterMap.(type) {
+                               case map[string]interface{}:
                                        for k, v := range 
valueAfterMap.(map[string]interface{}) {
                                                item.ConnectionId = 
data.Options.ConnectionId
                                                item.ChangelogId = 
taskChangelog.Id
                                                item.Field = k
                                                item.ValueAfterParsed = 
v.(string)
-                                               item.ValueBeforeParsed = 
valueBeforeMap[k]
-                                               results = append(results, item)
+                                               switch valueBeforeMap.(type) {
+                                               case map[string]interface{}:
+                                                       item.ValueBeforeParsed 
= valueBeforeMap.(map[string]interface{})[k].(string)
+                                               default:
+                                                       item.ValueBeforeParsed 
= valueBeforeMap.(string)
+                                               }
+                                               results = append(results, &item)
                                        }
                                default:
                                        item.ConnectionId = 
data.Options.ConnectionId

Reply via email to