From c352d8589cd2769b0242e291aa25cab0a262538e Mon Sep 17 00:00:00 2001 From: Haruo Kinoshita Date: Mon, 16 Jan 2023 17:28:22 +0900 Subject: [PATCH 1/2] Fix: Migration from GitBucket does not work since importing Reviews was added in GitHub migration. --- services/migrations/gitbucket.go | 8 +++++--- services/migrations/github.go | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/migrations/gitbucket.go b/services/migrations/gitbucket.go index 65c138ed04a2f..acea93d325280 100644 --- a/services/migrations/gitbucket.go +++ b/services/migrations/gitbucket.go @@ -33,10 +33,11 @@ func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateO return nil, err } - baseURL := u.Scheme + "://" + u.Host fields := strings.Split(u.Path, "/") - oldOwner := fields[1] - oldName := strings.TrimSuffix(fields[2], ".git") + baseURL := u.Scheme + "://" + u.Host + strings.TrimSuffix(strings.Join(fields[:len(fields)-2], "/"), "/git") + + oldOwner := fields[len(fields)-2] + oldName := strings.TrimSuffix(fields[len(fields)-1], ".git") log.Trace("Create GitBucket downloader. BaseURL: %s RepoOwner: %s RepoName: %s", baseURL, oldOwner, oldName) return NewGitBucketDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil @@ -71,6 +72,7 @@ func (g *GitBucketDownloader) ColorFormat(s fmt.State) { func NewGitBucketDownloader(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GitBucketDownloader { githubDownloader := NewGithubDownloaderV3(ctx, baseURL, userName, password, token, repoOwner, repoName) githubDownloader.SkipReactions = true + githubDownloader.SkipReviews = true return &GitBucketDownloader{ githubDownloader, } diff --git a/services/migrations/github.go b/services/migrations/github.go index 48dd90323d5a4..d34ad13b95a71 100644 --- a/services/migrations/github.go +++ b/services/migrations/github.go @@ -76,6 +76,7 @@ type GithubDownloaderV3 struct { curClientIdx int maxPerPage int SkipReactions bool + SkipReviews bool } // NewGithubDownloaderV3 creates a github Downloader via github v3 API @@ -809,6 +810,9 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques // GetReviews returns pull requests review func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) { allReviews := make([]*base.Review, 0, g.maxPerPage) + if g.SkipReviews { + return allReviews, nil + } opt := &github.ListOptions{ PerPage: g.maxPerPage, } From 18233715d6f936d8e784ec9a86549e689caf1ff2 Mon Sep 17 00:00:00 2001 From: Haruo Kinoshita Date: Mon, 16 Jan 2023 22:44:27 +0900 Subject: [PATCH 2/2] Update services/migrations/gitbucket.go Co-authored-by: zeripath --- services/migrations/gitbucket.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/migrations/gitbucket.go b/services/migrations/gitbucket.go index acea93d325280..cc3d4fc93674a 100644 --- a/services/migrations/gitbucket.go +++ b/services/migrations/gitbucket.go @@ -34,6 +34,9 @@ func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateO } fields := strings.Split(u.Path, "/") + if len(fields) < 2 { + return nil, fmt.Errorf("invalid path: %s", u.Path) + } baseURL := u.Scheme + "://" + u.Host + strings.TrimSuffix(strings.Join(fields[:len(fields)-2], "/"), "/git") oldOwner := fields[len(fields)-2]