From db2e03c72368ba629098e9cb1474566b8dfd15ed Mon Sep 17 00:00:00 2001 From: jNullj <15849761+jNullj@users.noreply.github.com> Date: Sun, 13 Aug 2023 17:55:29 +0300 Subject: [PATCH] refactor: remove node-fetch and use octokit insted --- .../docusaurus-swizzled-warning/index.js | 44 ++++++++++++++++--- .../package-lock.json | 3 +- .../docusaurus-swizzled-warning/package.json | 3 +- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js index 91ae51cd3c7db..43e09ce987db4 100644 --- a/.github/actions/docusaurus-swizzled-warning/index.js +++ b/.github/actions/docusaurus-swizzled-warning/index.js @@ -2,7 +2,6 @@ const core = require('@actions/core') const github = require('@actions/github') -const fetch = require('node-fetch') const { getAllFilesForPullRequest, getChangedFilesBetweenTags, @@ -47,12 +46,43 @@ async function run() { continue } - const pkgLockNewJson = await (await fetch(file.raw_url)).json() - const pkgLockOldJson = await ( - await fetch( - `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/master/${file.filename}`, - ) - ).json() + const pkgLockNewSha = ( + await client.rest.repos.getContent({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + path: file.filename, + ref: file.contents_url.split('ref=')[1], + }) + ).data.sha + const pkgLockNewBlob = ( + await client.rest.git.getBlob({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + file_sha: pkgLockNewSha, + }) + ).data.content + const pkgLockNewJson = JSON.parse( + Buffer.from(pkgLockNewBlob, 'base64').toString(), + ) + const pkgLockOldSha = ( + await client.rest.repos.getContent({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + path: file.filename, + ref: 'master', + }) + ).data.sha + const pkgLockOldBlob = ( + await client.rest.git.getBlob({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + file_sha: pkgLockOldSha, + }) + ).data.content + const pkgLockOldJson = JSON.parse( + Buffer.from(pkgLockOldBlob, 'base64').toString(), + ) + const oldVesionModuleKey = findKeyEndingWith( pkgLockOldJson.packages, `node_modules/${packageName}`, diff --git a/.github/actions/docusaurus-swizzled-warning/package-lock.json b/.github/actions/docusaurus-swizzled-warning/package-lock.json index 21ba9a338d902..5511c01825be6 100644 --- a/.github/actions/docusaurus-swizzled-warning/package-lock.json +++ b/.github/actions/docusaurus-swizzled-warning/package-lock.json @@ -10,8 +10,7 @@ "license": "CC0", "dependencies": { "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1", - "node-fetch": "^2.6.12" + "@actions/github": "^5.1.1" } }, "node_modules/@actions/core": { diff --git a/.github/actions/docusaurus-swizzled-warning/package.json b/.github/actions/docusaurus-swizzled-warning/package.json index e201afddfeb68..7fdf1a43a163f 100644 --- a/.github/actions/docusaurus-swizzled-warning/package.json +++ b/.github/actions/docusaurus-swizzled-warning/package.json @@ -11,7 +11,6 @@ "license": "CC0", "dependencies": { "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1", - "node-fetch": "^2.6.12" + "@actions/github": "^5.1.1" } }