Skip to content

Commit 7ea93ee

Browse files
committed
Add support for boolean repository properties
1 parent 28737ec commit 7ea93ee

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

lib/init-action.js

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

src/feature-flags/properties.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test("loadPropertiesFromApi returns empty object if on GHES", async (t) => {
5959
data: [
6060
{ property_name: "github-codeql-extra-queries", value: "+queries" },
6161
{ property_name: "unknown-property", value: "something" },
62-
] satisfies properties.RepositoryProperty[],
62+
] satisfies properties.GitHubPropertiesResponse,
6363
});
6464
const logger = getRunnerLogger(true);
6565
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
@@ -82,7 +82,7 @@ test("loadPropertiesFromApi loads known properties", async (t) => {
8282
data: [
8383
{ property_name: "github-codeql-extra-queries", value: "+queries" },
8484
{ property_name: "unknown-property", value: "something" },
85-
] satisfies properties.RepositoryProperty[],
85+
] satisfies properties.GitHubPropertiesResponse,
8686
});
8787
const logger = getRunnerLogger(true);
8888
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");

src/feature-flags/properties.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,50 @@ import { GitHubVariant, GitHubVersion } from "../util";
77
* Enumerates repository property names that have some meaning to us.
88
*/
99
export enum RepositoryPropertyName {
10+
DISABLE_OVERLAY = "github-codeql-disable-overlay",
1011
EXTRA_QUERIES = "github-codeql-extra-queries",
1112
}
1213

14+
function isKnownPropertyName(value: string): value is RepositoryPropertyName {
15+
return Object.values(RepositoryPropertyName).includes(
16+
value as RepositoryPropertyName,
17+
);
18+
}
19+
20+
type AllRepositoryProperties = {
21+
[RepositoryPropertyName.DISABLE_OVERLAY]: boolean;
22+
[RepositoryPropertyName.EXTRA_QUERIES]: string;
23+
};
24+
25+
export type RepositoryProperties = Partial<AllRepositoryProperties>;
26+
27+
const mapRepositoryProperties: {
28+
[K in RepositoryPropertyName]: (value: string) => AllRepositoryProperties[K];
29+
} = {
30+
[RepositoryPropertyName.DISABLE_OVERLAY]: (value) => value === "true",
31+
[RepositoryPropertyName.EXTRA_QUERIES]: (value) => value,
32+
};
33+
34+
function setProperty<K extends RepositoryPropertyName>(
35+
properties: RepositoryProperties,
36+
name: K,
37+
value: string,
38+
): void {
39+
properties[name] = mapRepositoryProperties[name](value);
40+
}
41+
1342
/**
1443
* A repository property has a name and a value.
1544
*/
16-
export interface RepositoryProperty {
45+
interface GitHubRepositoryProperty {
1746
property_name: string;
1847
value: string;
1948
}
2049

2150
/**
2251
* The API returns a list of `RepositoryProperty` objects.
2352
*/
24-
type GitHubPropertiesResponse = RepositoryProperty[];
25-
26-
/**
27-
* A partial mapping from `RepositoryPropertyName` to values.
28-
*/
29-
export type RepositoryProperties = Partial<
30-
Record<RepositoryPropertyName, string>
31-
>;
53+
export type GitHubPropertiesResponse = GitHubRepositoryProperty[];
3254

3355
/**
3456
* Retrieves all known repository properties from the API.
@@ -62,7 +84,6 @@ export async function loadPropertiesFromApi(
6284
`Retrieved ${remoteProperties.length} repository properties: ${remoteProperties.map((p) => p.property_name).join(", ")}`,
6385
);
6486

65-
const knownProperties = new Set(Object.values(RepositoryPropertyName));
6687
const properties: RepositoryProperties = {};
6788
for (const property of remoteProperties) {
6889
if (property.property_name === undefined) {
@@ -71,10 +92,8 @@ export async function loadPropertiesFromApi(
7192
);
7293
}
7394

74-
if (
75-
knownProperties.has(property.property_name as RepositoryPropertyName)
76-
) {
77-
properties[property.property_name] = property.value;
95+
if (isKnownPropertyName(property.property_name)) {
96+
setProperty(properties, property.property_name, property.value);
7897
}
7998
}
8099

0 commit comments

Comments
 (0)