From cdaf216b2a5baa0f20eecbf460912cc9947f2577 Mon Sep 17 00:00:00 2001 From: Maciej Mionskowski Date: Tue, 28 Nov 2023 15:36:33 +0100 Subject: [PATCH] feat: support unauthenticated requests (#59) GitHub API behaves differently for authenticated and unauthenticated requests. For example IP whitelisting for organisations is influenced by the type of the request. This will allow unauthenticated requests to GitHub API if `token: ""` is passed. --- dist/index.js | 5 +++-- index.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2257d71..9752acc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13824,9 +13824,10 @@ var baseFetchAssetFile = async (octokit, { id, outputPath, owner, repo, token }) repo }); let headers = { - accept, - authorization: `token ${token}` + accept }; + if (token !== "") + headers = { ...headers, authorization: `token ${token}` }; if (typeof userAgent !== "undefined") headers = { ...headers, "user-agent": userAgent }; const response = await fetch(url, { body, headers, method }); diff --git a/index.ts b/index.ts index 2d547e9..b5f3623 100644 --- a/index.ts +++ b/index.ts @@ -88,8 +88,10 @@ const baseFetchAssetFile = async ( ); let headers: HeadersInit = { accept, - authorization: `token ${token}`, }; + if (token !== '') + headers = { ...headers, authorization: `token ${token}` }; + if (typeof userAgent !== 'undefined') headers = { ...headers, 'user-agent': userAgent };