4.0 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a1d9f98e819ed70a0e994df | Challenge 333: Issue Triage 2 | 28 | challenge-333 |
--description--
Given an issue title and an array of current labels, return an updated array of labels based on the following rules:
If the issue doesn't have any labels, add:
"bug"and"needs triage"if the title contains"error"or"bug""enhancement"and"discussing"if the title contains"feature"or"add"
Otherwise, if the given labels contain:
"needs triage"and the title contains"simple"or"easy", remove"needs triage"and add"good first issue""discussing"and the title contains"planned"or"next", remove"discussing"and add"on the roadmap"- Otherwise, if
"needs triage"or"discussing"is present, remove it and add"help wanted"
If the title contains:
"security", add a"critical"label
--hints--
triageIssue("app crashes with error", []) should return ["bug", "needs triage"].
assert.deepEqual(triageIssue("app crashes with error", []).sort(), ["bug", "needs triage"].sort());
triageIssue("app crashes with error", ["bug", "needs triage"]) should return ["bug", "help wanted"].
assert.deepEqual(triageIssue("app crashes with error", ["bug", "needs triage"]).sort(), ["bug", "help wanted"].sort());
triageIssue("add dark mode", []) should return ["enhancement", "discussing"].
assert.deepEqual(triageIssue("add dark mode", []).sort(), ["enhancement", "discussing"].sort());
triageIssue("add dark mode", ["enhancement", "discussing"]) should return ["enhancement", "help wanted"].
assert.deepEqual(triageIssue("add dark mode", ["enhancement", "discussing"]).sort(), ["enhancement", "help wanted"].sort());
triageIssue("xss security bug", []) should return ["bug", "needs triage", "critical"].
assert.deepEqual(triageIssue("xss security bug", []).sort(), ["bug", "needs triage", "critical"].sort());
triageIssue("security vulnerability in auth", []) should return ["critical"].
assert.deepEqual(triageIssue("security vulnerability in auth", []).sort(), ["critical"].sort());
triageIssue("easy a11y fix", ["bug", "needs triage"]) should return ["bug", "good first issue"].
assert.deepEqual(triageIssue("easy a11y fix", ["bug", "needs triage"]).sort(), ["bug", "good first issue"].sort());
triageIssue("planned api migration", ["enhancement", "discussing"]) should return ["enhancement", "on the roadmap"].
assert.deepEqual(triageIssue("planned api migration", ["enhancement", "discussing"]).sort(), ["enhancement", "on the roadmap"].sort());
triageIssue("improve security", ["enhancement", "discussing"]) should return ["enhancement", "help wanted", "critical"].
assert.deepEqual(triageIssue("improve security", ["enhancement", "discussing"]).sort(), ["enhancement", "help wanted", "critical"].sort());
--seed--
--seed-contents--
function triageIssue(title, labels) {
return title;
}
--solutions--
function triageIssue(title, labels) {
const result = [...labels];
const t = title.toLowerCase();
const has = label => result.includes(label);
const add = label => { if (!has(label)) result.push(label); };
const remove = label => { const i = result.indexOf(label); if (i > -1) result.splice(i, 1); };
if (result.length === 0) {
if (t.includes("error") || t.includes("bug")) {
add("bug"); add("needs triage");
} else if (t.includes("feature") || t.includes("add")) {
add("enhancement"); add("discussing");
}
} else {
if (has("needs triage") && (t.includes("simple") || t.includes("easy"))) {
remove("needs triage"); add("good first issue");
} else if (has("discussing") && (t.includes("planned") || t.includes("next"))) {
remove("discussing"); add("on the roadmap");
} else if (has("needs triage") || has("discussing")) {
remove("needs triage"); remove("discussing"); add("help wanted");
}
}
if (t.includes("security")) {
add("critical");
}
return result;
}