Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions extensions/ql-vscode/src/common/query-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const SARIF_RESULTS_QUERY_KINDS = [
"problem",
"alert",
"path-problem",
"path-alert",
];

/**
* Returns whether this query kind supports producing SARIF results.
*/
export function isSarifResultsQueryKind(kind: string | undefined): boolean {
if (!kind) {
return false;
}

return SARIF_RESULTS_QUERY_KINDS.includes(kind);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { QueryLanguage } from "../common/query-language";
import type { CodeQLCliServer } from "../codeql-cli/cli";
import type { QlPackDetails } from "./ql-pack-details";
import { getQlPackFilePath } from "../common/ql";
import { isSarifResultsQueryKind } from "../common/query-metadata";

export async function resolveCodeScanningQueryPack(
logger: BaseLogger,
Expand Down Expand Up @@ -64,10 +65,7 @@ async function filterToOnlyProblemQueries(
const problemQueries: string[] = [];
for (const query of queries) {
const queryMetadata = await cliServer.resolveMetadata(query);
if (
queryMetadata.kind === "problem" ||
queryMetadata.kind === "path-problem"
) {
if (isSarifResultsQueryKind(queryMetadata.kind)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't change behaviour since all queries in the published packs should be using the new query kinds. Also it should be safe anyway and more correct than it was before.

problemQueries.push(query);
} else {
void logger.log(`Skipping non-problem query ${query}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { tryGetQueryMetadata } from "../codeql-cli/query-metadata";
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
import { findVariantAnalysisQlPackRoot } from "./ql";
import { resolveCodeScanningQueryPack } from "./code-scanning-pack";
import { isSarifResultsQueryKind } from "../common/query-metadata";

const maxRetryCount = 3;

Expand Down Expand Up @@ -309,21 +310,6 @@ export class VariantAnalysisManager
message: "Getting credentials",
});

const {
actionBranch,
base64Pack,
repoSelection,
controllerRepo,
queryStartTime,
} = await prepareRemoteQueryRun(
this.cliServer,
this.app.credentials,
qlPackDetails,
progress,
token,
this.dbManager,
);

// For now we get the metadata for the first query in the pack.
// and use that in the submission and query history. In the future
// we'll need to consider how to handle having multiple queries.
Expand All @@ -342,6 +328,32 @@ export class VariantAnalysisManager
);
}

// It's not possible to interpret a BQRS file to SARIF without an id property.
if (
queryMetadata?.kind &&
isSarifResultsQueryKind(queryMetadata.kind) &&
!queryMetadata.id
) {
throw new UserCancellationException(
`${firstQueryFile} does not have the required @id property for a ${queryMetadata.kind} query.`,
);
}

const {
actionBranch,
base64Pack,
repoSelection,
controllerRepo,
queryStartTime,
} = await prepareRemoteQueryRun(
this.cliServer,
this.app.credentials,
qlPackDetails,
progress,
token,
this.dbManager,
);

const queryText = await readFile(firstQueryFile, "utf8");

const queries: VariantAnalysisQueries | undefined =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RepositoriesSort } from "./RepositoriesSort";
import { RepositoriesFilter } from "./RepositoriesFilter";
import { RepositoriesResultFormat } from "./RepositoriesResultFormat";
import type { ResultFormat } from "../../variant-analysis/shared/variant-analysis-result-format";
import { isSarifResultsQueryKind } from "../../common/query-metadata";

type Props = {
filterSortValue: RepositoriesFilterSortState;
Expand Down Expand Up @@ -47,10 +48,7 @@ const RepositoriesResultFormatColumn = styled(RepositoriesResultFormat)`
function showResultFormatColumn(
variantAnalysisQueryKind: string | undefined,
): boolean {
return (
variantAnalysisQueryKind === "problem" ||
variantAnalysisQueryKind === "path-problem"
);
return isSarifResultsQueryKind(variantAnalysisQueryKind);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that this could cause a tiny UI inconsistency until https://github.com/github/codeql-variant-analysis-action/blob/4a8a27800b99bca0d1900c940648b70243804e2f/src/codeql.ts#L351 is also updated. This is because we decide to show the column based on the query kind instead of whether there are SARIF results available, because we can't check every repo and we need to show the column before any repos have been analysed.

However, I think it's fine to merge this as it's highly unlikely to affect anybody and it's fine so long as we also update the variant analysis action soon.

}

export const RepositoriesSearchSortRow = ({
Expand Down