mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Add nonEmptyStringProperty
This commit is contained in:
12
lib/entry-points.js
generated
12
lib/entry-points.js
generated
@@ -147996,13 +147996,17 @@ var stringProperty = {
|
||||
validate: isString2,
|
||||
parse: parseStringRepositoryProperty
|
||||
};
|
||||
var nonEmptyStringProperty = {
|
||||
...stringProperty,
|
||||
parse: parseNonEmptyStringRepositoryProperty
|
||||
};
|
||||
var booleanProperty = {
|
||||
// The value from the API should come as a string, which we then parse into a boolean.
|
||||
validate: isString2,
|
||||
parse: parseBooleanRepositoryProperty
|
||||
};
|
||||
var repositoryPropertyParsers = {
|
||||
["github-codeql-config-file" /* CONFIG_FILE */]: stringProperty,
|
||||
["github-codeql-config-file" /* CONFIG_FILE */]: nonEmptyStringProperty,
|
||||
["github-codeql-disable-overlay" /* DISABLE_OVERLAY */]: booleanProperty,
|
||||
["github-codeql-extra-queries" /* EXTRA_QUERIES */]: stringProperty,
|
||||
["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */]: booleanProperty,
|
||||
@@ -148080,6 +148084,12 @@ function parseBooleanRepositoryProperty(name, value, logger) {
|
||||
function parseStringRepositoryProperty(_name, value) {
|
||||
return value;
|
||||
}
|
||||
function parseNonEmptyStringRepositoryProperty(_name, value) {
|
||||
if (value.trim().length === 0) {
|
||||
return void 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
var KNOWN_REPOSITORY_PROPERTY_NAMES = new Set(
|
||||
Object.values(RepositoryPropertyName)
|
||||
);
|
||||
|
||||
@@ -176,6 +176,30 @@ test.serial(
|
||||
},
|
||||
);
|
||||
|
||||
test.serial(
|
||||
"loadPropertiesFromApi returns undefined if non-empty string property is empty",
|
||||
async (t) => {
|
||||
sinon.stub(api, "getRepositoryProperties").resolves({
|
||||
headers: {},
|
||||
status: 200,
|
||||
url: "",
|
||||
data: [{ property_name: "github-codeql-config-file", value: "" }],
|
||||
});
|
||||
const logger = getRunnerLogger(true);
|
||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||
|
||||
// `github-codeql-config-file` is a `nonEmptyStringProperty`, so we expect to
|
||||
// get `undefined` instead of the empty string
|
||||
const response = await properties.loadPropertiesFromApi(
|
||||
logger,
|
||||
mockRepositoryNwo,
|
||||
);
|
||||
t.deepEqual(response, {
|
||||
"github-codeql-config-file": undefined,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test.serial(
|
||||
"loadPropertiesFromApi warns if boolean property has unexpected value",
|
||||
async (t) => {
|
||||
|
||||
@@ -22,16 +22,21 @@ export enum RepositoryPropertyName {
|
||||
|
||||
/** Parsed types of the known repository properties. */
|
||||
export type AllRepositoryProperties = {
|
||||
[RepositoryPropertyName.CONFIG_FILE]: string;
|
||||
[RepositoryPropertyName.CONFIG_FILE]: string | undefined;
|
||||
[RepositoryPropertyName.DISABLE_OVERLAY]: boolean;
|
||||
[RepositoryPropertyName.EXTRA_QUERIES]: string;
|
||||
[RepositoryPropertyName.FILE_COVERAGE_ON_PRS]: boolean;
|
||||
[RepositoryPropertyName.TOOLS]: string;
|
||||
};
|
||||
|
||||
/** The subset of known repository properties which are of type `string`. */
|
||||
/**
|
||||
* The subset of known repository properties which are of type `string`.
|
||||
* We tolerate `undefined` for `string`-typed properties that are empty.
|
||||
*/
|
||||
export type StringRepositoryPropertyNames = keyof {
|
||||
[K in keyof AllRepositoryProperties as AllRepositoryProperties[K] extends string
|
||||
[K in keyof AllRepositoryProperties as AllRepositoryProperties[K] extends
|
||||
| string
|
||||
| undefined
|
||||
? K
|
||||
: never]: AllRepositoryProperties[K];
|
||||
};
|
||||
@@ -79,6 +84,12 @@ const stringProperty = {
|
||||
parse: parseStringRepositoryProperty,
|
||||
};
|
||||
|
||||
/** A repository property that we expect to contain a non-empty string value. */
|
||||
const nonEmptyStringProperty = {
|
||||
...stringProperty,
|
||||
parse: parseNonEmptyStringRepositoryProperty,
|
||||
};
|
||||
|
||||
/** A repository property that we expect to contain a boolean value. */
|
||||
const booleanProperty = {
|
||||
// The value from the API should come as a string, which we then parse into a boolean.
|
||||
@@ -90,7 +101,7 @@ const booleanProperty = {
|
||||
const repositoryPropertyParsers: {
|
||||
[K in RepositoryPropertyName]: PropertyInfo<K>;
|
||||
} = {
|
||||
[RepositoryPropertyName.CONFIG_FILE]: stringProperty,
|
||||
[RepositoryPropertyName.CONFIG_FILE]: nonEmptyStringProperty,
|
||||
[RepositoryPropertyName.DISABLE_OVERLAY]: booleanProperty,
|
||||
[RepositoryPropertyName.EXTRA_QUERIES]: stringProperty,
|
||||
[RepositoryPropertyName.FILE_COVERAGE_ON_PRS]: booleanProperty,
|
||||
@@ -235,6 +246,17 @@ function parseStringRepositoryProperty(_name: string, value: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Parse a non-empty string repository property. */
|
||||
function parseNonEmptyStringRepositoryProperty(
|
||||
_name: string,
|
||||
value: string,
|
||||
): string | undefined {
|
||||
if (value.trim().length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Set of known repository property names, for fast lookups. */
|
||||
const KNOWN_REPOSITORY_PROPERTY_NAMES = new Set<string>(
|
||||
Object.values(RepositoryPropertyName),
|
||||
|
||||
Reference in New Issue
Block a user