mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-06-06 12:00:02 +02:00
fix github migration error when using multiple tokens (#34144)
Git authorization was not taking into account multiple token feature, leading to auth failures Closes: https://github.com/go-gitea/gitea/issues/34141 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> (cherry picked from commit 8a6df00c532becd4d10efb70827ccf80b2bf74e2)
This commit is contained in:
parent
82dd00873d
commit
504bb09319
2 changed files with 49 additions and 1 deletions
|
@ -140,7 +140,7 @@ func (g *GithubDownloaderV3) LogString() string {
|
|||
func (g *GithubDownloaderV3) addClient(client *http.Client, baseURL string) {
|
||||
githubClient := github.NewClient(client)
|
||||
if baseURL != "https://github.com" {
|
||||
githubClient, _ = github.NewClient(client).WithEnterpriseURLs(baseURL, baseURL)
|
||||
githubClient, _ = githubClient.WithEnterpriseURLs(baseURL, baseURL)
|
||||
}
|
||||
g.clients = append(g.clients, githubClient)
|
||||
g.rates = append(g.rates, nil)
|
||||
|
@ -885,3 +885,18 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev
|
|||
}
|
||||
return allReviews, nil
|
||||
}
|
||||
|
||||
// FormatCloneURL add authentication into remote URLs
|
||||
func (g *GithubDownloaderV3) FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error) {
|
||||
u, err := url.Parse(remoteAddr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(opts.AuthToken) > 0 {
|
||||
// "multiple tokens" are used to benefit more "API rate limit quota"
|
||||
// git clone doesn't count for rate limits, so only use the first token.
|
||||
// source: https://github.com/orgs/community/discussions/44515
|
||||
u.User = url.UserPassword("oauth2", strings.Split(opts.AuthToken, ",")[0])
|
||||
}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue