Skip to content

Commit 7411bd2

Browse files
committed
Add contributer module, alternative to the 20k_club script
Uses github cli `gh` to fetch information through the github api to avoid the need to clone the repositories.
1 parent e702d5a commit 7411bd2

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

make_release/contributer.nu

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use std/log
2+
use std/assert
3+
4+
def is-extern-available [command: string] {
5+
which --all $command | any { $in.type == external }
6+
}
7+
8+
def "assert extern-is-available" [...commands: string] {
9+
for cmd in $commands {
10+
assert (which --all $cmd | any { $in.type == external }) --error-label {
11+
text: $"`($cmd)` not found in PATH"
12+
span: (metadata $cmd).span
13+
}
14+
}
15+
}
16+
17+
export-env {
18+
assert extern-is-available gh
19+
}
20+
21+
const default_repos = [
22+
"nushell/new-nu-parser"
23+
"nushell/nu-ansi-term"
24+
"nushell/nushell"
25+
"nushell/nushell.github.io"
26+
"nushell/nu_scripts"
27+
"nushell/reedline"
28+
"nushell/tree-sitter-nu"
29+
"nushell/vscode-nushell-lang"
30+
]
31+
32+
def fetch-contributor-stats [repo: string]: nothing -> record<name: string, stats: table<login: string, contributions: int>> {
33+
^gh api /repos/($repo)/contributors --cache 1h --paginate
34+
| from json
35+
| select login contributions
36+
| {
37+
name: $repo
38+
stats: $in
39+
}
40+
}
41+
42+
# Get the total contribution count of contributors across multiple repositories
43+
export def stats [
44+
repos: list<string> = $default_repos
45+
]: nothing -> table<user: string, contributions: int> {
46+
$default_repos
47+
| each {|repo| fetch-contributor-stats $repo }
48+
| each {|e| $e.stats | rename -c {login: "user" contributions: $e.name} }
49+
| reduce {|e|
50+
join --outer $e user
51+
}
52+
| transpose --header-row
53+
| update cells { default --empty 0 }
54+
| math sum
55+
| transpose user contributions
56+
| sort-by --reverse contributions
57+
}
58+
59+
const club_thresholds = [
60+
20
61+
50
62+
100
63+
250
64+
500
65+
1_000
66+
2_500
67+
3_000
68+
]
69+
70+
def bounds [thresholds: list<int>] {
71+
$club_thresholds
72+
| window 2
73+
| each {|e|
74+
{
75+
name: $e.0
76+
bounds: ($e.0)..<($e.1)
77+
}
78+
}
79+
| append {name: ($club_thresholds | last) bounds: (($club_thresholds | last)..)}
80+
}
81+
82+
# Group contributors across multiple repositories based on their total contribution count
83+
export def clubs [
84+
repos: list<string> = $default_repos
85+
--thresholds: list<int> = $club_thresholds
86+
] {
87+
let contributions = stats $repos
88+
let clubs_bounds = bounds $thresholds
89+
90+
$contributions
91+
| group-by {|e|
92+
$clubs_bounds
93+
| where $e.contributions in $it.bounds
94+
| try { first | get name }
95+
}
96+
| reject ""
97+
}

0 commit comments

Comments
 (0)