MCPcopy Index your code
hub / github.com/git-bug/git-bug / ensureComment

Method ensureComment

bridge/github/import.go:448–489  ·  view source on GitHub ↗
(ctx context.Context, repo *cache.RepoCache, b *cache.BugCache, comment *issueComment, firstEdit *userContentEdit)

Source from the content-addressed store, hash-verified

446}
447
448func (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
492func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCache, actor *actor) (*cache.IdentityCache, error) {

Callers 2

ImportAllMethod · 0.95
ensureTimelineItemMethod · 0.95

Calls 8

ensurePersonMethod · 0.95
CleanupFunction · 0.92
NewImportCommentFunction · 0.92
parseIdFunction · 0.85
AddCommentRawMethod · 0.80
StringMethod · 0.65
IdMethod · 0.65

Tested by

no test coverage detected