forked from marionettejs/backbone.marionette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger-deploy-mn-com.js
50 lines (43 loc) · 991 Bytes
/
trigger-deploy-mn-com.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
var Travis = require('travis-ci');
var repo = 'marionettejs/marionettejs.com';
var travis = new Travis({
version: '2.0.0',
headers: {
'User-Agent': 'Travis/1.0'
}
});
var getLastMainBuildId = function(builds) {
var id;
for (var i = 0; i < builds.length; i++) {
if (!builds[i].pull_request) {
id = builds[i].id;
break;
}
}
if (!id) {
throw new Error('Build id was not found');
}
return id;
};
travis.authenticate({
github_token: process.env.GH_TOKEN
}, function (err, res) {
if (err) {
return console.error(err);
}
//get repo builds
travis.repos(repo.split('/')[0], repo.split('/')[1]).builds.get(function (err, res) {
if (err) {
return console.error(err);
}
//rebuild latest build
travis.requests.post({
build_id: getLastMainBuildId(res.builds)
}, function (err, res) {
if (err) {
return console.error(err);
}
console.log(res.flash[0].notice);
});
});
});