11import { detectCiPullRequestContext } from './detect-ci-pull-request-context.mts'
22import { getDefaultOrgSlug } from './fetch-default-org-slug.mts'
3+ import {
4+ markPrIgnoreCommandsProcessed ,
5+ readPrIgnoreCommands ,
6+ } from './pr-ignore-commands.mts'
37import {
48 reportGitLabCommitStatusFailure ,
59 withGitLabCommitStatus ,
@@ -34,11 +38,16 @@ import {
3438} from '../scan/python-diff-json.mts'
3539
3640import type { PythonDiffJsonContext } from '../scan/python-diff-json.mts'
41+ import type { IgnoreAuthorization } from './pr-ignore-commands.mts'
3742
3843export async function handleCi (
3944 autoManifest : boolean ,
4045 pythonJsonFormat = false ,
4146 strictBlocking = false ,
47+ ignoreSettings : {
48+ authorization ?: IgnoreAuthorization | undefined
49+ disabled ?: boolean | undefined
50+ } = { } ,
4251) : Promise < void > {
4352 debugFn ( 'notice' , 'Starting CI scan' )
4453 debugDir ( 'inspect' , { autoManifest, pythonJsonFormat } )
@@ -183,6 +192,8 @@ export async function handleCi(
183192 pullRequestContext,
184193 pythonJsonContext,
185194 pythonJsonFormat,
195+ ignoreAuthorization : ignoreSettings . authorization ?? 'enforce' ,
196+ disableIgnore : ignoreSettings . disabled ?? false ,
186197 repoName,
187198 } )
188199 } )
@@ -192,6 +203,8 @@ async function runCiScan({
192203 autoManifest,
193204 branchName,
194205 cwd,
206+ disableIgnore,
207+ ignoreAuthorization,
195208 onDiffOutcome,
196209 orgSlug,
197210 pullRequestContext,
@@ -213,6 +226,8 @@ async function runCiScan({
213226 pullRequestContext : Awaited < ReturnType < typeof detectCiPullRequestContext > >
214227 pythonJsonContext : PythonDiffJsonContext
215228 pythonJsonFormat : boolean
229+ ignoreAuthorization : IgnoreAuthorization
230+ disableIgnore : boolean
216231 repoName : string
217232} ) : Promise < void > {
218233 const { number : pullRequest } = pullRequestContext
@@ -266,6 +281,13 @@ async function runCiScan({
266281 debugDir ( 'inspect' , { orgSlug, cwd, branchName, repoName } )
267282
268283 const [ owner , repo ] = ( constants . ENV . GITHUB_REPOSITORY || '' ) . split ( '/' )
284+ const ignoreCommands = baselineScanId
285+ ? await readPrIgnoreCommands ( {
286+ authorization : ignoreAuthorization ,
287+ context : pullRequestContext ,
288+ disabled : disableIgnore ,
289+ } )
290+ : [ ]
269291 await handleCreateNewScan ( {
270292 autoManifest,
271293 branchName,
@@ -286,6 +308,7 @@ async function runCiScan({
286308 pendingHead : true ,
287309 pullRequest,
288310 pullRequestUrl : pullRequestContext . url ,
311+ prIgnoreCommands : ignoreCommands ,
289312 baselineScanId,
290313 onDiffReport : async ( diffScanId , outcome ) => {
291314 onDiffOutcome ( outcome )
@@ -302,6 +325,10 @@ async function runCiScan({
302325 console . error (
303326 'Socket could not publish GitLab merge request notes: missing target project metadata. Check CI_MERGE_REQUEST_PROJECT_ID, CI_MERGE_REQUEST_PROJECT_URL, and CI_SERVER_URL.' ,
304327 )
328+ await markPrIgnoreCommandsProcessed ( {
329+ commands : ignoreCommands ,
330+ context : pullRequestContext ,
331+ } )
305332 return
306333 }
307334 try {
@@ -314,6 +341,8 @@ async function runCiScan({
314341 process . env [ 'SOCKET_CLI_DISABLE_SECURITY_COMMENT' ] ,
315342 ) ,
316343 orgSlug,
344+ ignoreCommands,
345+ disableIgnore,
317346 mergeRequestIid : pullRequest ,
318347 projectId,
319348 projectUrl,
@@ -326,6 +355,10 @@ async function runCiScan({
326355 errorMessage ( error ) ,
327356 )
328357 }
358+ await markPrIgnoreCommandsProcessed ( {
359+ commands : ignoreCommands ,
360+ context : pullRequestContext ,
361+ } )
329362 return
330363 }
331364 if (
@@ -334,6 +367,10 @@ async function runCiScan({
334367 ! repo ||
335368 ! constants . ENV . SOCKET_CLI_GITHUB_TOKEN
336369 ) {
370+ await markPrIgnoreCommandsProcessed ( {
371+ commands : ignoreCommands ,
372+ context : pullRequestContext ,
373+ } )
337374 return
338375 }
339376 try {
@@ -346,6 +383,8 @@ async function runCiScan({
346383 process . env [ 'SOCKET_CLI_DISABLE_SECURITY_COMMENT' ] ,
347384 ) ,
348385 orgSlug,
386+ ignoreCommands,
387+ disableIgnore,
349388 owner,
350389 pullRequest,
351390 repo,
@@ -357,6 +396,10 @@ async function runCiScan({
357396 'Socket could not publish the scan comments. Check the Socket API scopes and GitHub pull request write permission.\n' ,
358397 )
359398 }
399+ await markPrIgnoreCommandsProcessed ( {
400+ commands : ignoreCommands ,
401+ context : pullRequestContext ,
402+ } )
360403 } ,
361404 reach : {
362405 dynamicSbomInference : undefined ,
0 commit comments