diff --git a/.eslintrc.json b/.eslintrc.json index ce2dfb06..2a8dde83 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -77,5 +77,13 @@ "unicorn/prefer-spread": "off", // Temp disable to prevent mixing changes with other PRs "i18n-text/no-en": "off" - } + }, + "overrides": [ + { + "files": ["jest.setup.js"], + "rules": { + "import/no-commonjs": "off" + } + } + ] } diff --git a/dist/index.js b/dist/index.js index b5ba506c..a992aa78 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index b6f2aea5..c59edba2 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/jest.config.js b/jest.config.js index be54f49e..27ddc31a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -25,6 +25,6 @@ module.exports = { // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader modulePathIgnorePatterns: ['/lib/', '/dist/'], - // A list of paths to modules that run some code to configure or set up the testing framework before each test - setupFilesAfterEnv: ['/src/jest.setup.ts'], + // Use jest.setup.js to polyfill fetch for all tests + setupFiles: ['/jest.setup.js'], }; diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 00000000..8e0c7c93 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,2 @@ +const fetch = require('node-fetch'); +global.fetch = fetch; diff --git a/package.json b/package.json index 968ca1d7..6b38964e 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "jest-fail-on-console": "^3.0.2", "js-yaml": "^4.1.0", "lefthook": "^1.6.1", + "node-fetch": "2", "prettier": "^2.5.1", "ts-jest": "^27.1.3", "ts-node": "10.8.1", @@ -84,4 +85,4 @@ "node": "20.5.1", "yarn": "1.22.19" } -} \ No newline at end of file +} diff --git a/src/model/github.ts b/src/model/github.ts index a3b60e17..c3ea0072 100644 --- a/src/model/github.ts +++ b/src/model/github.ts @@ -3,6 +3,7 @@ import CloudRunner from './cloud-runner/cloud-runner'; import CloudRunnerOptions from './cloud-runner/options/cloud-runner-options'; import * as core from '@actions/core'; import { Octokit } from '@octokit/core'; +import fetch from 'node-fetch'; class GitHub { private static readonly asyncChecksApiWorkflowName = `Async Checks API`; @@ -15,11 +16,13 @@ class GitHub { private static get octokitDefaultToken() { return new Octokit({ auth: process.env.GITHUB_TOKEN, + request: { fetch }, }); } private static get octokitPAT() { return new Octokit({ auth: CloudRunner.buildParameters.gitPrivateToken, + request: { fetch }, }); } private static get sha() { @@ -163,11 +166,10 @@ class GitHub { core.info(JSON.stringify(workflows)); throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`); } - await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, { + await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflowId}/dispatches`, { owner: GitHub.owner, repo: GitHub.repo, - // eslint-disable-next-line camelcase - workflow_id: selectedId, + workflowId: selectedId, ref: CloudRunnerOptions.branch, inputs: { checksObject: JSON.stringify({ data, mode }), @@ -198,11 +200,10 @@ class GitHub { core.info(JSON.stringify(workflows)); throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`); } - await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, { + await GitHub.octokitPAT.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflowId}/dispatches`, { owner: GitHub.owner, repo: GitHub.repo, - // eslint-disable-next-line camelcase - workflow_id: selectedId, + workflowId: selectedId, ref: CloudRunnerOptions.branch, inputs: { buildGuid: CloudRunner.buildParameters.buildGuid, @@ -213,10 +214,6 @@ class GitHub { core.info(`github workflow complete hook not found`); } } - - public static async getCheckStatus() { - return await GitHub.octokitDefaultToken.request(`GET /repos/{owner}/{repo}/check-runs/{check_run_id}`); - } } export default GitHub; diff --git a/yarn.lock b/yarn.lock index 9c32e641..95e4c0f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6242,6 +6242,13 @@ no-case@^3.0.4: lower-case "^2.0.2" tslib "^2.0.3" +node-fetch@2: + version "2.7.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" + integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== + dependencies: + whatwg-url "^5.0.0" + node-fetch@^2.6.7: version "2.6.12" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.12.tgz#02eb8e22074018e3d5a83016649d04df0e348fba"