Skip to content

Commit

Permalink
refactor: remove node-fetch and use octokit insted
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Aug 13, 2023
1 parent c77af69 commit db2e03c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
44 changes: 37 additions & 7 deletions .github/actions/docusaurus-swizzled-warning/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const core = require('@actions/core')
const github = require('@actions/github')
const fetch = require('node-fetch')
const {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
Expand Down Expand Up @@ -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}`,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .github/actions/docusaurus-swizzled-warning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit db2e03c

Please sign in to comment.