From b932930fd476dcdcee919ab0bdb3ba9edd952e3d Mon Sep 17 00:00:00 2001 From: d4x1 <1507509064@qq.com> Date: Mon, 15 Jul 2024 12:35:00 +0800 Subject: [PATCH] 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 d4cdc7998f0..1eeafb1310c 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