Skip to content

Commit 9edf80f

Browse files
haruo31zeripath
andauthored
Fix migration from gitbucket (repost) (#22477)
Reposting pull request for #22465 > Migration from GitBucket does not work due to a access for "Reviews" API on GitBucket that makes 404 response. This PR has following changes. > 1. Made to stop access for Reviews API while migrating from GitBucket. > 2. Added support for custom URL (e.g. `http://example.com/gitbucket/owner/repository`) > 3. Made to accept for git checkout URL (`http://example.com/git/owner/repository.git`) Co-authored-by: zeripath <[email protected]>
1 parent 3510d7e commit 9edf80f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: services/migrations/gitbucket.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateO
3333
return nil, err
3434
}
3535

36-
baseURL := u.Scheme + "://" + u.Host
3736
fields := strings.Split(u.Path, "/")
38-
oldOwner := fields[1]
39-
oldName := strings.TrimSuffix(fields[2], ".git")
37+
if len(fields) < 2 {
38+
return nil, fmt.Errorf("invalid path: %s", u.Path)
39+
}
40+
baseURL := u.Scheme + "://" + u.Host + strings.TrimSuffix(strings.Join(fields[:len(fields)-2], "/"), "/git")
41+
42+
oldOwner := fields[len(fields)-2]
43+
oldName := strings.TrimSuffix(fields[len(fields)-1], ".git")
4044

4145
log.Trace("Create GitBucket downloader. BaseURL: %s RepoOwner: %s RepoName: %s", baseURL, oldOwner, oldName)
4246
return NewGitBucketDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil
@@ -71,6 +75,7 @@ func (g *GitBucketDownloader) ColorFormat(s fmt.State) {
7175
func NewGitBucketDownloader(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GitBucketDownloader {
7276
githubDownloader := NewGithubDownloaderV3(ctx, baseURL, userName, password, token, repoOwner, repoName)
7377
githubDownloader.SkipReactions = true
78+
githubDownloader.SkipReviews = true
7479
return &GitBucketDownloader{
7580
githubDownloader,
7681
}

Diff for: services/migrations/github.go

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type GithubDownloaderV3 struct {
7676
curClientIdx int
7777
maxPerPage int
7878
SkipReactions bool
79+
SkipReviews bool
7980
}
8081

8182
// NewGithubDownloaderV3 creates a github Downloader via github v3 API
@@ -809,6 +810,9 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
809810
// GetReviews returns pull requests review
810811
func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
811812
allReviews := make([]*base.Review, 0, g.maxPerPage)
813+
if g.SkipReviews {
814+
return allReviews, nil
815+
}
812816
opt := &github.ListOptions{
813817
PerPage: g.maxPerPage,
814818
}

0 commit comments

Comments
 (0)