diff --git a/lib/main.js b/lib/main.js index b80eb4e..8ca384f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -37,14 +37,11 @@ function run() { // Load the existing labels the issue has const labels = getLabels(client, issue_number); // Load our regex rules from the configuration path - const labelGlobs = yield getLabelGlobs(client, configPath); + const labelRegexes = yield getLabelRegexes(client, configPath); const addLabel = []; const removeLabelItems = []; - for (const [label, globs] of labelGlobs.entries()) { - console.debug(`processing ${label}`); - console.debug(`for globs ${globs[0]}`); - if (checkGlobs(issue_body, globs)) { - console.log(`Queue label for addition: ${label}`); + for (const [label, globs] of labelRegexes.entries()) { + if (checkRegexes(issue_body, globs)) { addLabel.push(label); } else { @@ -80,13 +77,13 @@ function getIssueBody() { } return issue.body; } -function getLabelGlobs(client, configurationPath) { +function getLabelRegexes(client, configurationPath) { return __awaiter(this, void 0, void 0, function* () { const configurationContent = yield fetchContent(client, configurationPath); // loads (hopefully) a `{[label:string]: string | string[]}`, but is `any`: const configObject = yaml.safeLoad(configurationContent); // transform `any` => `Map` or throw if yaml is malformed: - return getLabelGlobMapFromObject(configObject); + return getLabelRegexesMapFromObject(configObject); }); } // Load the configuration file @@ -106,32 +103,28 @@ function fetchContent(client, repoPath) { return Buffer.from(data.content, 'base64').toString('utf8'); }); } -function getLabelGlobMapFromObject(configObject) { - const labelGlobs = new Map(); +function getLabelRegexesMapFromObject(configObject) { + const labelRegexes = new Map(); for (const label in configObject) { if (typeof configObject[label] === 'string') { - labelGlobs.set(label, [configObject[label]]); + labelRegexes.set(label, [configObject[label]]); } else if (Array.isArray(configObject[label])) { - labelGlobs.set(label, configObject[label]); + labelRegexes.set(label, configObject[label]); } else { - throw Error(`found unexpected type for label ${label} (should be string or array of globs)`); + throw Error(`found unexpected type for label ${label} (should be string or array of regex)`); } } - return labelGlobs; + return labelRegexes; } -function checkGlobs(issue_body, globs) { - console.log(issue_body); +function checkRegexes(issue_body, regexes) { // If several regex entries are provided we require all of them to match for the label to be applied. - for (const glob of globs) { - console.log(` checking pattern ${glob}`); - const found = issue_body.match(glob); + for (const regEx of regexes) { + const found = issue_body.match(regEx); if (!found) { - console.log(`Didn't find pattern`); return false; } - console.log(`Found patterns ${found}`); } return true; } @@ -148,12 +141,9 @@ function getLabels(client, issue_number) { process.exit(1); } const labels = []; - console.log(data); for (let i = 0; i < Object.keys(data).length; i++) { - console.log(`label is ${data[i].name}`); labels.push(data[i].name); } - console.log("done"); return labels; }); }