Skip to content

Commit f8153bb

Browse files
committed
Fix type of queries in UserConfig to account for string values
1 parent 17783bf commit f8153bb

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

lib/init-action.js

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

src/config/db-config.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,29 @@ export interface QuerySpec {
2626
uses: string;
2727
}
2828

29+
// We generally accept simple strings or `QuerySpec` objects as inputs for extra queries.
30+
export type QueryInput = QuerySpec | string;
31+
32+
/**
33+
* A helper function for log messages that turns a `QueryInput` into a `string`.
34+
*
35+
* @param input The `QueryInput` to display.
36+
* @returns A string representation of `QueryInput`.
37+
*/
38+
export function renderQueryInput(input: QueryInput): string {
39+
if (typeof input === "string") {
40+
return input;
41+
}
42+
return input.uses;
43+
}
44+
2945
/**
3046
* Format of the config file supplied by the user.
3147
*/
3248
export interface UserConfig {
3349
name?: string;
3450
"disable-default-queries"?: boolean;
35-
queries?: QuerySpec[];
51+
queries?: QueryInput[];
3652
"paths-ignore"?: string[];
3753
paths?: string[];
3854

@@ -374,8 +390,8 @@ function combineQueries(
374390
logger: Logger,
375391
config: UserConfig,
376392
augmentationProperties: AugmentationProperties,
377-
): QuerySpec[] {
378-
const result: QuerySpec[] = [];
393+
): QueryInput[] {
394+
const result: QueryInput[] = [];
379395

380396
// Query settings obtained from the repository properties have the highest precedence.
381397
if (
@@ -440,7 +456,7 @@ export function generateCodeScanningConfig(
440456
augmentationProperties,
441457
);
442458
logger.debug(
443-
`Combined queries: ${augmentedConfig.queries?.map((q) => q.uses).join(",")}`,
459+
`Combined queries: ${augmentedConfig.queries?.map(renderQueryInput).join(",")}`,
444460
);
445461
if (augmentedConfig.queries?.length === 0) {
446462
delete augmentedConfig.queries;

src/status-report.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
isSelfHostedRunner,
1313
} from "./actions-util";
1414
import { getAnalysisKey, getApiClient } from "./api-client";
15-
import { parseRegistriesWithoutCredentials, type Config } from "./config-utils";
15+
import {
16+
parseRegistriesWithoutCredentials,
17+
renderQueryInput,
18+
type Config,
19+
} from "./config-utils";
1620
import { DependencyCacheRestoreStatusReport } from "./dependency-caching";
1721
import { DocUrl } from "./doc-url";
1822
import { EnvVar } from "./environment";
@@ -549,7 +553,7 @@ export async function createInitWithConfigStatusReport(
549553
let queriesInput = getOptionalInput("queries")?.trim();
550554
if (queriesInput === undefined || queriesInput.startsWith("+")) {
551555
queries.push(
552-
...(config.originalUserInput.queries || []).map((q) => q.uses),
556+
...(config.originalUserInput.queries || []).map(renderQueryInput),
553557
);
554558
}
555559
if (queriesInput !== undefined) {

0 commit comments

Comments
 (0)