diff --git a/src/utilities/fetch-package-repos.mjs b/src/utilities/fetch-package-repos.mjs index f030d19bc50f..8928c8a4350d 100644 --- a/src/utilities/fetch-package-repos.mjs +++ b/src/utilities/fetch-package-repos.mjs @@ -3,9 +3,10 @@ import path from 'path'; import { mkdirp } from 'mkdirp'; import { promisify } from 'util'; import _ from 'lodash'; +import { Octokit as GithubAPI } from '@octokit/rest'; +import { createActionAuth } from '@octokit/auth-action'; import { excludedLoaders, excludedPlugins } from './constants.mjs'; import { fileURLToPath } from 'url'; -import api from './githubAPI.mjs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -33,6 +34,17 @@ const fetch = { }; async function main() { + let api; + if (process.env.CI && process.env.CI === true) { + const auth = createActionAuth(); + const authentication = await auth(); + api = new GithubAPI({ + auth: authentication, + }); + } else { + api = new GithubAPI(); + } + async function paginate(org) { const data = await api.paginate('GET /orgs/:org/repos', { org: org, diff --git a/src/utilities/githubAPI.mjs b/src/utilities/githubAPI.mjs deleted file mode 100644 index d6b7b70ddd41..000000000000 --- a/src/utilities/githubAPI.mjs +++ /dev/null @@ -1,26 +0,0 @@ -import { Octokit as GithubAPI } from '@octokit/rest'; -import { createActionAuth } from '@octokit/auth-action'; -/** @type import('@octokit/rest').Octokit */ -let api; -if ( - process.env.CI && - process.env.GITHUB_ACTION && - (process.env.CI === 'true' || process.env.CI === '1') // see https://github.com/cypress-io/github-action/blob/9674a20f82e9e45ec75aa66038310b00e2f24657/index.js#L223 for CI === '1' -) { - const auth = createActionAuth(); - const authentication = await auth(); - api = new GithubAPI({ - auth: authentication.token, - }); - console.log('api is authenticated'); -} else if (process.env.CI && process.env.VERCEL) { - // see https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables#system-environment-variables - api = new GithubAPI({ - auth: process.env.WEBPACK_JS_ORG_VERCEL_KEY, // this is a personal access token of @chenxsan - }); - console.log('api is authenticated on vercel'); -} else { - api = new GithubAPI(); - console.log('api is not authenticated'); -} -export default api;