aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/import.go
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/github/import.go')
-rw-r--r--bridge/github/import.go108
1 files changed, 45 insertions, 63 deletions
diff --git a/bridge/github/import.go b/bridge/github/import.go
index 7c4deb50..86444057 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -15,10 +15,9 @@ import (
)
const (
- keyOrigin = "origin"
- keyGithubId = "github-id"
- keyGithubUrl = "github-url"
- keyGithubLogin = "github-login"
+ metaKeyGithubId = "github-id"
+ metaKeyGithubUrl = "github-url"
+ metaKeyGithubLogin = "github-login"
)
// githubImporter implement the Importer interface
@@ -61,15 +60,18 @@ func (gi *githubImporter) ImportAll(ctx context.Context, repo *cache.RepoCache,
// loop over timeline items
for gi.iterator.NextTimelineItem() {
item := gi.iterator.TimelineItemValue()
- if err := gi.ensureTimelineItem(repo, b, item); err != nil {
- err := fmt.Errorf("timeline item creation: %v", err)
+ err := gi.ensureTimelineItem(repo, b, item)
+ if err != nil {
+ err = fmt.Errorf("timeline item creation: %v", err)
out <- core.NewImportError(err, "")
return
}
}
- // commit bug state
- if err := b.CommitAsNeeded(); err != nil {
+ if !b.NeedCommit() {
+ out <- core.NewImportNothing(b.Id(), "no imported operation")
+ } else if err := b.Commit(); err != nil {
+ // commit bug state
err = fmt.Errorf("bug commit: %v", err)
out <- core.NewImportError(err, "")
return
@@ -92,7 +94,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
}
// resolve bug
- b, err := repo.ResolveBugCreateMetadata(keyGithubUrl, issue.Url.String())
+ b, err := repo.ResolveBugCreateMetadata(metaKeyGithubUrl, issue.Url.String())
if err != nil && err != bug.ErrBugNotExist {
return nil, err
}
@@ -119,9 +121,9 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
cleanText,
nil,
map[string]string{
- keyOrigin: target,
- keyGithubId: parseId(issue.Id),
- keyGithubUrl: issue.Url.String(),
+ core.MetaKeyOrigin: target,
+ metaKeyGithubId: parseId(issue.Id),
+ metaKeyGithubUrl: issue.Url.String(),
})
if err != nil {
return nil, err
@@ -129,16 +131,12 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
// importing a new bug
gi.out <- core.NewImportBug(b.Id())
- } else {
- gi.out <- core.NewImportNothing("", "bug already imported")
}
-
} else {
// create bug from given issueEdits
for i, edit := range issueEdits {
if i == 0 && b != nil {
// The first edit in the github result is the issue creation itself, we already have that
- gi.out <- core.NewImportNothing("", "bug already imported")
continue
}
@@ -157,23 +155,22 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
cleanText,
nil,
map[string]string{
- keyOrigin: target,
- keyGithubId: parseId(issue.Id),
- keyGithubUrl: issue.Url.String(),
+ core.MetaKeyOrigin: target,
+ metaKeyGithubId: parseId(issue.Id),
+ metaKeyGithubUrl: issue.Url.String(),
},
)
if err != nil {
return nil, err
}
-
// importing a new bug
gi.out <- core.NewImportBug(b.Id())
continue
}
// other edits will be added as CommentEdit operations
- target, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(issue.Id))
+ target, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(issue.Id))
if err != nil {
return nil, err
}
@@ -203,13 +200,12 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
if err != nil {
return fmt.Errorf("timeline comment creation: %v", err)
}
+ return nil
case "LabeledEvent":
id := parseId(item.LabeledEvent.Id)
- _, err := b.ResolveOperationWithMetadata(keyGithubId, id)
+ _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id)
if err == nil {
- reason := fmt.Sprintf("operation already imported: %v", item.Typename)
- gi.out <- core.NewImportNothing("", reason)
return nil
}
@@ -227,7 +223,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
string(item.LabeledEvent.Label.Name),
},
nil,
- map[string]string{keyGithubId: id},
+ map[string]string{metaKeyGithubId: id},
)
if err != nil {
return err
@@ -238,10 +234,8 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
case "UnlabeledEvent":
id := parseId(item.UnlabeledEvent.Id)
- _, err := b.ResolveOperationWithMetadata(keyGithubId, id)
+ _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id)
if err == nil {
- reason := fmt.Sprintf("operation already imported: %v", item.Typename)
- gi.out <- core.NewImportNothing("", reason)
return nil
}
if err != cache.ErrNoMatchingOp {
@@ -259,7 +253,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
[]string{
string(item.UnlabeledEvent.Label.Name),
},
- map[string]string{keyGithubId: id},
+ map[string]string{metaKeyGithubId: id},
)
if err != nil {
return err
@@ -270,13 +264,11 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
case "ClosedEvent":
id := parseId(item.ClosedEvent.Id)
- _, err := b.ResolveOperationWithMetadata(keyGithubId, id)
+ _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id)
if err != cache.ErrNoMatchingOp {
return err
}
if err == nil {
- reason := fmt.Sprintf("operation already imported: %v", item.Typename)
- gi.out <- core.NewImportNothing("", reason)
return nil
}
author, err := gi.ensurePerson(repo, item.ClosedEvent.Actor)
@@ -286,7 +278,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
op, err := b.CloseRaw(
author,
item.ClosedEvent.CreatedAt.Unix(),
- map[string]string{keyGithubId: id},
+ map[string]string{metaKeyGithubId: id},
)
if err != nil {
@@ -298,13 +290,11 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
case "ReopenedEvent":
id := parseId(item.ReopenedEvent.Id)
- _, err := b.ResolveOperationWithMetadata(keyGithubId, id)
+ _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id)
if err != cache.ErrNoMatchingOp {
return err
}
if err == nil {
- reason := fmt.Sprintf("operation already imported: %v", item.Typename)
- gi.out <- core.NewImportNothing("", reason)
return nil
}
author, err := gi.ensurePerson(repo, item.ReopenedEvent.Actor)
@@ -314,7 +304,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
op, err := b.OpenRaw(
author,
item.ReopenedEvent.CreatedAt.Unix(),
- map[string]string{keyGithubId: id},
+ map[string]string{metaKeyGithubId: id},
)
if err != nil {
@@ -326,13 +316,11 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
case "RenamedTitleEvent":
id := parseId(item.RenamedTitleEvent.Id)
- _, err := b.ResolveOperationWithMetadata(keyGithubId, id)
+ _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id)
if err != cache.ErrNoMatchingOp {
return err
}
if err == nil {
- reason := fmt.Sprintf("operation already imported: %v", item.Typename)
- gi.out <- core.NewImportNothing("", reason)
return nil
}
author, err := gi.ensurePerson(repo, item.RenamedTitleEvent.Actor)
@@ -343,7 +331,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
author,
item.RenamedTitleEvent.CreatedAt.Unix(),
string(item.RenamedTitleEvent.CurrentTitle),
- map[string]string{keyGithubId: id},
+ map[string]string{metaKeyGithubId: id},
)
if err != nil {
return err
@@ -351,10 +339,6 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
gi.out <- core.NewImportTitleEdition(op.Id())
return nil
-
- default:
- reason := fmt.Sprintf("ignoring timeline type: %v", item.Typename)
- gi.out <- core.NewImportNothing("", reason)
}
return nil
@@ -367,10 +351,8 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache.
return err
}
- targetOpID, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(item.Id))
- if err == nil {
- gi.out <- core.NewImportNothing("", "comment already imported")
- } else if err != cache.ErrNoMatchingOp {
+ targetOpID, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(item.Id))
+ if err != nil && err != cache.ErrNoMatchingOp {
// real error
return err
}
@@ -390,8 +372,8 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache.
cleanText,
nil,
map[string]string{
- keyGithubId: parseId(item.Id),
- keyGithubUrl: parseId(item.Url.String()),
+ metaKeyGithubId: parseId(item.Id),
+ metaKeyGithubUrl: parseId(item.Url.String()),
},
)
if err != nil {
@@ -399,13 +381,13 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache.
}
gi.out <- core.NewImportComment(op.Id())
+ return nil
}
} else {
for i, edit := range edits {
if i == 0 && targetOpID != "" {
// The first edit in the github result is the comment creation itself, we already have that
- gi.out <- core.NewImportNothing("", "comment already imported")
continue
}
@@ -428,13 +410,14 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache.
cleanText,
nil,
map[string]string{
- keyGithubId: parseId(item.Id),
- keyGithubUrl: item.Url.String(),
+ metaKeyGithubId: parseId(item.Id),
+ metaKeyGithubUrl: item.Url.String(),
},
)
if err != nil {
return err
}
+ gi.out <- core.NewImportComment(op.Id())
// set target for the nexr edit now that the comment is created
targetOpID = op.Id()
@@ -451,9 +434,8 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache.
}
func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugCache, target entity.Id, edit userContentEdit) error {
- _, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(edit.Id))
+ _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(edit.Id))
if err == nil {
- gi.out <- core.NewImportNothing(b.Id(), "edition already imported")
return nil
}
if err != cache.ErrNoMatchingOp {
@@ -469,7 +451,7 @@ func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugC
switch {
case edit.DeletedAt != nil:
// comment deletion, not supported yet
- gi.out <- core.NewImportNothing(b.Id(), "comment deletion is not supported yet")
+ return nil
case edit.DeletedAt == nil:
@@ -485,7 +467,7 @@ func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugC
target,
cleanText,
map[string]string{
- keyGithubId: parseId(edit.Id),
+ metaKeyGithubId: parseId(edit.Id),
},
)
@@ -494,8 +476,8 @@ func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugC
}
gi.out <- core.NewImportCommentEdition(op.Id())
+ return nil
}
-
return nil
}
@@ -508,7 +490,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca
}
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(keyGithubLogin, string(actor.Login))
+ i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, string(actor.Login))
if err == nil {
return i, nil
}
@@ -543,7 +525,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca
string(actor.Login),
string(actor.AvatarUrl),
map[string]string{
- keyGithubLogin: string(actor.Login),
+ metaKeyGithubLogin: string(actor.Login),
},
)
@@ -557,7 +539,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca
func (gi *githubImporter) getGhost(repo *cache.RepoCache) (*cache.IdentityCache, error) {
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(keyGithubLogin, "ghost")
+ i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, "ghost")
if err == nil {
return i, nil
}
@@ -592,7 +574,7 @@ func (gi *githubImporter) getGhost(repo *cache.RepoCache) (*cache.IdentityCache,
string(q.User.Login),
string(q.User.AvatarUrl),
map[string]string{
- keyGithubLogin: string(q.User.Login),
+ metaKeyGithubLogin: string(q.User.Login),
},
)
}