Skip to content
Merged
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
Only validate property value type if we care about the property
  • Loading branch information
mbg committed Mar 9, 2026
commit 9c75a5f60ced7a336710741b803a179f74860d09
10 changes: 5 additions & 5 deletions lib/init-action.js

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

23 changes: 23 additions & 0 deletions src/feature-flags/properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ test.serial(
},
);

test.serial(
"loadPropertiesFromApi does not throw for unexpected value types of unknown properties",
async (t) => {
sinon.stub(api, "getRepositoryProperties").resolves({
headers: {},
status: 200,
url: "",
data: [{ property_name: "not-used-by-us", value: { foo: "bar" } }],
});
const logger = getRunnerLogger(true);
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
await t.notThrowsAsync(
properties.loadPropertiesFromApi(
{
type: util.GitHubVariant.DOTCOM,
},
logger,
mockRepositoryNwo,
),
);
},
);

test.serial(
"loadPropertiesFromApi returns empty object if on GHES",
async (t) => {
Expand Down
14 changes: 8 additions & 6 deletions src/feature-flags/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ export async function loadPropertiesFromApi(
);
}

if (typeof property.value !== "string") {
throw new Error(
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`,
);
}

if (isKnownPropertyName(property.property_name)) {
// Only validate the type of `value` if this is a property we care about, to avoid throwing
// on unrelated properties that may use representations we do not support.
if (typeof property.value !== "string") {
throw new Error(
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`,
);
}

setProperty(properties, property.property_name, property.value, logger);
}
}
Expand Down