reggi/dev-engines
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | const {posix, sep} = require('node:path') |
| 2 | |
| 3 | if (!process.env.GITHUB_TOKEN) { |
| 4 | throw new Error('GITHUB_TOKEN env var is required to build CLI docs') |
| 5 | } |
| 6 | |
| 7 | let octokit |
| 8 | const owner = 'npm' |
| 9 | const repo = 'cli' |
| 10 | const opts = {owner, repo} |
| 11 | |
| 12 | const getFile = async ({sha, ref, path}) => { |
| 13 | if (!octokit) { |
| 14 | const {Octokit} = await import('@octokit/rest') |
| 15 | octokit = new Octokit({auth: process.env.GITHUB_TOKEN}) |
| 16 | } |
| 17 | const {data} = await (sha |
| 18 | ? octokit.git.getBlob({ |
| 19 | ...opts, |
| 20 | file_sha: sha, |
| 21 | }) |
| 22 | : octokit.repos.getContent({ |
| 23 | ...opts, |
| 24 | ref, |
| 25 | path: path.split(sep).join(posix.sep), |
| 26 | })) |
| 27 | return Buffer.from(data.content, data.encoding) |
| 28 | } |
| 29 | |
| 30 | const pathExists = async (ref, path) => { |
| 31 | if (!octokit) { |
| 32 | const {Octokit} = await import('@octokit/rest') |
| 33 | octokit = new Octokit({auth: process.env.GITHUB_TOKEN}) |
| 34 | } |
| 35 | try { |
| 36 | await octokit.repos.getContent({ |
| 37 | ...opts, |
| 38 | ref, |
| 39 | path: path.split(sep).join(posix.sep), |
| 40 | }) |
| 41 | return path |
| 42 | } catch (err) { |
| 43 | /* istanbul ignore next */ |
| 44 | if (!err.status === 404) { |
| 45 | throw err |
| 46 | } |
| 47 | } |
| 48 | return null |
| 49 | } |
| 50 | |
| 51 | module.exports = { |
| 52 | getFile, |
| 53 | pathExists, |
| 54 | nwo: `${owner}/${repo}`, |
| 55 | } |