File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const SARIF_RESULTS_QUERY_KINDS = [
2+ "problem" ,
3+ "alert" ,
4+ "path-problem" ,
5+ "path-alert" ,
6+ ] ;
7+
8+ /**
9+ * Returns whether this query kind supports producing SARIF results.
10+ */
11+ export function isSarifResultsQueryKind ( kind : string | undefined ) : boolean {
12+ if ( ! kind ) {
13+ return false ;
14+ }
15+
16+ return SARIF_RESULTS_QUERY_KINDS . includes ( kind ) ;
17+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type { QueryLanguage } from "../common/query-language";
44import type { CodeQLCliServer } from "../codeql-cli/cli" ;
55import type { QlPackDetails } from "./ql-pack-details" ;
66import { getQlPackFilePath } from "../common/ql" ;
7+ import { isSarifResultsQueryKind } from "../common/query-metadata" ;
78
89export async function resolveCodeScanningQueryPack (
910 logger : BaseLogger ,
@@ -64,10 +65,7 @@ async function filterToOnlyProblemQueries(
6465 const problemQueries : string [ ] = [ ] ;
6566 for ( const query of queries ) {
6667 const queryMetadata = await cliServer . resolveMetadata ( query ) ;
67- if (
68- queryMetadata . kind === "problem" ||
69- queryMetadata . kind === "path-problem"
70- ) {
68+ if ( isSarifResultsQueryKind ( queryMetadata . kind ) ) {
7169 problemQueries . push ( query ) ;
7270 } else {
7371 void logger . log ( `Skipping non-problem query ${ query } ` ) ;
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ import { tryGetQueryMetadata } from "../codeql-cli/query-metadata";
9696import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders" ;
9797import { findVariantAnalysisQlPackRoot } from "./ql" ;
9898import { resolveCodeScanningQueryPack } from "./code-scanning-pack" ;
99+ import { isSarifResultsQueryKind } from "../common/query-metadata" ;
99100
100101const maxRetryCount = 3 ;
101102
@@ -310,21 +311,6 @@ export class VariantAnalysisManager
310311 message : "Getting credentials" ,
311312 } ) ;
312313
313- const {
314- actionBranch,
315- base64Pack,
316- repoSelection,
317- controllerRepo,
318- queryStartTime,
319- } = await prepareRemoteQueryRun (
320- this . cliServer ,
321- this . app . credentials ,
322- qlPackDetails ,
323- progress ,
324- token ,
325- this . dbManager ,
326- ) ;
327-
328314 // For now we get the metadata for the first query in the pack.
329315 // and use that in the submission and query history. In the future
330316 // we'll need to consider how to handle having multiple queries.
@@ -343,6 +329,32 @@ export class VariantAnalysisManager
343329 ) ;
344330 }
345331
332+ // It's not possible to interpret a BQRS file to SARIF without an id property.
333+ if (
334+ queryMetadata ?. kind &&
335+ isSarifResultsQueryKind ( queryMetadata . kind ) &&
336+ ! queryMetadata . id
337+ ) {
338+ throw new UserCancellationException (
339+ `${ firstQueryFile } does not have the required @id property for a ${ queryMetadata . kind } query.` ,
340+ ) ;
341+ }
342+
343+ const {
344+ actionBranch,
345+ base64Pack,
346+ repoSelection,
347+ controllerRepo,
348+ queryStartTime,
349+ } = await prepareRemoteQueryRun (
350+ this . cliServer ,
351+ this . app . credentials ,
352+ qlPackDetails ,
353+ progress ,
354+ token ,
355+ this . dbManager ,
356+ ) ;
357+
346358 const queryText = await readFile ( firstQueryFile , "utf8" ) ;
347359
348360 const queries : VariantAnalysisQueries | undefined =
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { RepositoriesSort } from "./RepositoriesSort";
1111import { RepositoriesFilter } from "./RepositoriesFilter" ;
1212import { RepositoriesResultFormat } from "./RepositoriesResultFormat" ;
1313import type { ResultFormat } from "../../variant-analysis/shared/variant-analysis-result-format" ;
14+ import { isSarifResultsQueryKind } from "../../common/query-metadata" ;
1415
1516type Props = {
1617 filterSortValue : RepositoriesFilterSortState ;
@@ -47,10 +48,7 @@ const RepositoriesResultFormatColumn = styled(RepositoriesResultFormat)`
4748function showResultFormatColumn (
4849 variantAnalysisQueryKind : string | undefined ,
4950) : boolean {
50- return (
51- variantAnalysisQueryKind === "problem" ||
52- variantAnalysisQueryKind === "path-problem"
53- ) ;
51+ return isSarifResultsQueryKind ( variantAnalysisQueryKind ) ;
5452}
5553
5654export const RepositoriesSearchSortRow = ( {
You can’t perform that action at this time.
0 commit comments