Skip to content

Instantly share code, notes, and snippets.

@amtoine
Last active April 12, 2023 17:05
Show Gist options
  • Save amtoine/c68b9d5122454f0c2d2bc626d5e491f9 to your computer and use it in GitHub Desktop.
Save amtoine/c68b9d5122454f0c2d2bc626d5e491f9 to your computer and use it in GitHub Desktop.
list contributions in a *GitHub* repo

list contributions in a GitHub repo

this nushell module lets you list the top 100 contributors of a repository or a list of multiple repositories.

usage

  • load the module
> use mod.nu *
  • get the five biggest contributors to nushell/nushell
get-contributors [
    'nushell/nushell'
    'nushell/nushell.github.io'
    'nushell/nu_scripts'
]
| where nushell/nushell > 0
| select author nushell/nushell
| first 5
| transpose -r
| into record

will give

╭──────────────┬──────╮
 jntrnr        1386 
 fdncred       631  
 andrasio      387  
 elferherrera  230  
 kubouch       220  
╰──────────────┴──────╯
def gh-contributions [repo: string] {
http get ({
scheme: https
host: api.github.com
path: $"/repos/($repo)/contributors"
params: {
per_page: 100
}
} | url join)
| select login contributions
| rename author $repo
}
def join-contributions [repos] {
mut contributors = []
for repo in $repos {
$contributors = ($contributors | join $repo author --outer)
}
for column in ($contributors | columns | where {|it| $it != author}) {
$contributors = ($contributors | default 0 $column)
}
$contributors
}
export def get-contributors [repos: list<string>] {
let repos = (
$repos | each {|repo|
gh-contributions $repo
}
)
join-contributions $repos
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment