-
Notifications
You must be signed in to change notification settings - Fork 70
/
rollbar.js
68 lines (57 loc) · 1.52 KB
/
rollbar.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
// ## Rollbar.js ##########################################
//
// This script handles marking a deployment in rollbar
// so I can track when errors get introduced
//
// ########################################################
import https from 'https';
// This is stored in netlify variable, and is set in env during build
let token = process.env.ROLLBAR_ACCESS_TOKEN
// This gets set during the build by netlify
let commitRef = process.env.COMMIT_REF
if (!token) {
console.log("ERROR: no access token specified in env.");
process.exit(1);
}
if (!commitRef) {
console.log("ERROR: no commit ref in env.");
process.exit(1);
}
console.log(`Marking deployment ${commitRef} in Rollbar...`);
// Full json
// {
// "environment": "string",
// "revision": "string",
// "rollbar_username": "string",
// "local_username": "string",
// "comment": "string",
// "status": "string"
// }
const data = JSON.stringify({
"environment": process.env.CONTEXT,
"revision": commitRef,
"local_username": "netlify"
})
// https://api.rollbar.com/api/1/deploy
const options = {
hostname: 'api.rollbar.com',
port: 443,
path: '/api/1/deploy',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
'X-Rollbar-Access-Token': token
}
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.write(data)
req.end()