From e4486e9ed90ae58e001e6ff4fda387dbd5d5a524 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 18 Mar 2023 14:51:39 -0400 Subject: [PATCH] Throw an error if the config is the wrong type --- src/labeler.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/labeler.ts b/src/labeler.ts index aecc58f8..4d9c7698 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -130,20 +130,22 @@ async function fetchContent( function getLabelConfigMapFromObject( configObject: any ): Map { - const labelGlobs: Map = new Map(); + const labelMap: Map = new Map(); for (const label in configObject) { - if (typeof configObject[label] === 'string') { - labelGlobs.set(label, [configObject[label]]); - } else if (configObject[label] instanceof Array) { - labelGlobs.set(label, configObject[label]); - } else { + const configOptions = configObject[label]; + if ( + !Array.isArray(configOptions) || + !configOptions.every(opts => typeof opts === 'object') + ) { throw Error( - `found unexpected type for label ${label} (should be string or array of globs)` + `found unexpected type for label ${label} (should be array of config options)` ); } + + labelMap.set(label, configOptions); } - return labelGlobs; + return labelMap; } function toChangedFilesMatchConfig(config: any): ChangedFilesMatchConfig {