-
Notifications
You must be signed in to change notification settings - Fork 15
/
createBranches.js
49 lines (43 loc) · 1.21 KB
/
createBranches.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
const request = require('request-promise')
const fs = require('fs-extra')
const glob = require('glob')
const { sleep } = require('./utils')
const config = require('./config')
const api = `${config.target.baseUrl}/${config.target.org}/${config.target.repo}`
const headers = {
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'node.js'
}
if (config.target.token) {
headers['Authorization'] = `token ${config.target.token}`
}
const createBranch = async (issue) => {
const ref = `refs/heads/pr${issue.number}base`
await request({
method: 'POST',
headers,
url: `${api}/git/refs`,
body: {
ref,
sha: issue.base.sha,
},
json: true,
}).catch(err => {
console.log(`Unable to create ref: ${ref}`)
console.log(err.message)
})
}
const main = async () => {
const issues = glob.sync(`${config.source.repo}/issues/issue-+([0-9]).json`)
.map(file => JSON.parse(fs.readFileSync(file)))
.sort((a, b) => a.number - b.number)
// console.log(issues)
for (let issue of issues) {
if (issue.base) {
console.log(`Creating branch for PR-${issue.number}`)
await createBranch(issue)
await sleep(60 * 60 * 1000 / config.apiCallsPerHour)
}
}
}
main()