Skip to content

Commit bcf0dcc

Browse files
committed
areaLabel: Edit issue instead of posting comment.
GitHub sends all subscribed users a notification for new comments. So spamming subscribers with bot comments is annoying. Fixes #180.
1 parent 39b257e commit bcf0dcc

File tree

2 files changed

+15
-43
lines changed

2 files changed

+15
-43
lines changed

config/templates/areaLabelAddition.md

-3
This file was deleted.

src/events/responses/areaLabel.js

+15-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const referenced = [];
2-
31
exports.run = async function(issue, repo, label) {
42
const areaLabel = label.name;
53
const number = issue.number;
@@ -17,43 +15,20 @@ exports.run = async function(issue, repo, label) {
1715
const uniqueTeams = this.util.deduplicate(labelTeams);
1816

1917
const areaTeams = `@${repoOwner}/${uniqueTeams.join(`, @${repoOwner}/`)}`;
20-
const references = issueAreaLabels.join("\", \"");
21-
22-
const payload = issue.pull_request ? "pull request" : "issue";
23-
const labelSize = labelTeams.length === 1 ? "label" : "labels";
24-
const template = this.templates.get("areaLabelAddition");
25-
26-
const comment = template.format({
27-
teams: areaTeams, refs: `"${references}"`, labels: labelSize,
28-
payload: payload
29-
});
30-
31-
const comments = await template.getComments({
32-
owner: repoOwner, repo: repoName, number: number
33-
});
34-
35-
const tag = `${repoOwner}/${repoName}#${number}`;
36-
37-
if (comments.length) {
38-
const id = comments[0].id;
39-
if (issueAreaLabels.length) {
40-
this.issues.editComment({
41-
owner: repoOwner, repo: repoName, comment_id: id, body: comment
42-
});
43-
} else {
44-
this.issues.deleteComment({
45-
owner: repoOwner, repo: repoName, comment_id: id
46-
});
47-
}
48-
} else if (!referenced.includes(tag) && issueAreaLabels.length) {
49-
this.issues.createComment({
50-
owner: repoOwner, repo: repoName, number: number, body: comment
51-
});
52-
53-
// Ignore labels added in bulk
54-
referenced.push(tag);
55-
setTimeout(() => {
56-
referenced.splice(referenced.indexOf(tag), 1);
57-
}, 1000);
18+
19+
const prefix = "CC by @zulipbot: ";
20+
21+
const updatedIssue = {
22+
owner: repoOwner, repo: repoName, issue_number: number, body: issue.body
23+
};
24+
25+
const pattern = new RegExp(`${prefix}.$`, "mg");
26+
27+
if (issue.description.includes(prefix)) {
28+
issue.body = issue.body.replace(pattern, `${prefix}${areaTeams}`);
29+
} else {
30+
issue.body += `\n\n${prefix}${areaTeams}`;
5831
}
32+
33+
this.issues.update(updatedIssue);
5934
};

0 commit comments

Comments
 (0)