Skip to content

Commit

Permalink
fix: don't reuse octokit between auth methods
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-run committed May 14, 2024
1 parent 05b352f commit b45e4ff
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/common/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@ import * as R from 'remeda'
import { log } from './log.ts'
import { blacklisted } from './repos.ts'

let octokit: Octokit | null = null
let packagesOctokit: Octokit | null = null
let cliOctokit: Octokit | null = null

export function getOctokitClient(auth: 'cli' | 'package' = 'cli'): Octokit {
if (octokit === null) {
octokit = new Octokit({ auth: auth === 'cli' ? getGithubCliToken() : Bun.env.NPM_AUTH_TOKEN })
}
switch (auth) {
case 'cli':
if (cliOctokit === null) {
cliOctokit = new Octokit({ auth: getGithubCliToken() })
}

return cliOctokit
case 'package':
if (Bun.env.NPM_AUTH_TOKEN == null) {
throw new Error('No NPM_AUTH_TOKEN set')
}

return octokit
if (packagesOctokit === null) {
packagesOctokit = new Octokit({ auth: Bun.env.NPM_AUTH_TOKEN })
}

return packagesOctokit
}
}

/**
Expand Down

0 comments on commit b45e4ff

Please sign in to comment.