@@ -60,7 +60,7 @@ func (f *GithubDownloaderV3Factory) New(opts base.MigrateOptions) (base.Download
6060
6161 log .Trace ("Create github downloader: %s/%s" , oldOwner , oldName )
6262
63- return NewGithubDownloaderV3 (opts .AuthUsername , opts .AuthPassword , oldOwner , oldName ), nil
63+ return NewGithubDownloaderV3 (opts .AuthUsername , opts .AuthPassword , opts . AuthToken , oldOwner , oldName ), nil
6464}
6565
6666// GitServiceType returns the type of git service
@@ -81,7 +81,7 @@ type GithubDownloaderV3 struct {
8181}
8282
8383// NewGithubDownloaderV3 creates a github Downloader via github v3 API
84- func NewGithubDownloaderV3 (userName , password , repoOwner , repoName string ) * GithubDownloaderV3 {
84+ func NewGithubDownloaderV3 (userName , password , token , repoOwner , repoName string ) * GithubDownloaderV3 {
8585 var downloader = GithubDownloaderV3 {
8686 userName : userName ,
8787 password : password ,
@@ -90,23 +90,19 @@ func NewGithubDownloaderV3(userName, password, repoOwner, repoName string) *Gith
9090 repoName : repoName ,
9191 }
9292
93- var client * http.Client
94- if userName != "" {
95- if password == "" {
96- ts := oauth2 .StaticTokenSource (
97- & oauth2.Token {AccessToken : userName },
98- )
99- client = oauth2 .NewClient (downloader .ctx , ts )
100- } else {
101- client = & http.Client {
102- Transport : & http.Transport {
103- Proxy : func (req * http.Request ) (* url.URL , error ) {
104- req .SetBasicAuth (userName , password )
105- return nil , nil
106- },
107- },
108- }
109- }
93+ client := & http.Client {
94+ Transport : & http.Transport {
95+ Proxy : func (req * http.Request ) (* url.URL , error ) {
96+ req .SetBasicAuth (userName , password )
97+ return nil , nil
98+ },
99+ },
100+ }
101+ if token != "" {
102+ ts := oauth2 .StaticTokenSource (
103+ & oauth2.Token {AccessToken : token },
104+ )
105+ client = oauth2 .NewClient (downloader .ctx , ts )
110106 }
111107 downloader .client = github .NewClient (client )
112108 return & downloader
0 commit comments