(ctx context.Context, repo *cache.RepoCache, b *cache.BugCache, comment *issueComment, firstEdit *userContentEdit)
| 446 | } |
| 447 | |
| 448 | func (gi *githubImporter) ensureComment(ctx context.Context, repo *cache.RepoCache, b *cache.BugCache, comment *issueComment, firstEdit *userContentEdit) error { |
| 449 | author, err := gi.ensurePerson(ctx, repo, comment.Author) |
| 450 | if err != nil { |
| 451 | return err |
| 452 | } |
| 453 | |
| 454 | _, err = b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(comment.Id)) |
| 455 | if err == nil { |
| 456 | return nil |
| 457 | } |
| 458 | if err != cache.ErrNoMatchingOp { |
| 459 | // real error |
| 460 | return err |
| 461 | } |
| 462 | |
| 463 | var textInput string |
| 464 | if firstEdit != nil { |
| 465 | // use the first comment edit: it represents the comment creation itself |
| 466 | textInput = string(*firstEdit.Diff) |
| 467 | } else { |
| 468 | // if there are not comment edits, then the comment struct holds the comment creation |
| 469 | textInput = string(comment.Body) |
| 470 | } |
| 471 | |
| 472 | // add comment operation |
| 473 | commentId, _, err := b.AddCommentRaw( |
| 474 | author, |
| 475 | comment.CreatedAt.Unix(), |
| 476 | text.Cleanup(textInput), |
| 477 | nil, |
| 478 | map[string]string{ |
| 479 | metaKeyGithubId: parseId(comment.Id), |
| 480 | metaKeyGithubUrl: comment.Url.String(), |
| 481 | }, |
| 482 | ) |
| 483 | if err != nil { |
| 484 | return err |
| 485 | } |
| 486 | |
| 487 | gi.out <- core.NewImportComment(b.Id(), commentId) |
| 488 | return nil |
| 489 | } |
| 490 | |
| 491 | // ensurePerson create a bug.Person from the Github data |
| 492 | func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCache, actor *actor) (*cache.IdentityCache, error) { |
no test coverage detected