-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
83 lines (73 loc) · 3.17 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
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
const validateGitHubWebHook = require('./validate-github-webhook')
module.exports = async function (context, req) {
const withStatus = (status, headers, body) => {
if (typeof body === 'object') try {
body = JSON.stringify(null, 2)
} catch (e) {
context.log(e)
}
context.res = {
status,
headers,
body
}
}
const ok = (body) => {
withStatus(undefined, undefined, body)
}
try {
validateGitHubWebHook(context)
} catch (e) {
context.log(e)
return withStatus(403, undefined, `Go away, you are not a valid GitHub webhook: ${e}`)
}
try {
const slashCommand = require('./slash-commands')
if (req.headers['x-github-event'] === 'issue_comment'
&& req.body.action === 'created'
&& req.body.comment?.body
&& req.body.comment.body.startsWith('/')) return ok(await slashCommand(context, req))
} catch (e) {
context.log(e)
return withStatus(500, undefined, e.message || JSON.stringify(e, null, 2))
}
try {
const selfHostedARM64Runners = require('./self-hosted-arm64-runners')
if (req.headers['x-github-event'] === 'workflow_job'
&& ['git-for-windows/git-for-windows-automation', 'git-for-windows/git-sdk-arm64'].includes(req.body.repository.full_name)
&& ['queued', 'completed'].includes(req.body.action)
&& req.body.workflow_job.labels.length === 2
&& req.body.workflow_job.labels[0] === 'Windows'
&& req.body.workflow_job.labels[1] === 'ARM64') return ok(await selfHostedARM64Runners(context, req))
} catch (e) {
context.log(e)
return withStatus(500, undefined, e.message || JSON.stringify(e, null, 2))
}
try {
const finalizeGitForWindowsRelease = require('./finalize-g4w-release')
if (req.headers['x-github-event'] === 'workflow_run'
&& req.body.repository.full_name === 'git-for-windows/git-for-windows-automation'
&& req.body.action === 'completed'
&& req.body.workflow_run.path === '.github/workflows/release-git.yml'
&& req.body.workflow_run.conclusion === 'success') return ok(await finalizeGitForWindowsRelease(context, req))
} catch (e) {
context.log(e)
return withStatus(500, undefined, e.message || JSON.stringify(e, null, 2))
}
try {
const { cascadingRuns, handlePush } = require('./cascading-runs.js')
if (req.headers['x-github-event'] === 'check_run'
&& req.body.repository.full_name === 'git-for-windows/git'
&& req.body.action === 'completed') return ok(await cascadingRuns(context, req))
if (req.headers['x-github-event'] === 'push'
&& req.body.repository.full_name === 'git-for-windows/git') return ok(await handlePush(context, req))
} catch (e) {
context.log(e)
return withStatus(500, undefined, e.message || JSON.stringify(e, null, 2))
}
context.log("Got headers")
context.log(req.headers)
context.log("Got body")
context.log(req.body)
ok(`Received event ${req.headers["x-github-event"]}`)
}