From e678e81bc70638a1217b3c657fcdf7e270c3e222 Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Tue, 30 Jul 2019 23:51:37 +0200 Subject: bridge/gitlab: fix bug when running import multiple times --- bridge/gitlab/import.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'bridge') diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index e9426016..dbedfda8 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -132,6 +132,11 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, note *gitlab.Note) error { id := parseID(note.ID) + hash, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, id) + if errResolve != nil && errResolve != cache.ErrNoMatchingOp { + return errResolve + } + // ensure issue author author, err := gi.ensurePerson(repo, note.Author.ID) if err != nil { @@ -141,6 +146,10 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n noteType, body := GetNoteType(note) switch noteType { case NOTE_CLOSED: + if errResolve == nil { + return nil + } + _, err = b.CloseRaw( author, note.CreatedAt.Unix(), @@ -151,6 +160,10 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n return err case NOTE_REOPENED: + if errResolve == nil { + return nil + } + _, err = b.OpenRaw( author, note.CreatedAt.Unix(), @@ -167,8 +180,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n // since gitlab doesn't provide the issue history // we should check for "changed the description" notes and compare issue texts // TODO: Check only one time and ignore next 'description change' within one issue - if issue.Description != firstComment.Message { - + if errResolve == cache.ErrNoMatchingOp && issue.Description != firstComment.Message { // comment edition _, err = b.EditCommentRaw( author, @@ -184,11 +196,6 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n } case NOTE_COMMENT: - hash, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, id) - if errResolve != cache.ErrNoMatchingOp { - return errResolve - } - cleanText, err := text.Cleanup(body) if err != nil { return err @@ -237,6 +244,10 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n case NOTE_TITLE_CHANGED: // title change events are given new notes + if errResolve == nil { + return nil + } + _, err = b.SetTitleRaw( author, note.CreatedAt.Unix(), -- cgit