This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
by-repo.js
103 lines (97 loc) · 2.67 KB
/
by-repo.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict'
// npm
// const groupBy = require('lodash.groupby')
const sortBy = require('lodash.sortby')
const dd = x => console.error(new Date().toISOString(), x)
// self
dd('start')
const { users } = require('./gat-repos-v3.json')
dd('loaded')
const projects = new Map()
dd('process')
users.forEach(u => {
if (u.starredRepositories || u.starredRepositoriesV2) {
;(u.starredRepositories || u.starredRepositoriesV2).forEach(p => {
const g = projects.get(p.nameWithOwner) || p
g.rolloCountStars = (g.rolloCountStars || 0) + 1
if (!g.rolloCountContribs) {
g.rolloCountContribs = 0
}
if (!g.users) {
g.users = []
}
g.users.push({ login: u.login, location: u.location, type: 'star' })
if (!g.contribsProrata) {
g.contribsProrata = 0
}
g.starsProrata =
(g.rolloCountStars &&
// g.stargazersCount > 9 &&
g.rolloCountStars / g.stargazersCount) ||
0
projects.set(g.nameWithOwner, g)
})
}
if (u.repositoriesContributedTo) {
u.repositoriesContributedTo.forEach(p => {
const g = projects.get(p.nameWithOwner) || p
g.rolloCountContribs = (g.rolloCountContribs || 0) + 1
if (!g.rolloCountStars) {
g.rolloCountStars = 0
}
if (!g.users) {
g.users = []
}
g.users.push({ login: u.login, location: u.location, type: 'contrib' })
if (!g.starsProrata) {
g.starsProrata = 0
}
g.contribsProrata =
(g.rolloCountContribs &&
// g.forkCount > 4 &&
g.rolloCountContribs / (g.watchersCount + g.forkCount)) ||
0
projects.set(g.nameWithOwner, g)
})
}
})
dd('processed')
dd('toArray')
const repos = Array.from(projects.values())
// console.error(repos[0], Object.keys(repos[0]))
dd('toObj')
const obj = {
nResults: {
stars: repos.reduce((a, b) => a + b.rolloCountStars, 0),
contribs: repos.reduce((a, b) => a + b.rolloCountContribs, 0),
tot: repos.reduce((a, b) => a + b.rolloCountStars + b.rolloCountContribs, 0)
},
repos,
contribs: sortBy(repos, 'rolloCountContribs')
.reverse()
.slice(0, 100),
contribsProrata: sortBy(
sortBy(repos, 'contribsProrata')
.reverse()
.slice(0, 500),
'rolloCountContribs'
)
.reverse()
.slice(0, 500),
stars: sortBy(repos, 'rolloCountStars')
.reverse()
.slice(0, 100),
starsProrata: sortBy(
sortBy(repos, 'starsProrata')
.reverse()
.slice(0, 500),
'rolloCountStars'
)
.reverse()
.slice(0, 500),
tot: sortBy(repos, a => a.rolloCountContribs + a.rolloCountStars)
.reverse()
.slice(0, 100)
}
dd('done')
console.log(JSON.stringify(obj, null, ' '))