Skip to content

Commit 9c61a2d

Browse files
committed
Reorganize properties file
1 parent 2808ca7 commit 9c61a2d

File tree

2 files changed

+65
-45
lines changed

2 files changed

+65
-45
lines changed

lib/init-action.js

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

src/feature-flags/properties.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ export enum RepositoryPropertyName {
1111
EXTRA_QUERIES = "github-codeql-extra-queries",
1212
}
1313

14-
const KNOWN_REPOSITORY_PROPERTY_NAMES = new Set<string>(
15-
Object.values(RepositoryPropertyName),
16-
);
17-
18-
function isKnownPropertyName(value: string): value is RepositoryPropertyName {
19-
return KNOWN_REPOSITORY_PROPERTY_NAMES.has(value);
20-
}
21-
14+
/** Parsed types of the known repository properties. */
2215
type AllRepositoryProperties = {
2316
[RepositoryPropertyName.DISABLE_OVERLAY]: boolean;
2417
[RepositoryPropertyName.EXTRA_QUERIES]: string;
2518
};
2619

20+
/** Parsed repository properties. */
2721
export type RepositoryProperties = Partial<AllRepositoryProperties>;
2822

2923
/** Parsers that transform repository properties from the API response into typed values. */
@@ -34,27 +28,10 @@ const repositoryPropertyParsers: {
3428
logger: Logger,
3529
) => AllRepositoryProperties[K];
3630
} = {
37-
[RepositoryPropertyName.DISABLE_OVERLAY]: (name, value, logger) => {
38-
if (value !== "true" && value !== "false") {
39-
logger.warning(
40-
`Repository property '${name}' has unexpected value '${value}'. Expected 'true' or 'false'. Defaulting to false.`,
41-
);
42-
}
43-
return value === "true";
44-
},
45-
[RepositoryPropertyName.EXTRA_QUERIES]: (_name, value) => value,
31+
[RepositoryPropertyName.DISABLE_OVERLAY]: parseBooleanRepositoryProperty,
32+
[RepositoryPropertyName.EXTRA_QUERIES]: parseStringRepositoryProperty,
4633
};
4734

48-
/** Update the partial set of repository properties with the parsed value of the specified property. */
49-
function setProperty<K extends RepositoryPropertyName>(
50-
properties: RepositoryProperties,
51-
name: K,
52-
value: string,
53-
logger: Logger,
54-
): void {
55-
properties[name] = repositoryPropertyParsers[name](name, value, logger);
56-
}
57-
5835
/**
5936
* A repository property has a name and a value.
6037
*/
@@ -139,3 +116,42 @@ export async function loadPropertiesFromApi(
139116
);
140117
}
141118
}
119+
120+
/** Update the partial set of repository properties with the parsed value of the specified property. */
121+
function setProperty<K extends RepositoryPropertyName>(
122+
properties: RepositoryProperties,
123+
name: K,
124+
value: string,
125+
logger: Logger,
126+
): void {
127+
properties[name] = repositoryPropertyParsers[name](name, value, logger);
128+
}
129+
130+
/** Parse a boolean repository property. */
131+
function parseBooleanRepositoryProperty(
132+
name: string,
133+
value: string,
134+
logger: Logger,
135+
): boolean {
136+
if (value !== "true" && value !== "false") {
137+
logger.warning(
138+
`Repository property '${name}' has unexpected value '${value}'. Expected 'true' or 'false'. Defaulting to false.`,
139+
);
140+
}
141+
return value === "true";
142+
}
143+
144+
/** Parse a string repository property. */
145+
function parseStringRepositoryProperty(_name: string, value: string): string {
146+
return value;
147+
}
148+
149+
/** Set of known repository property names, for fast lookups. */
150+
const KNOWN_REPOSITORY_PROPERTY_NAMES = new Set<string>(
151+
Object.values(RepositoryPropertyName),
152+
);
153+
154+
/** Returns whether the given value is a known repository property name. */
155+
function isKnownPropertyName(name: string): name is RepositoryPropertyName {
156+
return KNOWN_REPOSITORY_PROPERTY_NAMES.has(name);
157+
}

0 commit comments

Comments
 (0)