Skip to content

Commit b9bb1f9

Browse files
authored
fix keyword matching (#3431)
* add a crash template, and remove redundancies * merge conflicts * fix keyword matching bug
1 parent e070ef9 commit b9bb1f9

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

.github/scripts/issue_labelAssign.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,38 @@ module.exports = async function ({github, context}, keywords) {
2424
assigneeNames.push(assignee.login);
2525
}
2626

27-
// test if module keyword is in issue body
28-
const regexModule1 = "### (JASP Module|Is your feature request related to a JASP module\\?)\\s+,*.*(";
29-
const regexModule2 = ").*\\s+###";
30-
for (const words of keywords.modules) {
31-
// create the regex to match with, case insensitive
32-
var regex = new RegExp(regexModule1 + words[0] + regexModule2, "i");
33-
let found = regex.test(body);
27+
// Extract the answer(s) to the module question
28+
const match = body.match(/### (JASP Module|Is your feature request related to a JASP module\?)\s*\n+(.+?)\s*(\n|$)/i);
3429

35-
// label and assign someone
36-
if (found) {
37-
// checks if there is actually a label specified in the keywords
38-
if (words[1].length > 0) {
39-
github.rest.issues.addLabels({
40-
issue_number: context.issue.number,
41-
owner: context.repo.owner,
42-
repo: context.repo.repo,
43-
labels: [
44-
words[1]
45-
]
46-
});
47-
}
48-
// checks if there is actually an assignee specified in the keywords
49-
if (words[2].length > 0) {
50-
github.rest.issues.addAssignees({
51-
issue_number: context.issue.number,
52-
owner: context.repo.owner,
53-
repo: context.repo.repo,
54-
assignees: [
55-
words[2]
56-
]
57-
});
30+
if (match && match[2]) {
31+
const rawAnswers = match[2].split(/[,;\n]/).map(ans => ans.trim().toLowerCase());
32+
const uniqueAnswers = [...new Set(rawAnswers)];
33+
34+
for (const [keyword, label, assignee] of keywords.modules) {
35+
const keywordLower = keyword.toLowerCase();
36+
37+
if (uniqueAnswers.includes(keywordLower)) {
38+
if (label) {
39+
await github.rest.issues.addLabels({
40+
issue_number: context.issue.number,
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
labels: [label]
44+
});
45+
}
46+
if (assignee) {
47+
await github.rest.issues.addAssignees({
48+
issue_number: context.issue.number,
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
assignees: [assignee]
52+
});
53+
}
5854
}
5955
}
6056
}
6157

58+
6259
const regexOS1 = "\\#\\#\\# What OS are you seeing the problem on\\?\\s+,*.*(";
6360
const regexOS2 = ").*\\s+\\#\\#\\#";
6461
// test if OS keyword is in issue body

0 commit comments

Comments
 (0)