Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,24 @@ export const run = async function (payload, commenter, args) {
.match(/".*?"/g)
.map((string) => string.replaceAll('"', ""));

// Get all specific area labels
const specificLabels = labels.filter(
(label) =>
label.includes("area: ") && label.includes("(") && label.includes(")"),
);

const generalLabels = new Set();
// Add general labels from every specific label
for (const label of specificLabels) {
generalLabels.add(label.slice(0, Math.max(0, label.indexOf(" ("))));
}

const alreadyAdded = labels.filter((label) => issueLabels.has(label));
const rejected = labels.filter((label) => !repoLabels.has(label));
const addLabels = labels.filter(

// Add general lables to the input lables and filter
const combinedLabels = new Set([...labels, ...generalLabels]);
const addLabels = [...combinedLabels].filter(
(label) => repoLabels.has(label) && !issueLabels.has(label),
);

Expand Down
26 changes: 25 additions & 1 deletion test/unit/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ const payload = {
},
};

const repoLabels = [{ name: "test" }, { name: "test2" }, { name: "bug" }];
const repoLabels = [
{ name: "test" },
{ name: "test2" },
{ name: "bug" },
{ name: "area: test (specific)" },
{ name: "area: test" },
];

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

scope.done();
});

test("Add general label when specific label is added", async () => {
client.cfg.issues.commands.label.self = false;
const commenter = "octocat";
const args = '"area: test (specific)"';

const scope = nock("https://api.github.com")
.get("/repos/zulip/zulipbot/labels")
.reply(200, repoLabels)
.post("/repos/zulip/zulipbot/issues/69/labels", {
labels: ["area: test (specific)", "area: test"],
})
.reply(200);

await add.run.call(client, payload, commenter, args);

scope.done();
});