Merge pull request #358 from MichaelMure/gitlab-tests

Michael Muré created

gitlab: fix issues import url

Change summary

bridge/github/import.go      |  5 ++++-
bridge/gitlab/import.go      |  7 ++++++-
bridge/gitlab/import_test.go |  8 ++++----
bridge/jira/import.go        | 12 +++++++++++-
bridge/jira/jira.go          |  1 +
bridge/launchpad/import.go   |  5 ++++-
6 files changed, 30 insertions(+), 8 deletions(-)

Detailed changes

bridge/github/import.go 🔗

@@ -108,7 +108,10 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
 	}
 
 	// resolve bug
-	b, err := repo.ResolveBugCreateMetadata(metaKeyGithubUrl, issue.Url.String())
+	b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+		return excerpt.CreateMetadata[core.MetaKeyOrigin] == target &&
+			excerpt.CreateMetadata[metaKeyGithubId] == parseId(issue.Id)
+	})
 	if err != nil && err != bug.ErrBugNotExist {
 		return nil, err
 	}

bridge/gitlab/import.go 🔗

@@ -123,7 +123,12 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
 	}
 
 	// resolve bug
-	b, err := repo.ResolveBugCreateMetadata(metaKeyGitlabUrl, issue.WebURL)
+	b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+		return excerpt.CreateMetadata[core.MetaKeyOrigin] == target &&
+			excerpt.CreateMetadata[metaKeyGitlabId] == parseID(issue.IID) &&
+			excerpt.CreateMetadata[metaKeyGitlabBaseUrl] == gi.conf[confKeyProjectID] &&
+			excerpt.CreateMetadata[metaKeyGitlabProject] == gi.conf[confKeyGitlabBaseUrl]
+	})
 	if err == nil {
 		return b, nil
 	}

bridge/gitlab/import_test.go 🔗

@@ -29,7 +29,7 @@ func TestImport(t *testing.T) {
 	}{
 		{
 			name: "simple issue",
-			url:  "https://gitlab.com/git-bug/test/issues/1",
+			url:  "https://gitlab.com/git-bug/test/-/issues/1",
 			bug: &bug.Snapshot{
 				Operations: []bug.Operation{
 					bug.NewCreateOp(author, 0, "simple issue", "initial comment", nil),
@@ -40,7 +40,7 @@ func TestImport(t *testing.T) {
 		},
 		{
 			name: "empty issue",
-			url:  "https://gitlab.com/git-bug/test/issues/2",
+			url:  "https://gitlab.com/git-bug/test/-/issues/2",
 			bug: &bug.Snapshot{
 				Operations: []bug.Operation{
 					bug.NewCreateOp(author, 0, "empty issue", "", nil),
@@ -49,7 +49,7 @@ func TestImport(t *testing.T) {
 		},
 		{
 			name: "complex issue",
-			url:  "https://gitlab.com/git-bug/test/issues/3",
+			url:  "https://gitlab.com/git-bug/test/-/issues/3",
 			bug: &bug.Snapshot{
 				Operations: []bug.Operation{
 					bug.NewCreateOp(author, 0, "complex issue", "initial comment", nil),
@@ -66,7 +66,7 @@ func TestImport(t *testing.T) {
 		},
 		{
 			name: "editions",
-			url:  "https://gitlab.com/git-bug/test/issues/4",
+			url:  "https://gitlab.com/git-bug/test/-/issues/4",
 			bug: &bug.Snapshot{
 				Operations: []bug.Operation{
 					bug.NewCreateOp(author, 0, "editions", "initial comment edited", nil),

bridge/jira/import.go 🔗

@@ -216,7 +216,16 @@ func (ji *jiraImporter) ensureIssue(repo *cache.RepoCache, issue Issue) (*cache.
 		return nil, err
 	}
 
-	b, err := repo.ResolveBugCreateMetadata(metaKeyJiraId, issue.ID)
+	b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+		if _, ok := excerpt.CreateMetadata[metaKeyJiraBaseUrl]; ok &&
+			excerpt.CreateMetadata[metaKeyJiraBaseUrl] != ji.conf[confKeyBaseUrl] {
+			return false
+		}
+
+		return excerpt.CreateMetadata[core.MetaKeyOrigin] == target &&
+			excerpt.CreateMetadata[metaKeyJiraId] == issue.ID &&
+			excerpt.CreateMetadata[metaKeyJiraProject] == ji.conf[confKeyProject]
+	})
 	if err != nil && err != bug.ErrBugNotExist {
 		return nil, err
 	}
@@ -241,6 +250,7 @@ func (ji *jiraImporter) ensureIssue(repo *cache.RepoCache, issue Issue) (*cache.
 				metaKeyJiraId:      issue.ID,
 				metaKeyJiraKey:     issue.Key,
 				metaKeyJiraProject: ji.conf[confKeyProject],
+				metaKeyJiraBaseUrl: ji.conf[confKeyBaseUrl],
 			})
 		if err != nil {
 			return nil, err

bridge/jira/jira.go 🔗

@@ -20,6 +20,7 @@ const (
 	metaKeyJiraKey        = "jira-key"
 	metaKeyJiraUser       = "jira-user"
 	metaKeyJiraProject    = "jira-project"
+	metaKeyJiraBaseUrl    = "jira-base-url"
 	metaKeyJiraExportTime = "jira-export-time"
 	metaKeyJiraLogin      = "jira-login"
 

bridge/launchpad/import.go 🔗

@@ -62,7 +62,10 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach
 				return
 			default:
 				lpBugID := fmt.Sprintf("%d", lpBug.ID)
-				b, err := repo.ResolveBugCreateMetadata(metaKeyLaunchpadID, lpBugID)
+				b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+					return excerpt.CreateMetadata[core.MetaKeyOrigin] == target &&
+						excerpt.CreateMetadata[metaKeyLaunchpadID] == lpBugID
+				})
 				if err != nil && err != bug.ErrBugNotExist {
 					out <- core.NewImportError(err, entity.Id(lpBugID))
 					return