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

lynwee pushed a commit to branch 10-cp
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit a05e7020e50a2f3496f4e43e7ca458f732d741fb
Author: d4x1 <[email protected]>
AuthorDate: Mon Jul 15 12:35:00 2024 +0800

    fix(jira): fix account id when there is no from/to values
---
 .../jira/tasks/issue_changelog_convertor.go        | 51 +++++++++++-----------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/backend/plugins/jira/tasks/issue_changelog_convertor.go 
b/backend/plugins/jira/tasks/issue_changelog_convertor.go
index d4cdc7998..1eeafb131 100644
--- a/backend/plugins/jira/tasks/issue_changelog_convertor.go
+++ b/backend/plugins/jira/tasks/issue_changelog_convertor.go
@@ -159,33 +159,13 @@ func ConvertIssueChangelogs(subtaskCtx 
plugin.SubTaskContext) errors.Error {
                                        changelog.ToValue = 
getStdStatus(toStatus.StatusCategory)
                                }
                        default:
-                               // process other account-like fields, it works 
on jira9 and jira cloud.
-                               if row.TmpFromAccountId != "" {
-                                       if row.FromValue != "" {
-                                               changelog.OriginalFromValue = 
accountIdGen.Generate(connectionId, row.FromValue)
-                                       } else {
-                                               changelog.OriginalFromValue = 
accountIdGen.Generate(connectionId, row.TmpFromAccountId)
-                                       }
+                               fromAccountId := 
tryToResolveAccountIdFromAccountLikeField(row.Field, row.TmpFromAccountId, 
row.FromValue, issueFieldMap)
+                               if fromAccountId != "" {
+                                       changelog.OriginalFromValue = 
accountIdGen.Generate(connectionId, fromAccountId)
                                }
-                               if row.TmpToAccountId != "" {
-                                       if row.ToValue != "" {
-                                               changelog.OriginalToValue = 
accountIdGen.Generate(connectionId, row.ToValue)
-                                       } else {
-                                               changelog.OriginalToValue = 
accountIdGen.Generate(connectionId, row.TmpToAccountId)
-                                       }
-                               }
-                               if row.TmpFromAccountId == "" && 
row.TmpToAccountId == "" {
-                                       // it works on jira8
-                                       // notice: field name is not unique, 
but we cannot fetch field id here.
-                                       if v, ok := issueFieldMap[row.Field]; 
ok && v.SchemaType == "user" {
-                                               // field type is account
-                                               if row.FromValue != "" {
-                                                       
changelog.OriginalFromValue = accountIdGen.Generate(connectionId, row.FromValue)
-                                               }
-                                               if row.ToValue != "" {
-                                                       
changelog.OriginalToValue = accountIdGen.Generate(connectionId, row.ToValue)
-                                               }
-                                       }
+                               toAccountId := 
tryToResolveAccountIdFromAccountLikeField(row.Field, row.TmpFromAccountId, 
row.FromValue, issueFieldMap)
+                               if toAccountId != "" {
+                                       changelog.OriginalToValue = 
accountIdGen.Generate(connectionId, toAccountId)
                                }
                        }
 
@@ -201,6 +181,25 @@ func ConvertIssueChangelogs(subtaskCtx 
plugin.SubTaskContext) errors.Error {
        return converter.Execute()
 }
 
+func tryToResolveAccountIdFromAccountLikeField(fieldName string, tmpAccountId 
string, fromOrToValue string, issueFieldMap map[string]models.JiraIssueField) 
string {
+       if tmpAccountId != "" {
+               // process other account-like fields, it works on jira9 and 
jira cloud.
+               if fromOrToValue != "" {
+                       return fromOrToValue
+               } else {
+                       return tmpAccountId
+               }
+       } else {
+               // it works on jira8
+               // notice: field name is not unique, but we cannot fetch field 
id here.
+               if v, ok := issueFieldMap[fieldName]; ok && v.SchemaType == 
"user" {
+                       // field type is account
+                       return fromOrToValue
+               }
+       }
+       return ""
+}
+
 func convertIds(ids string, connectionId uint64, sprintIdGenerator 
*didgen.DomainIdGenerator) (string, errors.Error) {
        ss := strings.Split(ids, ",")
        var resultSlice []string

Reply via email to