@@ -27,6 +27,7 @@ import {
2727 cleanupOpenPrs ,
2828 enablePrAutoMerge ,
2929 getGitHubEnvRepoInfo ,
30+ getOpenSocketPrs ,
3031 openPr ,
3132 prExistForBranch ,
3233 setGitRemoteGitHubRepoUrl ,
@@ -60,6 +61,7 @@ import { applyRange } from '../../utils/semver.mts'
6061import { getCveInfoFromAlertsMap } from '../../utils/socket-package-alert.mts'
6162import { idToPurl } from '../../utils/spec.mts'
6263
64+ import type { GitHubRepoInfo } from './open-pr.mts'
6365import type { NodeClass } from '../../shadow/npm/arborist/types.mts'
6466import type { CResult , StringKeyValueObject } from '../../types.mts'
6567import type { EnvDetails } from '../../utils/package-environment.mts'
@@ -138,8 +140,29 @@ export async function pnpmFix(
138140 const { spinner } = constants
139141 const { pkgPath : rootPath } = pkgEnvDetails
140142
143+ // Lazily access constants.ENV properties.
144+ const token = constants . ENV . SOCKET_CLI_GITHUB_TOKEN
145+ const isCi = ! ! (
146+ constants . ENV . CI &&
147+ constants . ENV . GITHUB_ACTIONS &&
148+ constants . ENV . GITHUB_REPOSITORY &&
149+ token
150+ )
151+
141152 spinner ?. start ( )
142153
154+ let count = 0
155+ let repoInfo : GitHubRepoInfo | null = null
156+ if ( isCi ) {
157+ repoInfo = getGitHubEnvRepoInfo ( ) !
158+ count += (
159+ await getOpenSocketPrs ( repoInfo . owner , repoInfo . repo , {
160+ // Lazily access constants.ENV.SOCKET_CLI_GIT_USER_NAME.
161+ author : constants . ENV . SOCKET_CLI_GIT_USER_NAME ,
162+ } )
163+ ) . length
164+ }
165+
143166 let actualTree : NodeClass | undefined
144167 const lockfilePath = path . join ( rootPath , 'pnpm-lock.yaml' )
145168 let lockfileContent = await readPnpmLockfile ( lockfilePath )
@@ -202,7 +225,7 @@ export async function pnpmFix(
202225 )
203226 } catch ( e ) {
204227 spinner ?. stop ( )
205- debugFn ( 'fail : PURL API\n' , e )
228+ debugFn ( 'catch : PURL API\n' , e )
206229 return {
207230 ok : false ,
208231 message : 'API Error' ,
@@ -217,14 +240,6 @@ export async function pnpmFix(
217240 return { ok : true , data : { fixed : false } }
218241 }
219242
220- // Lazily access constants.ENV properties.
221- const token = constants . ENV . SOCKET_CLI_GITHUB_TOKEN
222- const isCi = ! ! (
223- constants . ENV . CI &&
224- constants . ENV . GITHUB_ACTIONS &&
225- constants . ENV . GITHUB_REPOSITORY &&
226- token
227- )
228243 const baseBranch = isCi ? getBaseGitBranch ( ) : ''
229244 const workspacePkgJsonPaths = await globWorkspace (
230245 pkgEnvDetails . agent ,
@@ -252,8 +267,6 @@ export async function pnpmFix(
252267
253268 spinner ?. stop ( )
254269
255- let count = 0
256-
257270 infoEntriesLoop: for (
258271 let i = 0 , { length } = sortedInfoEntries ;
259272 i < length ;
@@ -545,12 +558,11 @@ export async function pnpmFix(
545558 continue infosLoop
546559 }
547560
548- const repoInfo = getGitHubEnvRepoInfo ( ) !
549561 const branch = getSocketBranchName ( oldPurl , newVersion , workspace )
550562 let skipPr = false
551563 if (
552564 // eslint-disable-next-line no-await-in-loop
553- await prExistForBranch ( repoInfo . owner , repoInfo . repo , branch )
565+ await prExistForBranch ( repoInfo ! . owner , repoInfo ! . repo , branch )
554566 ) {
555567 skipPr = true
556568 debugFn ( `skip: branch "${ branch } " exists` )
@@ -599,20 +611,20 @@ export async function pnpmFix(
599611 // eslint-disable-next-line no-await-in-loop
600612 await Promise . allSettled ( [
601613 setGitRemoteGitHubRepoUrl (
602- repoInfo . owner ,
603- repoInfo . repo ,
614+ repoInfo ! . owner ,
615+ repoInfo ! . repo ,
604616 token ,
605617 cwd ,
606618 ) ,
607- cleanupOpenPrs ( repoInfo . owner , repoInfo . repo , newVersion , {
619+ cleanupOpenPrs ( repoInfo ! . owner , repoInfo ! . repo , newVersion , {
608620 purl : oldPurl ,
609621 workspace,
610622 } ) ,
611623 ] )
612624 // eslint-disable-next-line no-await-in-loop
613625 const prResponse = await openPr (
614- repoInfo . owner ,
615- repoInfo . repo ,
626+ repoInfo ! . owner ,
627+ repoInfo ! . repo ,
616628 branch ,
617629 oldPurl ,
618630 newVersion ,
0 commit comments