forked from habitlab/habitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_libs_to_github
executable file
·57 lines (47 loc) · 1.51 KB
/
upload_libs_to_github
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
#!/usr/bin/env node
let jsyaml = require('js-yaml')
let fs = require('fs')
let version = jsyaml.safeLoad(fs.readFileSync('src/manifest.yaml', 'utf-8')).version.trim().split('.').join('-')
let Octokat = require('octokat')
let getsecret = require('getsecret')
let {exec} = require('shelljs')
let octo = new Octokat({token: getsecret('github_api_key')})
let name = version
let {removeSync} = require('remove')
async function list_repos() {
let repo_list = await octo.orgs('habitlab-dist').repos.fetch()
return repo_list.items.map(x => x.name)
}
async function does_repo_exist(name) {
// return await octo.orgs('habitlab-dist').repos.contains(name)
// above line does not work as contains expects an id not a name
let repo_list = await list_repos()
return repo_list.includes(name)
}
async function create_repo(name) {
await octo.orgs('habitlab-dist').repos.create({name: name})
}
async function main() {
if (!fs.existsSync('dist')) {
console.log('missing dist directory')
return
}
let repo_exists = await does_repo_exist(name)
if (!repo_exists) {
console.log('creating repo on github ' + name)
await create_repo(name)
}
process.chdir('dist')
if (fs.existsSync('.git')) {
removeSync('.git')
}
exec('git init')
// exec('git remote rm origin')
exec('git remote add origin git@github.com:habitlab-dist/' + name + '.git')
exec('git add .')
exec('git commit -am "initial commit"')
exec('git branch gh-pages')
exec('git push origin gh-pages --force')
removeSync('.git')
}
main()