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

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


The following commit(s) were added to refs/heads/hexun-tapd by this push:
     new 5ea07e3d4 fix(tapd): convert unicode to string (#4398)
5ea07e3d4 is described below

commit 5ea07e3d498874fe3ec7a4b841efdda4bacfb7f2
Author: Warren Chen <[email protected]>
AuthorDate: Mon Feb 13 16:05:51 2023 +0800

    fix(tapd): convert unicode to string (#4398)
---
 plugins/tapd/tasks/story_changelog_extractor.go | 35 +++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/plugins/tapd/tasks/story_changelog_extractor.go 
b/plugins/tapd/tasks/story_changelog_extractor.go
index a9a976f35..f9055b1c8 100644
--- a/plugins/tapd/tasks/story_changelog_extractor.go
+++ b/plugins/tapd/tasks/story_changelog_extractor.go
@@ -20,6 +20,7 @@ package tasks
 import (
        "encoding/json"
        "github.com/apache/incubator-devlake/errors"
+       "strconv"
        "strings"
 
        "github.com/apache/incubator-devlake/plugins/core"
@@ -89,14 +90,23 @@ func ExtractStoryChangelog(taskCtx core.SubTaskContext) 
errors.Error {
                                                default:
                                                        item.ValueBeforeParsed 
= valueBeforeMap.(string)
                                                }
+                                               err = convertUnicode(&item)
+                                               if err != nil {
+                                                       return nil, err
+                                               }
                                                results = append(results, &item)
                                        }
                                default:
                                        item.ConnectionId = 
data.Options.ConnectionId
                                        item.ChangelogId = storyChangelog.Id
                                        item.Field = fc.Field
-                                       item.ValueAfterParsed = 
strings.Trim(string(fc.ValueAfterParsed), `"`)
-                                       item.ValueBeforeParsed = 
strings.Trim(string(fc.ValueBeforeParsed), `"`)
+                                       item.ValueAfterParsed = 
valueAfterMap.(string)
+                                       // as ValueAfterParsed is string, 
valueBeforeMap is always string
+                                       item.ValueBeforeParsed = 
valueBeforeMap.(string)
+                               }
+                               err = convertUnicode(&item)
+                               if err != nil {
+                                       return nil, err
                                }
                                if item.Field == "iteration_id" {
                                        iterationFrom, iterationTo, err := 
parseIterationChangelog(taskCtx, item.ValueBeforeParsed, item.ValueAfterParsed)
@@ -119,3 +129,24 @@ func ExtractStoryChangelog(taskCtx core.SubTaskContext) 
errors.Error {
 
        return extractor.Execute()
 }
+
+func unicodeToZh(s string) (string, error) {
+       str, err := strconv.Unquote(strings.Replace(strconv.Quote(s), `\\u`, 
`\u`, -1))
+       if err != nil {
+               return "", err
+       }
+       return str, nil
+}
+
+func convertUnicode(item *models.TapdStoryChangelogItem) errors.Error {
+       var err errors.Error
+       item.ValueAfterParsed, err = 
errors.Convert01(unicodeToZh(item.ValueAfterParsed))
+       if err != nil {
+               return err
+       }
+       item.ValueBeforeParsed, err = 
errors.Convert01(unicodeToZh(item.ValueBeforeParsed))
+       if err != nil {
+               return err
+       }
+       return nil
+}

Reply via email to