Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Naka Masato committed Oct 22, 2020
1 parent b101774 commit 8fc40c7
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ async function run() {
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);
}
}

Expand Down Expand Up @@ -91,10 +89,10 @@ function getPrNumber(): number | undefined {
return pullRequest.number;
}

function getPrTitle(): string | undefined {
function getPrTitle(): string {
const pullRequest = github.context.payload.pull_request;
if (!pullRequest) {
return undefined;
return '';
}

return pullRequest.title;
Expand Down Expand Up @@ -200,11 +198,9 @@ function getLabelTitleRegexMapFromObject(
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)`
Expand Down Expand Up @@ -245,6 +241,18 @@ function checkGlobs(
return false;
}

function checkRegexs(
prTitle: string,
regexs: RegExp[]
): boolean {
for (const regex of regexs) {
if (regex.test(prTitle)) {
return true;
}
}
return false;
}

function isMatch(changedFile: string, matchers: IMinimatch[]): boolean {
core.debug(` matching patterns against file ${changedFile}`);
for (const matcher of matchers) {
Expand Down

0 comments on commit 8fc40c7

Please sign in to comment.