Skip to content

Commit ec6a35a

Browse files
jolheiserzeripathlunny
authored
Hopefully support GH enterprise (#12863)
Signed-off-by: jolheiser <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 2dbca92 commit ec6a35a

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

modules/migrations/gitea_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestGiteaUploadRepo(t *testing.T) {
2828
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
2929

3030
var (
31-
downloader = NewGithubDownloaderV3(context.Background(), "", "", "", "go-xorm", "builder")
31+
downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
3232
repoName = "builder-" + time.Now().Format("2006-01-02-15-04-05")
3333
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
3434
)

modules/migrations/github.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ func (f *GithubDownloaderV3Factory) New(ctx context.Context, opts base.MigrateOp
4747
return nil, err
4848
}
4949

50+
baseURL := u.Scheme + "://" + u.Host
5051
fields := strings.Split(u.Path, "/")
5152
oldOwner := fields[1]
5253
oldName := strings.TrimSuffix(fields[2], ".git")
5354

5455
log.Trace("Create github downloader: %s/%s", oldOwner, oldName)
5556

56-
return NewGithubDownloaderV3(ctx, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil
57+
return NewGithubDownloaderV3(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil
5758
}
5859

5960
// GitServiceType returns the type of git service
@@ -74,7 +75,7 @@ type GithubDownloaderV3 struct {
7475
}
7576

7677
// NewGithubDownloaderV3 creates a github Downloader via github v3 API
77-
func NewGithubDownloaderV3(ctx context.Context, userName, password, token, repoOwner, repoName string) *GithubDownloaderV3 {
78+
func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GithubDownloaderV3 {
7879
var downloader = GithubDownloaderV3{
7980
userName: userName,
8081
password: password,
@@ -98,6 +99,9 @@ func NewGithubDownloaderV3(ctx context.Context, userName, password, token, repoO
9899
client = oauth2.NewClient(downloader.ctx, ts)
99100
}
100101
downloader.client = github.NewClient(client)
102+
if baseURL != "https://github.com" {
103+
downloader.client, _ = github.NewEnterpriseClient(baseURL, baseURL, client)
104+
}
101105
return &downloader
102106
}
103107

modules/migrations/github_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func assertLabelEqual(t *testing.T, name, color, description string, label *base
6565

6666
func TestGitHubDownloadRepo(t *testing.T) {
6767
GithubLimitRateRemaining = 3 //Wait at 3 remaining since we could have 3 CI in //
68-
downloader := NewGithubDownloaderV3(context.Background(), "", "", os.Getenv("GITHUB_READ_TOKEN"), "go-gitea", "test_repo")
68+
downloader := NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", os.Getenv("GITHUB_READ_TOKEN"), "go-gitea", "test_repo")
6969
err := downloader.RefreshRate()
7070
assert.NoError(t, err)
7171

0 commit comments

Comments
 (0)