Skip to content

Commit bfa6493

Browse files
committedAug 2, 2021
fix: support of the new Code API
1 parent b7a190b commit bfa6493

File tree

3 files changed

+1550
-4387
lines changed

3 files changed

+1550
-4387
lines changed
 

‎src/lib/plugins/sast/analysis.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,14 @@ async function getCodeAnalysis(root: string, options: Options): Promise<Log> {
4949
const severity = options.severityThreshold
5050
? severityToAnalysisSeverity(options.severityThreshold)
5151
: AnalysisSeverity.info;
52-
const paths: string[] = [root];
53-
const sarif = true;
52+
5453
const result = await analyzeFolders({
55-
baseURL,
56-
sessionToken,
57-
severity,
58-
paths,
59-
sarif,
54+
connection: { baseURL, sessionToken, source: 'snyk-cli' },
55+
analysisOptions: { severity },
56+
fileOptions: { paths: [root] },
6057
});
6158

62-
return result.sarifResults!;
59+
return result?.analysisResults.sarif!;
6360
}
6461

6562
function severityToAnalysisSeverity(severity: SEVERITY): AnalysisSeverity {

‎test/fixtures/sast/sample-analyze-folders-response.json

+1,535-4,373
Large diffs are not rendered by default.

‎test/jest/unit/snyk-code-test.spec.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,20 @@ describe('Test snyk code', () => {
360360
it('analyzeFolders should be called with the right arguments', async () => {
361361
const baseURL = expect.any(String);
362362
const sessionToken = expect.any(String);
363+
const source = expect.any(String);
363364
const severity = AnalysisSeverity.info;
364365
const paths: string[] = ['.'];
365-
const sarif = true;
366366

367367
const codeAnalysisArgs = {
368-
baseURL,
369-
sessionToken,
370-
severity,
371-
paths,
372-
sarif,
368+
connection: {
369+
baseURL,
370+
sessionToken,
371+
source,
372+
},
373+
analysisOptions: {
374+
severity,
375+
},
376+
fileOptions: { paths },
373377
};
374378

375379
const analyzeFoldersSpy = analyzeFoldersMock.mockResolvedValue(

0 commit comments

Comments
 (0)
Please sign in to comment.