Skip to content

Commit 41186e8

Browse files
authored
New: Add new issues to triage project (#143)
1 parent 774d8a9 commit 41186e8

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

Diff for: src/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const bot = probot.createProbot({
2828
id: process.env.APP_ID
2929
});
3030
const enabledPlugins = new Set([
31+
"addToTriageProject",
3132
"autoCloser",
3233
"commitMessage",
3334
"issueArchiver",

Diff for: src/constants.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @fileoverview Shared constants for the bot
3+
* @author Nicholas C. Zakas
4+
*/
5+
6+
"use strict";
7+
8+
module.exports = {
9+
NEEDS_TRIAGE_COLUMN_ID: 11153344
10+
};

Diff for: src/plugins/add-to-triage-project/index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @fileoverview Adds a newly opened issue to the Triage project
3+
* @author Nicholas C. Zakas
4+
*/
5+
6+
"use strict";
7+
8+
const { NEEDS_TRIAGE_COLUMN_ID } = require("../../constants");
9+
10+
/**
11+
* Adds the issue to the triage project.
12+
* @param {Context} context Probot webhook event context
13+
* @returns {Promise<void>} A Promise that fulfills when the action is complete
14+
* @private
15+
*/
16+
async function triage(context) {
17+
18+
const issue = context.payload.issue;
19+
20+
await context.github.projects.createCard({
21+
column_id: NEEDS_TRIAGE_COLUMN_ID,
22+
content_id: issue.id,
23+
content_type: "Issue"
24+
});
25+
}
26+
27+
module.exports = robot => {
28+
robot.on("issues.opened", triage);
29+
};

Diff for: src/plugins/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
module.exports = {
16+
addToTriageProject: require("./add-to-triage-project"),
1617
autoCloser: require("./auto-closer"),
1718
checkUnitTest: require("./check-unit-test"),
1819
commitMessage: require("./commit-message"),

Diff for: tests/plugins/add-to-triage-project/index.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"use strict";
2+
3+
const { addToTriageProject } = require("../../../src/plugins/index");
4+
const nock = require("nock");
5+
const { Application } = require("probot");
6+
const { NEEDS_TRIAGE_COLUMN_ID } = require("../../../src/constants");
7+
const GitHubApi = require("@octokit/rest");
8+
9+
describe("add-to-triage-project", () => {
10+
let bot = null;
11+
12+
beforeAll(() => {
13+
bot = new Application({
14+
id: "test",
15+
cert: "test",
16+
cache: {
17+
wrap: () => Promise.resolve({ data: { token: "test" } })
18+
}
19+
});
20+
bot.auth = () => new GitHubApi();
21+
addToTriageProject(bot);
22+
});
23+
24+
afterEach(() => {
25+
nock.cleanAll();
26+
});
27+
28+
describe("issue opened", () => {
29+
test("Adds the issue to the projectt", async() => {
30+
const addIssueToTriageProject = nock("https://api.github.com")
31+
.post(`/projects/columns/${NEEDS_TRIAGE_COLUMN_ID}/cards`, body => {
32+
expect(body).toEqual({
33+
content_id: 1234,
34+
content_type: "Issue"
35+
});
36+
return true;
37+
})
38+
.reply(200);
39+
40+
await bot.receive({
41+
name: "issues",
42+
payload: {
43+
action: "opened",
44+
installation: {
45+
id: 1
46+
},
47+
issue: {
48+
labels: [],
49+
number: 1,
50+
id: 1234
51+
},
52+
repository: {
53+
name: "repo-test",
54+
owner: {
55+
login: "test"
56+
}
57+
}
58+
}
59+
});
60+
61+
expect(addIssueToTriageProject.isDone()).toBeTruthy();
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)