@@ -4,13 +4,9 @@ import { joinAnd } from '@socketsecurity/registry/lib/arrays'
44import { debugDir , debugFn } from '@socketsecurity/registry/lib/debug'
55import { logger } from '@socketsecurity/registry/lib/logger'
66
7- import { getFixEnv } from './fix-env-helpers.mts'
8- import {
9- enablePrAutoMerge ,
10- fetchGhsaDetails ,
11- openCoanaPr ,
12- setGitRemoteGithubRepoUrl ,
13- } from './pull-request.mts'
7+ import { getFixEnv } from './env-helpers.mts'
8+ import { getSocketFixBranchName , getSocketFixCommitMessage } from './git.mts'
9+ import { openSocketFixPr } from './pull-request.mts'
1410import { handleApiCall } from '../../utils/api.mts'
1511import { cmdFlagValueToArray } from '../../utils/cmd.mts'
1612import { spawnCoana } from '../../utils/coana.mts'
@@ -24,6 +20,11 @@ import {
2420 gitResetAndClean ,
2521 gitUnstagedModifiedFiles ,
2622} from '../../utils/git.mts'
23+ import {
24+ enablePrAutoMerge ,
25+ fetchGhsaDetails ,
26+ setGitRemoteGithubRepoUrl ,
27+ } from '../../utils/github.mts'
2728import { getPackageFilesForScan } from '../../utils/path-resolve.mts'
2829import { setupSdk } from '../../utils/sdk.mts'
2930import { fetchSupportedScanFileNames } from '../scan/fetch-supported-scan-file-names.mts'
@@ -166,8 +167,8 @@ export async function coanaFix(
166167
167168 // Process each GHSA ID individually, similar to npm-fix/pnpm-fix.
168169 ghsaLoop: for ( let i = 0 , { length } = ids ; i < length ; i += 1 ) {
169- const id = ids [ i ] !
170- debugFn ( 'notice' , `check: ${ id } ` )
170+ const ghsaId = ids [ i ] !
171+ debugFn ( 'notice' , `check: ${ ghsaId } ` )
171172
172173 // Apply fix for single GHSA ID.
173174 // eslint-disable-next-line no-await-in-loop
@@ -178,7 +179,7 @@ export async function coanaFix(
178179 '--manifests-tar-hash' ,
179180 tarHash ,
180181 '--apply-fixes-to' ,
181- id ,
182+ ghsaId ,
182183 ...( fixConfig . rangeStyle
183184 ? [ '--range-style' , fixConfig . rangeStyle ]
184185 : [ ] ) ,
@@ -190,7 +191,7 @@ export async function coanaFix(
190191
191192 if ( ! fixCResult . ok ) {
192193 logger . error (
193- `Update failed for ${ id } : ${ fixCResult . message || 'Unknown error' } ` ,
194+ `Update failed for ${ ghsaId } : ${ fixCResult . message || 'Unknown error' } ` ,
194195 )
195196 continue ghsaLoop
196197 }
@@ -205,13 +206,13 @@ export async function coanaFix(
205206 : [ ]
206207
207208 if ( ! modifiedFiles . length ) {
208- debugFn ( 'notice' , `skip: no changes for ${ id } ` )
209+ debugFn ( 'notice' , `skip: no changes for ${ ghsaId } ` )
209210 continue ghsaLoop
210211 }
211212
212213 overallFixed = true
213214
214- const branch = `socket/fix/ ${ id } `
215+ const branch = getSocketFixBranchName ( ghsaId )
215216
216217 try {
217218 // Check if branch already exists.
@@ -221,11 +222,13 @@ export async function coanaFix(
221222 continue ghsaLoop
222223 }
223224
224- debugFn ( 'notice' , `pr: creating for ${ id } ` )
225+ debugFn ( 'notice' , `pr: creating for ${ ghsaId } ` )
225226
226- const details = ghsaDetails . get ( id )
227- const summary = details ?. summary
228- debugFn ( 'notice' , `ghsa: ${ id } details ${ details ? 'found' : 'missing' } ` )
227+ const details = ghsaDetails . get ( ghsaId )
228+ debugFn (
229+ 'notice' ,
230+ `ghsa: ${ ghsaId } details ${ details ? 'found' : 'missing' } ` ,
231+ )
229232
230233 const pushed =
231234 // eslint-disable-next-line no-await-in-loop
@@ -234,7 +237,7 @@ export async function coanaFix(
234237 ( await gitCheckoutBranch ( branch , cwd ) ) &&
235238 // eslint-disable-next-line no-await-in-loop
236239 ( await gitCommit (
237- `fix: ${ id } ${ summary ? ` - ${ summary } ` : '' } ` ,
240+ getSocketFixCommitMessage ( ghsaId , details ) ,
238241 modifiedFiles ,
239242 {
240243 cwd,
@@ -246,7 +249,7 @@ export async function coanaFix(
246249 ( await gitPushBranch ( branch , cwd ) )
247250
248251 if ( ! pushed ) {
249- logger . warn ( `Push failed for ${ id } , skipping PR creation.` )
252+ logger . warn ( `Push failed for ${ ghsaId } , skipping PR creation.` )
250253 // eslint-disable-next-line no-await-in-loop
251254 await gitResetAndClean ( fixEnv . baseBranch , cwd )
252255 // eslint-disable-next-line no-await-in-loop
@@ -266,12 +269,12 @@ export async function coanaFix(
266269 )
267270
268271 // eslint-disable-next-line no-await-in-loop
269- const prResponse = await openCoanaPr (
272+ const prResponse = await openSocketFixPr (
270273 fixEnv . repoInfo . owner ,
271274 fixEnv . repoInfo . repo ,
272275 branch ,
273276 // Single GHSA ID.
274- [ id ] ,
277+ [ ghsaId ] ,
275278 {
276279 baseBranch : fixEnv . baseBranch ,
277280 cwd,
@@ -282,7 +285,7 @@ export async function coanaFix(
282285 if ( prResponse ) {
283286 const { data } = prResponse
284287 const prRef = `PR #${ data . number } `
285- logger . success ( `Opened ${ prRef } for ${ id } .` )
288+ logger . success ( `Opened ${ prRef } for ${ ghsaId } .` )
286289
287290 if ( autoMerge ) {
288291 logger . indent ( )
@@ -309,7 +312,7 @@ export async function coanaFix(
309312 await gitCheckoutBranch ( fixEnv . baseBranch , cwd )
310313 } catch ( e ) {
311314 logger . warn (
312- `Unexpected condition: Push failed for ${ id } , skipping PR creation.` ,
315+ `Unexpected condition: Push failed for ${ ghsaId } , skipping PR creation.` ,
313316 )
314317 debugDir ( 'inspect' , { error : e } )
315318 // eslint-disable-next-line no-await-in-loop
0 commit comments