Skip to content

Commit 899bf2f

Browse files
committed
Use postProcessSarifFiles and uploadProcessedFiles in uploadSarif
1 parent 6fbdd5f commit 899bf2f

File tree

6 files changed

+56
-49
lines changed

6 files changed

+56
-49
lines changed

lib/analyze-action.js

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 10 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ export async function uploadFiles(
789789
/**
790790
* Uploads the given array of SARIF files.
791791
*/
792-
export async function uploadSpecifiedFiles(
792+
async function uploadSpecifiedFiles(
793793
sarifPaths: string[],
794794
checkoutPath: string,
795795
category: string | undefined,

src/upload-sarif.test.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,29 @@ const uploadSarifMacro = test.macro({
3333

3434
const toFullPath = (filename: string) => path.join(tempDir, filename);
3535

36-
const uploadSpecifiedFiles = sinon.stub(
36+
const postProcessSarifFiles = sinon.stub(
3737
uploadLib,
38-
"uploadSpecifiedFiles",
38+
"postProcessSarifFiles",
39+
);
40+
const uploadProcessedFiles = sinon.stub(
41+
uploadLib,
42+
"uploadProcessedFiles",
3943
);
4044

4145
for (const analysisKind of Object.values(AnalysisKind)) {
42-
uploadSpecifiedFiles
46+
const analysisConfig = getAnalysisConfig(analysisKind);
47+
postProcessSarifFiles
4348
.withArgs(
49+
logger,
4450
sinon.match.any,
4551
sinon.match.any,
4652
sinon.match.any,
47-
features,
48-
logger,
49-
getAnalysisConfig(analysisKind),
53+
sinon.match.any,
54+
analysisConfig,
5055
)
56+
.resolves({ sarif: { runs: [] }, analysisKey: "", environment: "" });
57+
uploadProcessedFiles
58+
.withArgs(logger, sinon.match.any, analysisConfig, sinon.match.any)
5159
.resolves(expectedResult[analysisKind as AnalysisKind]?.uploadResult);
5260
}
5361

@@ -63,35 +71,33 @@ const uploadSarifMacro = test.macro({
6371
if (analysisKindResult) {
6472
// We are expecting a result for this analysis kind, check that we have it.
6573
t.deepEqual(actual[analysisKind], analysisKindResult.uploadResult);
66-
// Additionally, check that the mocked `uploadSpecifiedFiles` was called with only the file paths
74+
// Additionally, check that the mocked `postProcessSarifFiles` was called with only the file paths
6775
// that we expected it to be called with.
6876
t.assert(
69-
uploadSpecifiedFiles.calledWith(
77+
postProcessSarifFiles.calledWith(
78+
logger,
79+
features,
80+
sinon.match.any,
7081
analysisKindResult.expectedFiles?.map(toFullPath) ??
7182
fullSarifPaths,
7283
sinon.match.any,
73-
sinon.match.any,
74-
features,
75-
logger,
7684
getAnalysisConfig(analysisKind),
7785
),
7886
);
7987
} else {
8088
// Otherwise, we are not expecting a result for this analysis kind. However, note that `undefined`
81-
// is also returned by our mocked `uploadSpecifiedFiles` when there is no expected result for this
89+
// is also returned by our mocked `uploadProcessedFiles` when there is no expected result for this
8290
// analysis kind.
8391
t.is(actual[analysisKind], undefined);
84-
// Therefore, we also check that the mocked `uploadSpecifiedFiles` was not called for this analysis kind.
92+
// Therefore, we also check that the mocked `uploadProcessedFiles` was not called for this analysis kind.
8593
t.assert(
86-
!uploadSpecifiedFiles.calledWith(
87-
sinon.match.any,
88-
sinon.match.any,
89-
sinon.match.any,
90-
features,
94+
!uploadProcessedFiles.calledWith(
9195
logger,
96+
sinon.match.any,
9297
getAnalysisConfig(analysisKind),
98+
sinon.match.any,
9399
),
94-
`uploadSpecifiedFiles was called for ${analysisKind}, but should not have been.`,
100+
`uploadProcessedFiles was called for ${analysisKind}, but should not have been.`,
95101
);
96102
}
97103
}

src/upload-sarif.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ export async function uploadSarif(
3737
sarifGroups,
3838
)) {
3939
const analysisConfig = analyses.getAnalysisConfig(analysisKind);
40-
uploadResults[analysisKind] = await upload_lib.uploadSpecifiedFiles(
41-
sarifFiles,
40+
const processingResults = await upload_lib.postProcessSarifFiles(
41+
logger,
42+
features,
4243
checkoutPath,
44+
sarifFiles,
4345
category,
44-
features,
46+
analysisConfig,
47+
);
48+
49+
uploadResults[analysisKind] = await upload_lib.uploadProcessedFiles(
4550
logger,
51+
checkoutPath,
4652
analysisConfig,
53+
processingResults,
4754
);
4855
}
4956

0 commit comments

Comments
 (0)