forked from ember-learn/guides-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
should-it-deploy-preview-app.js
executable file
·45 lines (33 loc) · 1.07 KB
/
should-it-deploy-preview-app.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
#!/usr/bin/env node
/* eslint-env node */
const https = require('https')
/*
With this script, we only run a preview build on demand, since our CI was timing out
when we ran previews for everything.
*/
if (process.env.TRAVIS_EVENT_TYPE !== 'pull_request') {
console.log('This aint no pull request')
process.exit(1)
}
const needsDeploy = 861719997
const options = {
hostname: 'api.github.com',
path: `/repos/ember-learn/guides-source/pulls/${process.env.TRAVIS_PULL_REQUEST}`,
method: 'GET',
headers: { 'User-Agent': 'node/https' }
}
const parseResponse = (res) => {
let { labels } = JSON.parse(res)
const needsDeployLabel = labels.find(item => item.id === needsDeploy)
if (needsDeployLabel) {
console.log('Needs deploy preview label found on PR')
process.exit(0)
}
console.log('Needs deploy preview label not found on PR')
process.exit(1)
}
https.get(options, (response) => {
let data = ''
response.on('data', (chunk) => data += chunk)
response.on('end', () => parseResponse(data))
}).on('error', (err) => console.error('Error: ' + err.message))