Skip to content

Commit 8fc40c7

Browse files
author
Naka Masato
committed
fix
1 parent b101774 commit 8fc40c7

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/main.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ async function run() {
4242
configPath
4343
);
4444
for (const [label, regexs] of labelTitleRegex.entries()) {
45-
core.debug(`[labelTitleRegex] processing ${label}`);
46-
for (const regex of regexs) {
47-
core.info(`label: ${label}, regex: ${regex}`);
48-
if (prTitle != undefined && regex.test(prTitle)) {
49-
core.info(`in`);
50-
labels.push(label);
51-
}
45+
core.debug(`processing ${label}`);
46+
if (checkRegexs(prTitle, regexs)) {
47+
labels.push(label);
48+
} else if (pullRequest.labels.find(l => l.name === label)) {
49+
labelsToRemove.push(label);
5250
}
5351
}
5452

@@ -91,10 +89,10 @@ function getPrNumber(): number | undefined {
9189
return pullRequest.number;
9290
}
9391

94-
function getPrTitle(): string | undefined {
92+
function getPrTitle(): string {
9593
const pullRequest = github.context.payload.pull_request;
9694
if (!pullRequest) {
97-
return undefined;
95+
return '';
9896
}
9997

10098
return pullRequest.title;
@@ -200,11 +198,9 @@ function getLabelTitleRegexMapFromObject(
200198
for (const label in configObject["title"]) {
201199
const val = configObject["title"][label];
202200
if (typeof val === "string") {
203-
titleRegexs.set(label, [new RegExp(val)]);
204-
core.info(`label: ${label}, ${val}, ${titleRegexs}`)
201+
titleRegexs.set(label, [new RegExp(val, 'i')]);
205202
} else if (val instanceof Array) {
206-
core.info(`label: ${label}, ${val}`)
207-
titleRegexs.set(label, val.map(regexStr => new RegExp(regexStr)) );
203+
titleRegexs.set(label, val.map(regexStr => new RegExp(regexStr, 'i')) );
208204
} else {
209205
throw Error(
210206
`found unexpected type for label ${label} (should be string or array of regex)`
@@ -245,6 +241,18 @@ function checkGlobs(
245241
return false;
246242
}
247243

244+
function checkRegexs(
245+
prTitle: string,
246+
regexs: RegExp[]
247+
): boolean {
248+
for (const regex of regexs) {
249+
if (regex.test(prTitle)) {
250+
return true;
251+
}
252+
}
253+
return false;
254+
}
255+
248256
function isMatch(changedFile: string, matchers: IMinimatch[]): boolean {
249257
core.debug(` matching patterns against file ${changedFile}`);
250258
for (const matcher of matchers) {

0 commit comments

Comments
 (0)