-
Notifications
You must be signed in to change notification settings - Fork 42
/
configure.js
94 lines (82 loc) · 2.24 KB
/
configure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const bodyParser = require("body-parser");
const debug = require("debug")("action-dashboard:configure");
const express = require("express");
const path = require("path");
const Actions = require("./actions");
const GitHub = require("./github");
const Routes = require("./routes");
const RunStatus = require("./runstatus");
const WebHooks = require("./webhooks");
const baseDir = path.basename(process.cwd());
// Handle when server is started from vue-cli vs root
if (baseDir === "client") {
debug("started from vue-cli");
require("dotenv").config({ path: path.resolve(process.cwd(), "../.env") });
}
// Handle when server is started from
else {
debug("started from index.js");
require("dotenv").config();
}
debug("env", process.env);
const {
PORT = 8080,
LOOKBACK_DAYS = 7,
GITHUB_APPID,
GITHUB_APP_CLIENTID,
GITHUB_APP_CLIENTSECRET,
GITHUB_APP_INSTALLATIONID,
GITHUB_APP_WEBHOOK_PORT = 8081,
GITHUB_APP_WEBHOOK_SECRET,
GITHUB_APP_WEBHOOK_PATH = "/",
GITHUB_ORG,
GITHUB_USERNAME,
} = process.env;
// Handles newlines \n in private key
const GITHUB_APP_PRIVATEKEY = Buffer.from(
process.env.GITHUB_APP_PRIVATEKEY || "",
"base64"
).toString("utf-8");
// For sharing runStatus across before/after stages
let _runStatus = null;
module.exports = {
before: (app) => {
debug("configure before");
const gitHub = new GitHub(
GITHUB_ORG,
GITHUB_USERNAME,
GITHUB_APPID,
GITHUB_APP_PRIVATEKEY,
GITHUB_APP_CLIENTID,
GITHUB_APP_CLIENTSECRET,
GITHUB_APP_INSTALLATIONID
);
_runStatus = new RunStatus();
const actions = new Actions(gitHub, _runStatus, LOOKBACK_DAYS);
const routes = new Routes(
actions,
process.env.GITHUB_ORG || process.env.GITHUB_USERNAME
);
const router = express.Router();
routes.attach(router);
app.use(bodyParser.json());
app.use("/api", router);
const webhooks = new WebHooks(
PORT,
GITHUB_APP_WEBHOOK_SECRET,
GITHUB_APP_WEBHOOK_PORT,
GITHUB_APP_WEBHOOK_PATH,
gitHub,
actions,
app
);
// Start everything
actions.start();
webhooks.start();
},
after: (app, server) => {
debug("configure after");
// Attach socket.io to server
_runStatus.start(server);
},
};