use mod.nu *
list contributions
Created
March 19, 2023 18:01
-
-
Save amtoine/8b028e16747bf7f850a8f55cfc4c1327 to your computer and use it in GitHub Desktop.
list contributions between PRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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