-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (45 loc) · 1.14 KB
/
index.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
require('dotenv-safe').config()
const { Octokit } = require('@octokit/rest')
const { CloudBuildClient } = require('@google-cloud/cloudbuild')
const cb = new CloudBuildClient()
const { Server } = require('./src/Server.js')
const { listTriggers } = require('./src/listTriggers')
const { buildTriggerMap } = require('./src/buildTriggerMap')
const {
PORT = 8080,
GITHUB_TOKEN,
REPO_NAME,
REPO_OWNER,
GCP_PROJECT,
GCP_TRIGGER_REGION,
} = process.env
const octokit = new Octokit({
auth: GITHUB_TOKEN,
})
;(async () => {
const triggerList = await listTriggers({
client: cb,
projectId: GCP_PROJECT,
region: GCP_TRIGGER_REGION,
})
const triggers = buildTriggerMap(triggerList)
console.log(
'watching for builds from the follow triggers:',
JSON.stringify(triggers),
)
const server = Server({
log: console.log,
triggers,
createStatus: (status) =>
octokit.repos.createCommitStatus(
Object.assign(
{
repo: REPO_NAME,
owner: REPO_OWNER,
},
status,
),
),
})
server.listen(PORT, () => console.log(`🚀 listening on port ${PORT}`))
})()