in backend/plugins/jira/tasks/issue_extractor.go [87:198]
func extractIssues(data *JiraTaskData, mappings *typeMappings, row *api.RawData) ([]interface{}, errors.Error) {
var apiIssue apiv2models.Issue
err := errors.Convert(json.Unmarshal(row.Data, &apiIssue))
if err != nil {
return nil, err
}
err = apiIssue.SetAllFields(row.Data)
if err != nil {
return nil, err
}
var results []interface{}
// if the field `created` is nil, ignore it
if apiIssue.Fields.Created == nil {
return results, nil
}
sprints, issue, comments, worklogs, changelogs, changelogItems, users := apiIssue.ExtractEntities(data.Options.ConnectionId)
for _, sprintId := range sprints {
sprintIssue := &models.JiraSprintIssue{
ConnectionId: data.Options.ConnectionId,
SprintId: sprintId,
IssueId: issue.IssueId,
IssueCreatedDate: &issue.Created,
ResolutionDate: issue.ResolutionDate,
}
results = append(results, sprintIssue)
}
if issue.ResolutionDate != nil {
issue.LeadTimeMinutes = uint(issue.ResolutionDate.Unix()-issue.Created.Unix()) / 60
}
if data.Options.ScopeConfig != nil && data.Options.ScopeConfig.StoryPointField != "" {
unknownStoryPoint := apiIssue.Fields.AllFields[data.Options.ScopeConfig.StoryPointField]
switch sp := unknownStoryPoint.(type) {
case string:
// string, try to parse
issue.StoryPoint, _ = strconv.ParseFloat(sp, 32)
case nil:
default:
// not string, convert to float64, ignore it if failed
issue.StoryPoint, _ = unknownStoryPoint.(float64)
}
}
// code in next line will set issue.Type to issueType.Name
issue.Type = mappings.typeIdMappings[issue.Type]
issue.StdType = mappings.stdTypeMappings[issue.Type]
if issue.StdType == "" {
issue.StdType = strings.ToUpper(issue.Type)
}
issue.StdStatus = getStdStatus(issue.StatusKey)
if value, ok := mappings.standardStatusMappings[issue.Type][issue.StatusKey]; ok {
issue.StdStatus = value.StandardStatus
}
results = append(results, issue)
for _, comment := range comments {
results = append(results, comment)
}
for _, worklog := range worklogs {
results = append(results, worklog)
}
var issueUpdated *time.Time
// likely this issue has more changelogs to be collected
if len(changelogs) == 100 {
issueUpdated = nil
} else {
issueUpdated = &issue.Updated
}
for _, changelog := range changelogs {
changelog.IssueUpdated = issueUpdated
results = append(results, changelog)
}
for _, changelogItem := range changelogItems {
results = append(results, changelogItem)
}
for _, user := range users {
if user.AccountId != "" {
results = append(results, user)
}
}
results = append(results, &models.JiraBoardIssue{
ConnectionId: data.Options.ConnectionId,
BoardId: data.Options.BoardId,
IssueId: issue.IssueId,
})
labels := apiIssue.Fields.Labels
for _, v := range labels {
issueLabel := &models.JiraIssueLabel{
IssueId: issue.IssueId,
LabelName: v,
ConnectionId: data.Options.ConnectionId,
}
results = append(results, issueLabel)
}
issuelinks := apiIssue.Fields.Issuelinks
for _, v := range issuelinks {
issueLink := &models.JiraIssueRelationship{
ConnectionId: data.Options.ConnectionId,
IssueId: issue.IssueId,
IssueKey: issue.IssueKey,
TypeId: v.Type.ID, // Extracting the TypeId from the issuelink
TypeName: v.Type.Name, // Extracting the TypeName from the issuelink
Inward: v.Type.Inward, // Extracting the Inward from the issuelink
Outward: v.Type.Outward, // Extracting the Outward from the issuelink
InwardIssueId: v.InwardIssue.ID, // Extracting the InwardIssueId from the issuelink
InwardIssueKey: v.InwardIssue.Key, // Extracting the InwardIssueKey from the issuelink
OutwardIssueId: v.OutwardIssue.ID, // Extracting the OutwardIssueId from the issuelink
OutwardIssueKey: v.OutwardIssue.Key, // Extracting the OutwardIssueKey from the issuelink
}
results = append(results, issueLink)
}
return results, nil
}