File tree Expand file tree Collapse file tree 5 files changed +106
-0
lines changed Expand file tree Collapse file tree 5 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 1+ const { createNodeMiddleware, createProbot } = require ( "probot" ) ;
2+
3+ const app = require ( "../../../app" ) ;
4+ const probot = createProbot ( {
5+ defaults : {
6+ webhookPath : "/api/github/webhooks" ,
7+ } ,
8+ } ) ;
9+
10+ module . exports = createNodeMiddleware ( app , { probot } ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {import('probot').Probot } app
3+ */
4+ module . exports = ( app ) => {
5+ app . log ( "Yay! The app was loaded!" ) ;
6+
7+ app . on ( "issues.opened" , async ( context ) => {
8+ return context . octokit . issues . createComment (
9+ context . issue ( { body : "Hello, World!" } )
10+ ) ;
11+ } ) ;
12+ } ;
Original file line number Diff line number Diff line change 1+ default_events :
2+ - issues
3+
4+ default_permissions :
5+ issues : write
6+ metadata : read
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7+ < title > Hello from Vercel</ title >
8+ </ head >
9+ < body >
10+ < h1 > Hello from Vercel</ h1 >
11+
12+ < p > Edit this file in < code > public/index.html</ code > </ p >
13+
14+ < p >
15+ Your app receives webhook requests at
16+ < code > POST /api/github/webhooks</ code >
17+ </ p >
18+ </ body >
19+ </ html >
Original file line number Diff line number Diff line change 1+ const { suite } = require ( "uvu" ) ;
2+ const assert = require ( "uvu/assert" ) ;
3+
4+ const nock = require ( "nock" ) ;
5+ nock . disableNetConnect ( ) ;
6+
7+ const { Probot, ProbotOctokit } = require ( "probot" ) ;
8+
9+ const app = require ( "./app" ) ;
10+
11+ /** @type {import('probot').Probot */
12+ let probot ;
13+ const test = suite ( "app" ) ;
14+ test . before . each ( ( ) => {
15+ probot = new Probot ( {
16+ // simple authentication as alternative to appId/privateKey
17+ githubToken : "test" ,
18+ // disable logs
19+ logLevel : "warn" ,
20+ // disable request throttling and retries
21+ Octokit : ProbotOctokit . defaults ( {
22+ throttle : { enabled : false } ,
23+ retry : { enabled : false } ,
24+ } ) ,
25+ } ) ;
26+ probot . load ( app ) ;
27+ } ) ;
28+
29+ test ( "recieves issues.opened event" , async function ( ) {
30+ const mock = nock ( "https://api.github.com" )
31+ // create new check run
32+ . post ( "/repos/probot/example-vercel/issues/1/comments" , ( requestBody ) => {
33+ assert . equal ( requestBody , { body : "Hello, World!" } ) ;
34+
35+ return true ;
36+ } )
37+ . reply ( 201 , { } ) ;
38+
39+ await probot . receive ( {
40+ name : "issues" ,
41+ id : "1" ,
42+ payload : {
43+ action : "opened" ,
44+ repository : {
45+ owner : {
46+ login : "probot" ,
47+ } ,
48+ name : "example-vercel" ,
49+ } ,
50+ issue : {
51+ number : 1 ,
52+ } ,
53+ } ,
54+ } ) ;
55+
56+ assert . equal ( mock . activeMocks ( ) , [ ] ) ;
57+ } ) ;
58+
59+ test . run ( ) ;
You can’t perform that action at this time.
0 commit comments