-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.js
54 lines (44 loc) · 1.47 KB
/
sync.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
const path = require('path')
const { rmdir } = require('fs/promises')
const config = require('../config.json')
const {
getPublicRepos,
cloneToPath,
updateDescription,
createWebhook,
createMetaList
} = require('../utils')
async function main () {
const currentRepoNames = require(`${config.repositoriesPath}/repositories.json`)
console.log('[INFO] Fetching new list')
const updatedRepos = await getPublicRepos()
const updatedRepoNames = updatedRepos.map(repo => repo.name)
const newRepos = updatedRepoNames
.filter(updated => !currentRepoNames.includes(updated))
.map(name => updatedRepos.find(repo => repo.name === name))
const deletedRepos = currentRepoNames.filter(current => !updatedRepoNames.includes(current))
const delta = {
new: newRepos.length,
deleted: deletedRepos.length
}
if (delta.new + delta.deleted === 0) {
console.log('[INFO] No changes, exiting.')
return
}
console.log('[INFO] Delta:', delta)
// rm deleted repos locally
deletedRepos.map(async repo => {
const deletePath = path.join(config.repositoriesPath, repo)
await rmdir(deletePath, { recursive: true })
})
// clone new repos, setup description, add webhook
newRepos.map(async repo => {
const localPath = await cloneToPath(repo, true)
await updateDescription(localPath, repo, true)
await createWebhook(repo, true)
console.log('[INFO] Done %s', repo.name)
})
// update meta list
await createMetaList(updatedRepos)
}
main()