Skip to content

Commit 7a01ee2

Browse files
committed
Tweak pr filter for fix
1 parent 2dadad1 commit 7a01ee2

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/commands/fix/agent-fix.mts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { getFixEnv } from './fix-env-helpers.mts'
2222
import { getActualTree } from './get-actual-tree.mts'
2323
import {
2424
getSocketBranchName,
25-
getSocketBranchWorkspaceComponent,
2625
getSocketCommitMessage,
2726
gitCreateAndPushBranch,
2827
gitRemoteBranchExists,
@@ -238,9 +237,6 @@ export async function agentFix(
238237
const workspace = isWorkspaceRoot
239238
? 'root'
240239
: path.relative(rootPath, pkgPath)
241-
const branchWorkspace = fixEnv.isCi
242-
? getSocketBranchWorkspaceComponent(workspace)
243-
: ''
244240
// actualTree may not be defined on the first iteration of pkgJsonPathsLoop.
245241
if (!actualTree) {
246242
if (!fixEnv.isCi) {
@@ -326,10 +322,7 @@ export async function agentFix(
326322
continue infosLoop
327323
}
328324
const branch = getSocketBranchName(oldPurl, newVersion, workspace)
329-
const pr = prs.find(
330-
({ parsedBranch: b }) =>
331-
b.workspace === branchWorkspace && b.newVersion === newVersion,
332-
)
325+
const pr = prs.find(p => p.headRefName === branch)
333326
if (pr) {
334327
debugFn('notice', `skip: PR #${pr.number} for ${name} exists`)
335328
if (++count >= limit) {

src/commands/fix/pull-request.mts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
1717

1818
import {
1919
createSocketBranchParser,
20-
genericSocketBranchParser,
20+
getSocketBranchPattern,
2121
getSocketPullRequestBody,
2222
getSocketPullRequestTitle,
2323
} from './git.mts'
2424
import constants from '../../constants.mts'
2525
import { safeStatsSync } from '../../utils/fs.mts'
2626
import { getPurlObject } from '../../utils/purl.mts'
2727

28-
import type { SocketBranchParseResult } from './git.mts'
2928
import type { SocketArtifact } from '../../utils/alert/artifact.mts'
3029
import type { components } from '@octokit/openapi-types'
3130
import type { OctokitResponse } from '@octokit/types'
@@ -131,7 +130,6 @@ export type PrMatch = {
131130
headRefName: string
132131
mergeStateStatus: GQL_MERGE_STATE_STATUS
133132
number: number
134-
parsedBranch: SocketBranchParseResult
135133
state: GQL_PR_STATE
136134
title: string
137135
}
@@ -312,6 +310,7 @@ async function getSocketPrsWithContext(
312310
__proto__: null,
313311
...options,
314312
} as SocketPrsOptions
313+
const branchPattern = getSocketBranchPattern(options)
315314
const checkAuthor = isNonEmptyString(author)
316315
const octokit = getOctokit()
317316
const octokitGraphql = getOctokitGraphql()
@@ -373,8 +372,8 @@ async function getSocketPrsWithContext(
373372
const node = nodes[i]!
374373
const login = node.author?.login
375374
const matchesAuthor = checkAuthor ? login === author : true
376-
const parsedBranch = genericSocketBranchParser(node.headRefName)
377-
if (matchesAuthor && parsedBranch) {
375+
const matchesBranch = branchPattern.test(node.headRefName)
376+
if (matchesAuthor && matchesBranch) {
378377
contextualMatches.push({
379378
context: {
380379
apiType: 'graphql',
@@ -387,7 +386,6 @@ async function getSocketPrsWithContext(
387386
match: {
388387
...node,
389388
author: login ?? '<unknown>',
390-
parsedBranch,
391389
},
392390
})
393391
}
@@ -423,8 +421,8 @@ async function getSocketPrsWithContext(
423421
const login = pr.user?.login
424422
const headRefName = pr.head.ref
425423
const matchesAuthor = checkAuthor ? login === author : true
426-
const parsedBranch = genericSocketBranchParser(headRefName)
427-
if (matchesAuthor && parsedBranch) {
424+
const matchesBranch = branchPattern.test(headRefName)
425+
if (matchesAuthor && matchesBranch) {
428426
// Upper cased mergeable_state is equivalent to mergeStateStatus.
429427
// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
430428
const mergeStateStatus = (pr.mergeable_state?.toUpperCase?.() ??
@@ -450,7 +448,6 @@ async function getSocketPrsWithContext(
450448
headRefName,
451449
mergeStateStatus,
452450
number: pr.number,
453-
parsedBranch,
454451
state,
455452
title: pr.title,
456453
},

0 commit comments

Comments
 (0)