-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (39 loc) · 1005 Bytes
/
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
require('dotenv').config();
const Promise = require('bluebird');
const request = Promise.promisifyAll(require('request'));
const main = async () => {
const repo = process.env.GITHUB_REPO;
const branch = process.env.GITHUB_REPO_BRANCH;
const token = process.env.TRAVIS_API_KEY;
const res = await request.postAsync(
`https://api.travis-ci.com/repo/${repo}/requests`,
{
headers: {
'Authorization': `token ${token}`,
'Travis-API-Version': '3'
},
json: {
request: {
branch: branch || 'master'
}
}
}
);
if (res.statusCode >= 400) {
console.error(res.body);
throw new Error(res.statusMessage);
}
if (res.body.remaining_requests === 0){
console.error('Error! Requests exceed limit.');
return;
}
console.log(`Trigger build on ${decodeURIComponent(repo)} successfully.`)
}
main()
.then(() => {
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});