Skip to content

Commit

Permalink
fix(jira): fix account id when there is no from/to values (#7734) (#7735
Browse files Browse the repository at this point in the history
)

Co-authored-by: Lynwee <linwei.hou@merico.dev>
  • Loading branch information
github-actions[bot] and d4x1 authored Jul 15, 2024
1 parent 4f36381 commit 5ccfd15
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions backend/plugins/jira/tasks/issue_changelog_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,13 @@ func ConvertIssueChangelogs(taskCtx 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)
}
}

Expand All @@ -201,6 +181,25 @@ func ConvertIssueChangelogs(taskCtx 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
Expand Down

0 comments on commit 5ccfd15

Please sign in to comment.