-
Notifications
You must be signed in to change notification settings - Fork 314
Expand file tree
/
Copy pathcontributer.nu
More file actions
97 lines (87 loc) · 2.07 KB
/
contributer.nu
File metadata and controls
97 lines (87 loc) · 2.07 KB
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
use std/log
use std/assert
def is-extern-available [command: string] {
which --all $command | any { $in.type == external }
}
def "assert extern-is-available" [...commands: string] {
for cmd in $commands {
assert (which --all $cmd | any { $in.type == external }) --error-label {
text: $"`($cmd)` not found in PATH"
span: (metadata $cmd).span
}
}
}
export-env {
assert extern-is-available gh
}
const default_repos = [
"nushell/new-nu-parser"
"nushell/nu-ansi-term"
"nushell/nushell"
"nushell/nushell.github.io"
"nushell/nu_scripts"
"nushell/reedline"
"nushell/tree-sitter-nu"
"nushell/vscode-nushell-lang"
]
def fetch-contributor-stats [repo: string]: nothing -> record<name: string, stats: table<login: string, contributions: int>> {
^gh api /repos/($repo)/contributors --cache 1h --paginate
| from json
| select login contributions
| {
name: $repo
stats: $in
}
}
# Get the total contribution count of contributors across multiple repositories
export def stats [
repos: list<string> = $default_repos
]: nothing -> table<user: string, contributions: int> {
$default_repos
| each {|repo| fetch-contributor-stats $repo }
| each {|e| $e.stats | rename -c {login: "user" contributions: $e.name} }
| reduce {|e|
join --outer $e user
}
| transpose --header-row
| update cells { default --empty 0 }
| math sum
| transpose user contributions
| sort-by --reverse contributions
}
const club_thresholds = [
20
50
100
250
500
1_000
2_500
3_000
]
def bounds [thresholds: list<int>] {
$club_thresholds
| window 2
| each {|e|
{
name: $e.0
bounds: ($e.0)..<($e.1)
}
}
| append {name: ($club_thresholds | last) bounds: (($club_thresholds | last)..)}
}
# Group contributors across multiple repositories based on their total contribution count
export def clubs [
repos: list<string> = $default_repos
--thresholds: list<int> = $club_thresholds
] {
let contributions = stats $repos
let clubs_bounds = bounds $thresholds
$contributions
| group-by {|e|
$clubs_bounds
| where $e.contributions in $it.bounds
| try { first | get name }
}
| reject ""
}