File tree 5 files changed +105
-0
lines changed
tests/plugins/add-to-triage-project
5 files changed +105
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ const bot = probot.createProbot({
28
28
id : process . env . APP_ID
29
29
} ) ;
30
30
const enabledPlugins = new Set ( [
31
+ "addToTriageProject" ,
31
32
"autoCloser" ,
32
33
"commitMessage" ,
33
34
"issueArchiver" ,
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 13
13
*/
14
14
15
15
module . exports = {
16
+ addToTriageProject : require ( "./add-to-triage-project" ) ,
16
17
autoCloser : require ( "./auto-closer" ) ,
17
18
checkUnitTest : require ( "./check-unit-test" ) ,
18
19
commitMessage : require ( "./commit-message" ) ,
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments