Skip to content

Commit 3c7d9ca

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Add function for running autofix on a given SARIF
1 parent 19400a9 commit 3c7d9ca

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

extensions/ql-vscode/src/variant-analysis/view-autofixes.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,59 @@ async function getRepoStoragePaths(
544544
};
545545
}
546546

547+
/**
548+
* Runs autofix on the results in the given SARIF file.
549+
*/
550+
async function runAutofixOnResults(
551+
logger: NotificationLogger,
552+
cocofixBin: string,
553+
sarifFile: string,
554+
srcRootPath: string,
555+
outputTextFilePath: string,
556+
fixDescriptionFilePath: string,
557+
transcriptFilePath: string,
558+
workDir: string,
559+
alertNumber?: number, // Optional parameter for specific alert
560+
): Promise<void> {
561+
// Set up args for autofix command.
562+
const fixedAutofixArgs = [
563+
"--sarif",
564+
sarifFile,
565+
"--source-root",
566+
srcRootPath,
567+
"--model",
568+
"capi-dev-4o", // may fail with older versions of cocofix
569+
"--dev",
570+
"--no-cache",
571+
"--format",
572+
"text",
573+
"--diff-style",
574+
"diff", // could do "text" instead if want line of "=" between fixes
575+
];
576+
const varAutofixArgs = createVarAutofixArgs(
577+
outputTextFilePath,
578+
fixDescriptionFilePath,
579+
transcriptFilePath,
580+
alertNumber,
581+
);
582+
583+
const autofixArgs = [...fixedAutofixArgs, ...varAutofixArgs];
584+
585+
await execAutofix(
586+
logger,
587+
cocofixBin,
588+
autofixArgs,
589+
{
590+
cwd: workDir,
591+
env: {
592+
CAPI_DEV_KEY: process.env.CAPI_DEV_KEY,
593+
PATH: process.env.PATH,
594+
},
595+
},
596+
true,
597+
);
598+
}
599+
547600
/**
548601
* Creates autofix arguments that vary depending on the run.
549602
*/

0 commit comments

Comments
 (0)