Skip to content

Instantly share code, notes, and snippets.

@amtoine
Created March 19, 2023 18:01
Show Gist options
  • Save amtoine/8b028e16747bf7f850a8f55cfc4c1327 to your computer and use it in GitHub Desktop.
Save amtoine/8b028e16747bf7f850a8f55cfc4c1327 to your computer and use it in GitHub Desktop.
list contributions between PRs

list contributions between PRs

use the module

use mod.nu *
list contributions
export def "list tags" [] {
git tag -l
| str trim
| lines
| wrap name
| upsert date {|tag|
git show --summary --format=%ci $tag.name
| lines
| get 0
| str trim
| into datetime
}
| sort-by date
}
def latest-tag [] {
git describe --tags --abbrev=0 HEAD | str trim
}
def list-commits [
from: string
to: string # not included
] {
git log $"(git rev-parse $from)...(git rev-parse $to)^" --oneline --pretty="format:%h|%s|%an"
| lines
| split column "|" hash message author
}
export def "list contributions" [
release: string = $"(latest-tag)"
--pretty: bool
] {
let previous = (git describe --tags --abbrev=0 $"($release)^")
let contributions = (list-commits $previous $release)
$contributions
| group-by author
| transpose author contributions
| if $pretty {
flatten --all
| upsert pr {||
get message | parse "{rest} (#{pr})" | get pr
}
| flatten | group-by author | transpose name contributions | each {|contributor|
let contributions = ($contributor.contributions | each {|contribution|
let pr_url = ({
scheme: https
host: github.com
path: (["nushell" "nushell" "pull" $contribution.pr] | path join)
} | url join)
$"[($contribution.message)](char lparen)($pr_url)(char rparen)"
})
$"- ($contributor.name) created ($contributions | str join ', and ')"
}
| to text
} else {
reject contributions.author
| transpose -r
| into record
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment