Skip to content

Commit 2623eac

Browse files
committed
add command: Add general labels when specific labels are added.
This adds the relevant general area labels whenever a specific area label is added with the "add" command. adds a test case for this feature Co-authored-by: Skyler Simpson Fixes #29739.
1 parent dd069d3 commit 2623eac

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/commands/add.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,24 @@ export const run = async function (payload, commenter, args) {
2323
.match(/".*?"/g)
2424
.map((string) => string.replaceAll('"', ""));
2525

26+
// Get all specific area labels
27+
const specificLabels = labels.filter(
28+
(label) =>
29+
label.includes("area: ") && label.includes("(") && label.includes(")"),
30+
);
31+
32+
const generalLabels = new Set();
33+
// Add general labels from every specific label
34+
for (const label of specificLabels) {
35+
generalLabels.add(label.slice(0, Math.max(0, label.indexOf(" ("))));
36+
}
37+
2638
const alreadyAdded = labels.filter((label) => issueLabels.has(label));
2739
const rejected = labels.filter((label) => !repoLabels.has(label));
28-
const addLabels = labels.filter(
40+
41+
// Add general lables to the input lables and filter
42+
const combinedLabels = new Set([...labels, ...generalLabels]);
43+
const addLabels = [...combinedLabels].filter(
2944
(label) => repoLabels.has(label) && !issueLabels.has(label),
3045
);
3146

test/unit/commands/add.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ const payload = {
2121
},
2222
};
2323

24-
const repoLabels = [{ name: "test" }, { name: "test2" }, { name: "bug" }];
24+
const repoLabels = [
25+
{ name: "test" },
26+
{ name: "test2" },
27+
{ name: "bug" },
28+
{ name: "area: test (specific)" },
29+
{ name: "area: test" },
30+
];
2531

2632
const template = client.templates.get("labelError");
2733
template.content = "{labels} {labelList} {exist} {beState} {action} {type}.";
@@ -147,3 +153,21 @@ test("Add appropriate labels and reject already added labels", async () => {
147153

148154
scope.done();
149155
});
156+
157+
test("Add general label when specific label is added", async () => {
158+
client.cfg.issues.commands.label.self = false;
159+
const commenter = "octocat";
160+
const args = '"area: test (specific)"';
161+
162+
const scope = nock("https://api.github.com")
163+
.get("/repos/zulip/zulipbot/labels")
164+
.reply(200, repoLabels)
165+
.post("/repos/zulip/zulipbot/issues/69/labels", {
166+
labels: ["area: test (specific)", "area: test"],
167+
})
168+
.reply(200);
169+
170+
await add.run.call(client, payload, commenter, args);
171+
172+
scope.done();
173+
});

0 commit comments

Comments
 (0)