-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
52 lines (43 loc) · 1.43 KB
/
setup.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
require('dotenv').config()
const { mkdir } = require('fs/promises')
const config = require('../config.json')
const {
getPublicRepos,
createMetaList,
cloneToPath,
updateDescription,
createWebhook
} = require('../utils')
async function createRepositoriesPath () {
console.log('[INFO]', 'Creating repositories\' directory if it does not exist')
await mkdir(config.repositoriesPath, { recursive: true })
}
async function main () {
// Create repositories path if it doesn't exist
await createRepositoriesPath()
// Track the progress of cloning
let progressCount = 0
let totalProgressRequired
console.log('[INFO] Getting repos from GitHub')
await getPublicRepos()
.then(repos => {
totalProgressRequired = repos.length * 4
return repos
})
.then(createMetaList)
.then(repos => repos.map(async repo => {
const progress = () => `[${++progressCount}/${totalProgressRequired}]`
console.log('[INFO] %s Cloning %s', progress(), repo.name)
const localPath = await cloneToPath(repo)
console.log('[INFO] %s Adding description for %s', progress(), repo.name)
await updateDescription(localPath, repo)
console.log('[INFO] %s Creating webhook for %s', progress(), repo.name)
await createWebhook(repo)
console.log('[INFO] %s Done %s', progress(), repo.name)
}))
.catch(err => {
console.error('[ERR] An error occured:')
console.error(err)
})
}
main()