-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
sync.js
65 lines (54 loc) · 1.31 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
55
56
57
58
59
60
61
62
63
64
65
require('dotenv').config()
const fs = require('mz/fs')
const {fetch} = require('./api')
const query = `
query ($endCursor: String) {
search(type: REPOSITORY, query: "stars:>8000", first: 100, after: $endCursor) {
repositoryCount
nodes {
... on Repository {
owner {
login
}
name
stargazers {
totalCount
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
`
async function main() {
let {
search: {
repositoryCount,
nodes,
pageInfo: {hasNextPage, endCursor}
}
} = await fetch(query)
while (hasNextPage) {
const pt = Math.round(100 * nodes.length / repositoryCount)
console.log(`loading ${pt}% ${nodes.length}/${repositoryCount}`)
const data = await fetch(query, {endCursor})
endCursor = data.search.pageInfo.endCursor
hasNextPage = data.search.pageInfo.hasNextPage
nodes = nodes.concat(data.search.nodes)
}
console.log('Total repos: ' + nodes.length)
const db = {}
for (let node of nodes) {
const {
owner: {login},
name,
stargazers: {totalCount}
} = node
db[login + '/' + name] = totalCount
}
fs.writeFile('db.js', `module.exports = ${JSON.stringify(db, null, 2)}\n`)
}
main().catch(console.log)