Skip to content

Commit

Permalink
fix: switch to import for @octokit/rest
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jun 21, 2024
1 parent 19f2a46 commit 2e10e4e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cli/lib/gh.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const {Octokit} = require('@octokit/rest')
const {posix, sep} = require('path')
const {posix, sep} = require('node:path')

if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN env var is required to build CLI docs')
}

const octokit = new Octokit({auth: process.env.GITHUB_TOKEN})
let octokit
const owner = 'npm'
const repo = 'cli'
const opts = {owner, repo}

const getFile = async ({sha, ref, path}) => {
if (!octokit) {
const {Octokit} = await import('@octokit/rest')
octokit = new Octokit({auth: process.env.GITHUB_TOKEN})
}
const {data} = await (sha
? octokit.git.getBlob({
...opts,
Expand All @@ -25,6 +28,10 @@ const getFile = async ({sha, ref, path}) => {
}

const pathExists = async (ref, path) => {
if (!octokit) {
const {Octokit} = await import('@octokit/rest')
octokit = new Octokit({auth: process.env.GITHUB_TOKEN})
}
try {
await octokit.repos.getContent({
...opts,
Expand Down

0 comments on commit 2e10e4e

Please sign in to comment.