-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcreateReleases.js
60 lines (53 loc) · 1.56 KB
/
createReleases.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
51
52
53
54
55
56
57
58
59
60
const request = require('request-promise')
const fs = require('fs-extra')
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 createRelease = async (release) => {
console.log(`Creating Release: ${release.tag_name}`)
await request({
method: 'POST',
headers,
url: `${api}/releases`,
body: {
tag_name: release.tag_name,
target_commitish: release.target_commitish,
name: release.name,
body: release.body,
draft: release.draft,
prerelease: release.prerelease,
},
json: true,
}).catch(err => {
console.log(`Unable to create release: ${release.tag_name}`)
console.log(err.message)
})
}
/**
* Takes milliseconds of elapsed time and creates a string like '05m 10s'
* @param duration milliseconds
*/
const formatDuration = (duration) => {
const seconds = duration / 1000
return new Date((seconds % 86400) * 1000)
.toUTCString()
.replace(/.*(\d{2}):(\d{2}):(\d{2}).*/, '$1h $2m $3s')
.replace('00h ', '')
.replace('00m ', '')
.replace('00s', '')
.trim()
}
const main = async () => {
const releases = JSON.parse(await fs.readFile(`${config.source.repo}/releases.json`))
console.log(`Releases to create: ${releases.length}`)
for (let release of releases) {
await createRelease(release, releases)
}
}
main().catch(console.error)