issueHandlerFactory returns a handler that save record into `issues`, `board_issues` and `issue_labels` table
(boardId string, incremental bool)
| 319 | |
| 320 | // issueHandlerFactory returns a handler that save record into `issues`, `board_issues` and `issue_labels` table |
| 321 | func (s *Service) issueHandlerFactory(boardId string, incremental bool) func(record map[string]interface{}) errors.Error { |
| 322 | return func(record map[string]interface{}) errors.Error { |
| 323 | var err errors.Error |
| 324 | id, err := getStringField(record, "id", true) |
| 325 | if err != nil { |
| 326 | return err |
| 327 | } |
| 328 | |
| 329 | // Handle labels |
| 330 | labels, err := getStringField(record, "labels", false) |
| 331 | if err != nil { |
| 332 | return err |
| 333 | } |
| 334 | if labels != "" { |
| 335 | var issueLabels []*ticket.IssueLabel |
| 336 | appearedLabels := make(map[string]struct{}) // record the labels that have appeared |
| 337 | for _, label := range strings.Split(labels, ",") { |
| 338 | label = strings.TrimSpace(label) |
| 339 | if label == "" { |
| 340 | continue |
| 341 | } |
| 342 | if _, appeared := appearedLabels[label]; !appeared { |
| 343 | issueLabel := &ticket.IssueLabel{ |
| 344 | IssueId: id, |
| 345 | LabelName: label, |
| 346 | NoPKModel: common.NoPKModel{ |
| 347 | RawDataOrigin: common.RawDataOrigin{ |
| 348 | RawDataParams: boardId, |
| 349 | }, |
| 350 | }, |
| 351 | } |
| 352 | issueLabels = append(issueLabels, issueLabel) |
| 353 | appearedLabels[label] = struct{}{} |
| 354 | } |
| 355 | } |
| 356 | if len(issueLabels) > 0 { |
| 357 | err = s.dal.CreateOrUpdate(issueLabels) |
| 358 | if err != nil { |
| 359 | return err |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | delete(record, "labels") // Remove labels from record map as it's handled |
| 364 | |
| 365 | // Handle creator and assignee accounts |
| 366 | rawDataParams, err := getStringField(record, "_raw_data_params", true) |
| 367 | if err != nil { |
| 368 | // This should ideally not happen as it's set in importCSV, but good to check |
| 369 | return err |
| 370 | } |
| 371 | |
| 372 | // Handle creator |
| 373 | creatorName, err := getStringField(record, "creator_name", false) |
| 374 | if err != nil { |
| 375 | return err |
| 376 | } |
| 377 | creatorId, err := s.createOrUpdateAccount(creatorName, rawDataParams) |
| 378 | if err != nil { |
no test coverage detected