bridge/gitlab: importer and exporter correctly emit NothingEvents

amine created

Change summary

bridge/gitlab/export.go | 13 +++++++------
bridge/gitlab/import.go |  9 ++++-----
2 files changed, 11 insertions(+), 11 deletions(-)

Detailed changes

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
@@ -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)
@@ -237,14 +234,12 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc
 		// cache the ID of already exported or imported issues and events from Gitlab
 		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")
 	}
 }
 

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
@@ -99,7 +101,6 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
 	// resolve bug
 	b, err := repo.ResolveBugCreateMetadata(metaKeyGitlabUrl, issue.WebURL)
 	if err == nil {
-		gi.out <- core.NewImportNothing("", "bug already imported")
 		return b, nil
 	}
 	if err != bug.ErrBugNotExist {
@@ -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: