-
Notifications
You must be signed in to change notification settings - Fork 17
/
deployMaster.js
executable file
·41 lines (39 loc) · 1.12 KB
/
deployMaster.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
const axios = require('axios')
const CI_USER_TOKEN = process.env['CI_USER_TOKEN']
axios.post("https://api.github.com/repos/SwiftGGTeam/SwiftGGTeam.github.io/pulls", {
title: 'merge stage to master',
head: 'master',
base: 'aliyun-pages',
}, {
headers: {
'Authorization': `token ${CI_USER_TOKEN}`,
}
})
.then((result) => {
console.log(`PR created ${result.data.html_url}`)
const { number } = result.data
if (!number) {
console.error(`${number} error`)
process.exit(1)
}
setTimeout(() => {
// sometimes if request merge after created, API return error. so we delay 3s
axios.put(`https://api.github.com/repos/SwiftGGTeam/SwiftGGTeam.github.io/pulls/${number}/merge`, {
merge_method: 'merge'
}, {
headers: {
'Authorization': `token ${CI_USER_TOKEN}`,
}
})
.then((result) => {
console.log('merge success! API result is:')
console.log(result.data)
}).catch((err) => {
console.log(err.response)
process.exit(1)
});
}, 3000);
}).catch((err) => {
console.log(err.response.data.errors)
process.exit(1)
});