mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 02:46:04 +01: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>
This commit is contained in:
		| @@ -133,7 +133,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) | ||||
| @@ -872,3 +872,18 @@ func (g *GithubDownloaderV3) GetReviews(ctx context.Context, 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 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user