Skip to content

Commit 1d22f02

Browse files
committed
releases: download releases JSON without token first
Signed-off-by: CrazyMax <[email protected]>
1 parent b42885d commit 1d22f02

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/github.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,26 @@ export class GitHub {
5858
}
5959

6060
public async releases(name: string, opts: GitHubContentOpts): Promise<Record<string, GitHubRelease>> {
61+
let releases: Record<string, GitHubRelease>;
62+
try {
63+
// try without token first
64+
releases = await this.releasesRaw(name, opts);
65+
} catch (error) {
66+
if (!this.githubToken) {
67+
throw error;
68+
}
69+
// try with token
70+
releases = await this.releasesRaw(name, opts, this.githubToken);
71+
}
72+
return releases;
73+
}
74+
75+
public async releasesRaw(name: string, opts: GitHubContentOpts, token?: string): Promise<Record<string, GitHubRelease>> {
6176
const url = `https://raw.githubusercontent.com/${opts.owner}/${opts.repo}/${opts.ref}/${opts.path}`;
6277
const http: httpm.HttpClient = new httpm.HttpClient('docker-actions-toolkit');
6378
// prettier-ignore
64-
const httpResp: httpm.HttpClientResponse = await http.get(url, this.githubToken ? {
65-
Authorization: `token ${this.githubToken}`
79+
const httpResp: httpm.HttpClientResponse = await http.get(url, token ? {
80+
Authorization: `token ${token}`
6681
} : undefined);
6782
const dt = await httpResp.readBody();
6883
const statusCode = httpResp.message.statusCode || 500;

0 commit comments

Comments
 (0)