forked from COVID19Tracking/covid-public-api-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger-webhook.js
More file actions
31 lines (29 loc) · 813 Bytes
/
trigger-webhook.js
File metadata and controls
31 lines (29 loc) · 813 Bytes
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
require('dotenv').config()
const git = require('nodegit')
const fetch = require('node-fetch')
const run = () => {
if (typeof process.env.SITE_BUILD_WEBHOOK === 'undefined') {
console.log('No webhook set')
return
}
const changedFiles = []
git.Repository.open('./_api').then((repo) => {
git.Status.foreach(repo, (file) => {
if (file.search('status') === -1) {
changedFiles.push(file)
}
}).then((response) => {
if (changedFiles.length) {
console.log(`${changedFiles.length} files changed, sending webhook`)
fetch(process.env.SITE_BUILD_WEBHOOK, {
method: 'post',
body: '{}',
headers: { 'Content-Type': 'application/json' },
})
} else {
console.log('No files changed')
}
})
})
}
run()