From 2116d711159f3235b67a68fd9b393aed1906aaf5 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 23 Oct 2020 01:16:10 +0900 Subject: [PATCH] fix --- dist/index.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index c3b64461d..e32197039 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14558,13 +14558,12 @@ function run() { // add label based on title const labelTitleRegex = yield getLabelTitleRegex(client, configPath); for (const [label, regexs] of labelTitleRegex.entries()) { - core.debug(`[labelTitleRegex] processing ${label}`); - for (const regex of regexs) { - core.info(`label: ${label}, regex: ${regex}`); - if (prTitle != undefined && regex.test(prTitle)) { - core.info(`in`); - labels.push(label); - } + core.debug(`processing ${label}`); + if (checkRegexs(prTitle, regexs)) { + labels.push(label); + } + else if (pullRequest.labels.find(l => l.name === label)) { + labelsToRemove.push(label); } } // add label based on changed files @@ -14603,7 +14602,7 @@ function getPrNumber() { function getPrTitle() { const pullRequest = github.context.payload.pull_request; if (!pullRequest) { - return undefined; + return ''; } return pullRequest.title; } @@ -14679,12 +14678,10 @@ function getLabelTitleRegexMapFromObject(configObject) { for (const label in configObject["title"]) { const val = configObject["title"][label]; if (typeof val === "string") { - titleRegexs.set(label, [new RegExp(val)]); - core.info(`label: ${label}, ${val}, ${titleRegexs}`); + titleRegexs.set(label, [new RegExp(val, 'i')]); } else if (val instanceof Array) { - core.info(`label: ${label}, ${val}`); - titleRegexs.set(label, val.map(regexStr => new RegExp(regexStr))); + titleRegexs.set(label, val.map(regexStr => new RegExp(regexStr, 'i'))); } else { throw Error(`found unexpected type for label ${label} (should be string or array of regex)`); @@ -14715,6 +14712,14 @@ function checkGlobs(changedFiles, globs) { } return false; } +function checkRegexs(prTitle, regexs) { + for (const regex of regexs) { + if (regex.test(prTitle)) { + return true; + } + } + return false; +} function isMatch(changedFile, matchers) { core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) {