File tree Expand file tree Collapse file tree 6 files changed +23
-18
lines changed Expand file tree Collapse file tree 6 files changed +23
-18
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export class Install {
5858 const version : DownloadVersion = await Install . getDownloadVersion ( v ) ;
5959 core . debug ( `Install.download version: ${ version . version } ` ) ;
6060
61- const release : GitHubRelease = await Install . getRelease ( version ) ;
61+ const release : GitHubRelease = await Install . getRelease ( version , this . githubToken ) ;
6262 core . debug ( `Install.download release tag name: ${ release . tag_name } ` ) ;
6363
6464 const vspec = await this . vspec ( release . tag_name ) ;
@@ -315,8 +315,8 @@ export class Install {
315315 }
316316 }
317317
318- public static async getRelease ( version : DownloadVersion ) : Promise < GitHubRelease > {
319- const github = new GitHub ( ) ;
318+ public static async getRelease ( version : DownloadVersion , githubToken ?: string ) : Promise < GitHubRelease > {
319+ const github = new GitHub ( { token : githubToken } ) ;
320320 const releases = await github . releases ( 'Buildx' , version . contentOpts ) ;
321321 if ( ! releases [ version . version ] ) {
322322 throw new Error ( `Cannot find Buildx release ${ version . version } in releases JSON` ) ;
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ export class Install {
5454 const version : DownloadVersion = await Install . getDownloadVersion ( v ) ;
5555 core . debug ( `Install.download version: ${ version . version } ` ) ;
5656
57- const release : GitHubRelease = await Install . getRelease ( version ) ;
57+ const release : GitHubRelease = await Install . getRelease ( version , this . githubToken ) ;
5858 core . debug ( `Install.download release tag name: ${ release . tag_name } ` ) ;
5959
6060 const vspec = await this . vspec ( release . tag_name ) ;
@@ -213,8 +213,8 @@ export class Install {
213213 }
214214 }
215215
216- public static async getRelease ( version : DownloadVersion ) : Promise < GitHubRelease > {
217- const github = new GitHub ( ) ;
216+ public static async getRelease ( version : DownloadVersion , githubToken ?: string ) : Promise < GitHubRelease > {
217+ const github = new GitHub ( { token : githubToken } ) ;
218218 const releases = await github . releases ( 'Compose' , version . contentOpts ) ;
219219 if ( ! releases [ version . version ] ) {
220220 throw new Error ( `Cannot find Compose release ${ version . version } in releases JSON` ) ;
Original file line number Diff line number Diff line change @@ -208,14 +208,14 @@ export class Install {
208208 }
209209
210210 private async downloadSourceArchive ( component : 'docker' | 'docker-rootless-extras' , src : InstallSourceArchive ) : Promise < string > {
211- const release : GitHubRelease = await Install . getRelease ( src . version ) ;
211+ const release : GitHubRelease = await Install . getRelease ( src . version , this . githubToken ) ;
212212 this . _version = release . tag_name . replace ( / ^ ( d o c k e r - ) ? v + / , '' ) ;
213213 core . debug ( `docker.Install.downloadSourceArchive version: ${ this . _version } ` ) ;
214214
215215 const downloadURL = this . downloadURL ( component , this . _version , src . channel ) ;
216216 core . info ( `Downloading ${ downloadURL } ` ) ;
217217
218- const downloadPath = await tc . downloadTool ( downloadURL , undefined , this . githubToken ) ;
218+ const downloadPath = await tc . downloadTool ( downloadURL ) ;
219219 core . debug ( `docker.Install.downloadSourceArchive downloadPath: ${ downloadPath } ` ) ;
220220
221221 let extractFolder ;
@@ -698,8 +698,8 @@ EOF`,
698698 } ) ;
699699 }
700700
701- public static async getRelease ( version : string ) : Promise < GitHubRelease > {
702- const github = new GitHub ( ) ;
701+ public static async getRelease ( version : string , githubToken ?: string ) : Promise < GitHubRelease > {
702+ const github = new GitHub ( { token : githubToken } ) ;
703703 const releases = await github . releases ( 'Docker' , {
704704 owner : 'docker' ,
705705 repo : 'actions-toolkit' ,
Original file line number Diff line number Diff line change @@ -45,10 +45,12 @@ export interface GitHubOpts {
4545}
4646
4747export class GitHub {
48+ private readonly githubToken ?: string ;
4849 public readonly octokit : InstanceType < typeof Octokit > ;
4950
5051 constructor ( opts ?: GitHubOpts ) {
51- this . octokit = github . getOctokit ( `${ opts ?. token } ` ) ;
52+ this . githubToken = opts ?. token || process . env . GITHUB_TOKEN ;
53+ this . octokit = github . getOctokit ( `${ this . githubToken } ` ) ;
5254 }
5355
5456 public repoData ( ) : Promise < GitHubRepo > {
@@ -58,7 +60,10 @@ export class GitHub {
5860 public async releases ( name : string , opts : GitHubContentOpts ) : Promise < Record < string , GitHubRelease > > {
5961 const url = `https://raw.githubusercontent.com/${ opts . owner } /${ opts . repo } /${ opts . ref } /${ opts . path } ` ;
6062 const http : httpm . HttpClient = new httpm . HttpClient ( 'docker-actions-toolkit' ) ;
61- const httpResp : httpm . HttpClientResponse = await http . get ( url ) ;
63+ // prettier-ignore
64+ const httpResp : httpm . HttpClientResponse = await http . get ( url , this . githubToken ? {
65+ Authorization : `token ${ this . githubToken } `
66+ } : undefined ) ;
6267 const dt = await httpResp . readBody ( ) ;
6368 const statusCode = httpResp . message . statusCode || 500 ;
6469 if ( statusCode >= 400 ) {
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export class Install {
5050 const version : DownloadVersion = await Install . getDownloadVersion ( v ) ;
5151 core . debug ( `Install.download version: ${ version . version } ` ) ;
5252
53- const release : GitHubRelease = await Install . getRelease ( version ) ;
53+ const release : GitHubRelease = await Install . getRelease ( version , this . githubToken ) ;
5454 core . debug ( `Install.download release tag name: ${ release . tag_name } ` ) ;
5555
5656 const vspec = await this . vspec ( release . tag_name ) ;
@@ -153,8 +153,8 @@ export class Install {
153153 } ;
154154 }
155155
156- public static async getRelease ( version : DownloadVersion ) : Promise < GitHubRelease > {
157- const github = new GitHub ( ) ;
156+ public static async getRelease ( version : DownloadVersion , githubToken ?: string ) : Promise < GitHubRelease > {
157+ const github = new GitHub ( { token : githubToken } ) ;
158158 const releases = await github . releases ( 'regclient' , version . contentOpts ) ;
159159 if ( ! releases [ version . version ] ) {
160160 throw new Error ( `Cannot find regclient release ${ version . version } in releases JSON` ) ;
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export class Install {
5050 const version : DownloadVersion = await Install . getDownloadVersion ( v ) ;
5151 core . debug ( `Install.download version: ${ version . version } ` ) ;
5252
53- const release : GitHubRelease = await Install . getRelease ( version ) ;
53+ const release : GitHubRelease = await Install . getRelease ( version , this . githubToken ) ;
5454 core . debug ( `Install.download release tag name: ${ release . tag_name } ` ) ;
5555
5656 const vspec = await this . vspec ( release . tag_name ) ;
@@ -164,8 +164,8 @@ export class Install {
164164 } ;
165165 }
166166
167- public static async getRelease ( version : DownloadVersion ) : Promise < GitHubRelease > {
168- const github = new GitHub ( ) ;
167+ public static async getRelease ( version : DownloadVersion , githubToken ?: string ) : Promise < GitHubRelease > {
168+ const github = new GitHub ( { token : githubToken } ) ;
169169 const releases = await github . releases ( 'Undock' , version . contentOpts ) ;
170170 if ( ! releases [ version . version ] ) {
171171 throw new Error ( `Cannot find Undock release ${ version . version } in releases JSON` ) ;
You can’t perform that action at this time.
0 commit comments