99// Requirements
1010//-----------------------------------------------------------------------------
1111
12- const { Probot , run } = require ( "probot" ) ;
12+ const { run } = require ( "probot" ) ;
1313const plugins = require ( "./plugins" ) ;
1414
1515//-----------------------------------------------------------------------------
1616// Type Definitions
1717//-----------------------------------------------------------------------------
1818
1919/** @typedef {import("probot").Probot } Probot */
20- /** @typedef {import("probot").Context<any> } ProbotContext */
21- /** @typedef {import("probot").ProbotOctokit } ProbotOctokit */
2220
2321//-----------------------------------------------------------------------------
2422// Main
2523//-----------------------------------------------------------------------------
2624
27- if ( ! process . env . SECRET ) {
28- throw new Error ( "Missing 'SECRET' environment variable" ) ;
29- }
30-
31- if ( ! process . env . PRIVATE_KEY ) {
32- throw new Error ( "Missing 'PRIVATE_KEY' environment variable" ) ;
33- }
34-
35- if ( ! process . env . APP_ID ) {
36- throw new Error ( "Missing 'APP_ID' environment variable" ) ;
37- }
38-
39- const port = process . env . PORT || 8000 ;
40- const app = new Probot ( {
41- privateKey : process . env . PRIVATE_KEY ,
42- appId : process . env . APP_ID ,
43- secret : process . env . SECRET ,
44- port
45- } ) ;
46-
4725const enabledPlugins = new Set ( [
4826 "commitMessage" ,
4927 "needsInfo" ,
@@ -52,10 +30,16 @@ const enabledPlugins = new Set([
5230 "wip"
5331] ) ;
5432
55- // load all the enabled plugins from inside plugins folder
56- Object . keys ( plugins )
57- . filter ( pluginId => enabledPlugins . has ( pluginId ) )
58- . forEach ( pluginId => app . load ( plugins [ pluginId ] ) ) ;
33+ /**
34+ * Assign the plugins to the robot.
35+ * @param {Probot } robot The Probot instance.
36+ * @returns {void }
37+ */
38+ function appFn ( robot ) {
39+ Object . keys ( plugins )
40+ . filter ( pluginId => enabledPlugins . has ( pluginId ) )
41+ . forEach ( pluginId => plugins [ pluginId ] ( robot ) ) ;
42+ }
5943
6044// start the server
61- run ( app ) ;
45+ run ( appFn ) ;
0 commit comments