-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathanchor.js
42 lines (36 loc) · 1.04 KB
/
anchor.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
const fs = require('fs-extra')
const request = require('request-promise')
const config = require('./config')
const source = `${config.source.baseUrl}/${config.source.org}/${config.source.repo}`
const headers = {
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'node.js'
}
if (config.source.token) {
headers['Authorization'] = `token ${config.source.token}`
}
const main = async () => {
const orphanedCommits = JSON.parse(await fs.readFile(`${config.source.repo}/missing-commits.json`))
let anchoredCommits = []
console.log(`Orphaned commits: ${orphanedCommits.length}`)
for (let commit of orphanedCommits) {
await request({
method: 'POST',
headers,
url: `${source}/git/refs`,
data: {
ref: `refs/anchor/${commit}`,
sha: commit
}
})
.then(response => {
anchoredCommits.push(commit)
return response
})
.catch(err => {
console.log(`Could not create an anchor for ${commit}`)
})
}
console.log(`Anchored commits: ${anchoredCommits.length}`)
}
main()