Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add nonEmptyStringProperty
  • Loading branch information
mbg committed Jul 28, 2026
commit e6801c5a55a185b64d872580d63f6f66785197cb
12 changes: 11 additions & 1 deletion lib/entry-points.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/feature-flags/properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
30 changes: 26 additions & 4 deletions src/feature-flags/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
Expand Down Expand Up @@ -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.
Expand All @@ -90,7 +101,7 @@ const booleanProperty = {
const repositoryPropertyParsers: {
[K in RepositoryPropertyName]: PropertyInfo<K>;
} = {
[RepositoryPropertyName.CONFIG_FILE]: stringProperty,
[RepositoryPropertyName.CONFIG_FILE]: nonEmptyStringProperty,
Comment thread
mbg marked this conversation as resolved.
Resolved
[RepositoryPropertyName.DISABLE_OVERLAY]: booleanProperty,
[RepositoryPropertyName.EXTRA_QUERIES]: stringProperty,
[RepositoryPropertyName.FILE_COVERAGE_ON_PRS]: booleanProperty,
Expand Down Expand Up @@ -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),
Expand Down