diff options
author | amine <hilalyamine@gmail.com> | 2019-11-10 17:48:13 +0100 |
---|---|---|
committer | amine <hilalyamine@gmail.com> | 2019-11-19 19:16:16 +0100 |
commit | 8ffe2a9b03f5d489e12d2d4d2677bbe67a1b53d7 (patch) | |
tree | 165e7aeda2b17b992762fae34863108c345b4524 /bridge/github | |
parent | 57e23c8ada0a9d921a6b68187a76eb5c8b8a407d (diff) | |
download | git-bug-8ffe2a9b03f5d489e12d2d4d2677bbe67a1b53d7.tar.gz |
bridge/launchpad: add missing metadata
bridge: use a specific key for origin metadata
Diffstat (limited to 'bridge/github')
-rw-r--r-- | bridge/github/config.go | 6 | ||||
-rw-r--r-- | bridge/github/export.go | 12 | ||||
-rw-r--r-- | bridge/github/export_test.go | 10 | ||||
-rw-r--r-- | bridge/github/import.go | 65 | ||||
-rw-r--r-- | bridge/github/import_test.go | 2 |
5 files changed, 47 insertions, 48 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go index 16abfa09..434a2c63 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -114,7 +114,7 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) return nil, fmt.Errorf("project doesn't exist or authentication token has an incorrect scope") } - conf[core.KeyTarget] = target + conf[core.ConfigKeyTarget] = target conf[keyToken] = token conf[keyOwner] = owner conf[keyProject] = project @@ -128,8 +128,8 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) } func (*Github) ValidateConfig(conf core.Configuration) error { - if v, ok := conf[core.KeyTarget]; !ok { - return fmt.Errorf("missing %s key", core.KeyTarget) + if v, ok := conf[core.ConfigKeyTarget]; !ok { + return fmt.Errorf("missing %s key", core.ConfigKeyTarget) } else if v != target { return fmt.Errorf("unexpected target name: %v", v) } diff --git a/bridge/github/export.go b/bridge/github/export.go index a79256fc..e2a185b0 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -174,16 +174,16 @@ func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc author := snapshot.Author // skip bug if origin is not allowed - origin, ok := snapshot.GetCreateMetadata(keyOrigin) + origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin) if ok && origin != target { out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin)) return } // get github bug ID - githubID, ok := snapshot.GetCreateMetadata(keyGithubId) + githubID, ok := snapshot.GetCreateMetadata(metaKeyGithubId) if ok { - githubURL, ok := snapshot.GetCreateMetadata(keyGithubUrl) + githubURL, ok := snapshot.GetCreateMetadata(metaKeyGithubUrl) if !ok { // if we find github ID, github URL must be found too err := fmt.Errorf("incomplete Github metadata: expected to find issue URL") @@ -258,7 +258,7 @@ func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc // ignore operations already existing in github (due to import or export) // cache the ID of already exported or imported issues and events from Github - if id, ok := op.GetMetadata(keyGithubId); ok { + if id, ok := op.GetMetadata(metaKeyGithubId); ok { ge.cachedOperationIDs[op.Id()] = id out <- core.NewExportNothing(op.Id(), "already exported operation") continue @@ -437,8 +437,8 @@ func markOperationAsExported(b *cache.BugCache, target entity.Id, githubID, gith _, err := b.SetMetadata( target, map[string]string{ - keyGithubId: githubID, - keyGithubUrl: githubURL, + metaKeyGithubId: githubID, + metaKeyGithubUrl: githubURL, }, ) diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index e39ace01..dba72f3f 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -233,27 +233,27 @@ func TestPushPull(t *testing.T) { for _, op := range tt.bug.Snapshot().Operations { // Check if the originals operations (*not* SetMetadata) are tagged properly if _, ok := op.(*bug.SetMetadataOperation); !ok { - _, haveIDMetadata := op.GetMetadata(keyGithubId) + _, haveIDMetadata := op.GetMetadata(metaKeyGithubId) require.True(t, haveIDMetadata) - _, haveURLMetada := op.GetMetadata(keyGithubUrl) + _, haveURLMetada := op.GetMetadata(metaKeyGithubUrl) require.True(t, haveURLMetada) } } // get bug github ID - bugGithubID, ok := tt.bug.Snapshot().GetCreateMetadata(keyGithubId) + bugGithubID, ok := tt.bug.Snapshot().GetCreateMetadata(metaKeyGithubId) require.True(t, ok) // retrieve bug from backendTwo - importedBug, err := backendTwo.ResolveBugCreateMetadata(keyGithubId, bugGithubID) + importedBug, err := backendTwo.ResolveBugCreateMetadata(metaKeyGithubId, bugGithubID) require.NoError(t, err) // verify bug have same number of original operations require.Len(t, importedBug.Snapshot().Operations, tt.numOrOp) // verify bugs are taged with origin=github - issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(keyOrigin) + issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.MetaKeyOrigin) require.True(t, ok) require.Equal(t, issueOrigin, target) diff --git a/bridge/github/import.go b/bridge/github/import.go index 7c4deb50..d3d56cbc 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 @@ -92,7 +91,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 +118,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 @@ -157,9 +156,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(), }, ) @@ -173,7 +172,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline } // 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 } @@ -206,7 +205,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug 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) @@ -227,7 +226,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,7 +237,7 @@ 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) @@ -259,7 +258,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,7 +269,7 @@ 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 } @@ -286,7 +285,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,7 +297,7 @@ 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 } @@ -314,7 +313,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,7 +325,7 @@ 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 } @@ -343,7 +342,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 @@ -367,7 +366,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. return err } - targetOpID, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(item.Id)) + targetOpID, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(item.Id)) if err == nil { gi.out <- core.NewImportNothing("", "comment already imported") } else if err != cache.ErrNoMatchingOp { @@ -390,8 +389,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 { @@ -428,8 +427,8 @@ 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 { @@ -451,7 +450,7 @@ 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 @@ -485,7 +484,7 @@ func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugC target, cleanText, map[string]string{ - keyGithubId: parseId(edit.Id), + metaKeyGithubId: parseId(edit.Id), }, ) @@ -508,7 +507,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 +542,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 +556,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 +591,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), }, ) } diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go index 41bcb58d..f1558831 100644 --- a/bridge/github/import_test.go +++ b/bridge/github/import_test.go @@ -163,7 +163,7 @@ func Test_Importer(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - b, err := backend.ResolveBugCreateMetadata(keyGithubUrl, tt.url) + b, err := backend.ResolveBugCreateMetadata(metaKeyGithubUrl, tt.url) require.NoError(t, err) ops := b.Snapshot().Operations |