diff --git a/lib/init-action.js b/lib/init-action.js index a047977e2..6cf274d04 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -104434,12 +104434,12 @@ async function loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) { `Expected repository property object to have a 'property_name', but got: ${JSON.stringify(property)}` ); } - 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)) { + if (typeof property.value !== "string") { + throw new Error( + `Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}` + ); + } setProperty2(properties, property.property_name, property.value, logger); } } diff --git a/src/feature-flags/properties.test.ts b/src/feature-flags/properties.test.ts index afe936932..396780685 100644 --- a/src/feature-flags/properties.test.ts +++ b/src/feature-flags/properties.test.ts @@ -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) => { diff --git a/src/feature-flags/properties.ts b/src/feature-flags/properties.ts index e98a41426..64459dd5c 100644 --- a/src/feature-flags/properties.ts +++ b/src/feature-flags/properties.ts @@ -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); } }