Skip to content

Commit a32700d

Browse files
haruo31zeripathlunny
authored
Fix migration from GitBucket (#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]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent a9400ba commit a32700d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

services/migrations/gitbucket.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateO
3434
return nil, err
3535
}
3636

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

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

services/migrations/github.go

Lines changed: 4 additions & 0 deletions
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
@@ -805,6 +806,9 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
805806
// GetReviews returns pull requests review
806807
func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
807808
allReviews := make([]*base.Review, 0, g.maxPerPage)
809+
if g.SkipReviews {
810+
return allReviews, nil
811+
}
808812
opt := &github.ListOptions{
809813
PerPage: g.maxPerPage,
810814
}

0 commit comments

Comments
 (0)