aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/gitlab')
-rw-r--r--bridge/gitlab/config.go6
-rw-r--r--bridge/gitlab/export.go31
-rw-r--r--bridge/gitlab/export_test.go10
-rw-r--r--bridge/gitlab/gitlab.go8
-rw-r--r--bridge/gitlab/import.go43
-rw-r--r--bridge/gitlab/import_test.go2
6 files changed, 50 insertions, 50 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go
index a673af8c..f2e667a8 100644
--- a/bridge/gitlab/config.go
+++ b/bridge/gitlab/config.go
@@ -80,7 +80,7 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams)
conf[keyProjectID] = strconv.Itoa(id)
conf[keyToken] = token
- conf[core.KeyTarget] = target
+ conf[core.ConfigKeyTarget] = target
err = g.ValidateConfig(conf)
if err != nil {
@@ -91,8 +91,8 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams)
}
func (g *Gitlab) 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/gitlab/export.go b/bridge/gitlab/export.go
index 251d720a..7c00e39d 100644
--- a/bridge/gitlab/export.go
+++ b/bridge/gitlab/export.go
@@ -117,8 +117,6 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
if snapshot.HasAnyActor(allIdentitiesIds...) {
// try to export the bug and it associated events
ge.exportBug(ctx, b, since, out)
- } else {
- out <- core.NewExportNothing(id, "not an actor")
}
}
}
@@ -131,6 +129,7 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, since time.Time, out chan<- core.ExportResult) {
snapshot := b.Snapshot()
+ var bugUpdated bool
var err error
var bugGitlabID int
var bugGitlabIDString string
@@ -141,7 +140,7 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
// from Gitlab) and we do not have the token of the bug author, there is nothing we can do.
// skip bug if origin is not allowed
- origin, ok := snapshot.GetCreateMetadata(core.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
@@ -152,9 +151,9 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
author := snapshot.Author
// get gitlab bug ID
- gitlabID, ok := snapshot.GetCreateMetadata(keyGitlabId)
+ gitlabID, ok := snapshot.GetCreateMetadata(metaKeyGitlabId)
if ok {
- projectID, ok := snapshot.GetCreateMetadata(keyGitlabProject)
+ projectID, ok := snapshot.GetCreateMetadata(metaKeyGitlabProject)
if !ok {
err := fmt.Errorf("expected to find gitlab project id")
out <- core.NewExportError(err, b.Id())
@@ -166,8 +165,6 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
return
}
- out <- core.NewExportNothing(b.Id(), "bug already exported")
-
// will be used to mark operation related to a bug as exported
bugGitlabIDString = gitlabID
bugGitlabID, err = strconv.Atoi(bugGitlabIDString)
@@ -199,9 +196,9 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
_, err = b.SetMetadata(
createOp.Id(),
map[string]string{
- keyGitlabId: idString,
- keyGitlabUrl: url,
- keyGitlabProject: ge.repositoryID,
+ metaKeyGitlabId: idString,
+ metaKeyGitlabUrl: url,
+ metaKeyGitlabProject: ge.repositoryID,
},
)
if err != nil {
@@ -235,16 +232,14 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
// ignore operations already existing in gitlab (due to import or export)
// cache the ID of already exported or imported issues and events from Gitlab
- if id, ok := op.GetMetadata(keyGitlabId); ok {
+ if id, ok := op.GetMetadata(metaKeyGitlabId); ok {
ge.cachedOperationIDs[op.Id().String()] = id
- out <- core.NewExportNothing(op.Id(), "already exported operation")
continue
}
opAuthor := op.GetAuthor()
client, err := ge.getIdentityClient(opAuthor.Id())
if err != nil {
- out <- core.NewExportNothing(op.Id(), "missing operation author token")
continue
}
@@ -371,6 +366,12 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
out <- core.NewExportError(err, b.Id())
return
}
+
+ bugUpdated = true
+ }
+
+ if !bugUpdated {
+ out <- core.NewExportNothing(b.Id(), "nothing has been exported")
}
}
@@ -378,8 +379,8 @@ func markOperationAsExported(b *cache.BugCache, target entity.Id, gitlabID, gitl
_, err := b.SetMetadata(
target,
map[string]string{
- keyGitlabId: gitlabID,
- keyGitlabUrl: gitlabURL,
+ metaKeyGitlabId: gitlabID,
+ metaKeyGitlabUrl: gitlabURL,
},
)
diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go
index 3d3f406f..26b47bfb 100644
--- a/bridge/gitlab/export_test.go
+++ b/bridge/gitlab/export_test.go
@@ -236,27 +236,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(keyGitlabId)
+ _, haveIDMetadata := op.GetMetadata(metaKeyGitlabId)
require.True(t, haveIDMetadata)
- _, haveURLMetada := op.GetMetadata(keyGitlabUrl)
+ _, haveURLMetada := op.GetMetadata(metaKeyGitlabUrl)
require.True(t, haveURLMetada)
}
}
// get bug gitlab ID
- bugGitlabID, ok := tt.bug.Snapshot().GetCreateMetadata(keyGitlabId)
+ bugGitlabID, ok := tt.bug.Snapshot().GetCreateMetadata(metaKeyGitlabId)
require.True(t, ok)
// retrieve bug from backendTwo
- importedBug, err := backendTwo.ResolveBugCreateMetadata(keyGitlabId, bugGitlabID)
+ importedBug, err := backendTwo.ResolveBugCreateMetadata(metaKeyGitlabId, bugGitlabID)
require.NoError(t, err)
// verify bug have same number of original operations
require.Len(t, importedBug.Snapshot().Operations, tt.numOpImp)
// verify bugs are taged with origin=gitlab
- issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.KeyOrigin)
+ issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.MetaKeyOrigin)
require.True(t, ok)
require.Equal(t, issueOrigin, target)
diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go
index 05721bfe..d976d813 100644
--- a/bridge/gitlab/gitlab.go
+++ b/bridge/gitlab/gitlab.go
@@ -12,10 +12,10 @@ import (
const (
target = "gitlab"
- keyGitlabId = "gitlab-id"
- keyGitlabUrl = "gitlab-url"
- keyGitlabLogin = "gitlab-login"
- keyGitlabProject = "gitlab-project-id"
+ metaKeyGitlabId = "gitlab-id"
+ metaKeyGitlabUrl = "gitlab-url"
+ metaKeyGitlabLogin = "gitlab-login"
+ metaKeyGitlabProject = "gitlab-project-id"
keyProjectID = "project-id"
keyToken = "token"
diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go
index e2015773..92e9952e 100644
--- a/bridge/gitlab/import.go
+++ b/bridge/gitlab/import.go
@@ -73,8 +73,10 @@ func (gi *gitlabImporter) ImportAll(ctx context.Context, repo *cache.RepoCache,
}
}
- // 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
@@ -97,9 +99,8 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
}
// resolve bug
- b, err := repo.ResolveBugCreateMetadata(keyGitlabUrl, issue.WebURL)
+ b, err := repo.ResolveBugCreateMetadata(metaKeyGitlabUrl, issue.WebURL)
if err == nil {
- gi.out <- core.NewImportNothing("", "bug already imported")
return b, nil
}
if err != bug.ErrBugNotExist {
@@ -120,10 +121,10 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
cleanText,
nil,
map[string]string{
- core.KeyOrigin: target,
- keyGitlabId: parseID(issue.IID),
- keyGitlabUrl: issue.WebURL,
- keyGitlabProject: gi.conf[keyProjectID],
+ core.MetaKeyOrigin: target,
+ metaKeyGitlabId: parseID(issue.IID),
+ metaKeyGitlabUrl: issue.WebURL,
+ metaKeyGitlabProject: gi.conf[keyProjectID],
},
)
@@ -140,7 +141,7 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, note *gitlab.Note) error {
gitlabID := parseID(note.ID)
- id, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, gitlabID)
+ id, errResolve := b.ResolveOperationWithMetadata(metaKeyGitlabId, gitlabID)
if errResolve != nil && errResolve != cache.ErrNoMatchingOp {
return errResolve
}
@@ -162,7 +163,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
author,
note.CreatedAt.Unix(),
map[string]string{
- keyGitlabId: gitlabID,
+ metaKeyGitlabId: gitlabID,
},
)
if err != nil {
@@ -180,7 +181,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
author,
note.CreatedAt.Unix(),
map[string]string{
- keyGitlabId: gitlabID,
+ metaKeyGitlabId: gitlabID,
},
)
if err != nil {
@@ -204,7 +205,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
firstComment.Id(),
issue.Description,
map[string]string{
- keyGitlabId: gitlabID,
+ metaKeyGitlabId: gitlabID,
},
)
if err != nil {
@@ -230,7 +231,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
cleanText,
nil,
map[string]string{
- keyGitlabId: gitlabID,
+ metaKeyGitlabId: gitlabID,
},
)
if err != nil {
@@ -278,7 +279,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
note.CreatedAt.Unix(),
body,
map[string]string{
- keyGitlabId: gitlabID,
+ metaKeyGitlabId: gitlabID,
},
)
if err != nil {
@@ -299,8 +300,6 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
NOTE_MENTIONED_IN_ISSUE,
NOTE_MENTIONED_IN_MERGE_REQUEST:
- reason := fmt.Sprintf("unsupported note type: %s", noteType.String())
- gi.out <- core.NewImportNothing("", reason)
return nil
default:
@@ -311,7 +310,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
}
func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCache, labelEvent *gitlab.LabelEvent) error {
- _, err := b.ResolveOperationWithMetadata(keyGitlabId, parseID(labelEvent.ID))
+ _, err := b.ResolveOperationWithMetadata(metaKeyGitlabId, parseID(labelEvent.ID))
if err != cache.ErrNoMatchingOp {
return err
}
@@ -330,7 +329,7 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa
[]string{labelEvent.Label.Name},
nil,
map[string]string{
- keyGitlabId: parseID(labelEvent.ID),
+ metaKeyGitlabId: parseID(labelEvent.ID),
},
)
@@ -341,7 +340,7 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa
nil,
[]string{labelEvent.Label.Name},
map[string]string{
- keyGitlabId: parseID(labelEvent.ID),
+ metaKeyGitlabId: parseID(labelEvent.ID),
},
)
@@ -354,7 +353,7 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa
func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.IdentityCache, error) {
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(keyGitlabId, strconv.Itoa(id))
+ i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGitlabId, strconv.Itoa(id))
if err == nil {
return i, nil
}
@@ -376,8 +375,8 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id
user.AvatarURL,
map[string]string{
// because Gitlab
- keyGitlabId: strconv.Itoa(id),
- keyGitlabLogin: user.Username,
+ metaKeyGitlabId: strconv.Itoa(id),
+ metaKeyGitlabLogin: user.Username,
},
)
if err != nil {
diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go
index a6fd8524..8e596349 100644
--- a/bridge/gitlab/import_test.go
+++ b/bridge/gitlab/import_test.go
@@ -116,7 +116,7 @@ func TestImport(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- b, err := backend.ResolveBugCreateMetadata(keyGitlabUrl, tt.url)
+ b, err := backend.ResolveBugCreateMetadata(metaKeyGitlabUrl, tt.url)
require.NoError(t, err)
ops := b.Snapshot().Operations