├── README.md └── gh-co-author /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Co-author Extension 2 | 3 | This is a GitHub CLI extension that generates `Co-authored-by` to be added as a *trailer* 4 | to the commit message. 5 | 6 | This repository is just a wrap around what [Hynek Schlawack](https://github.com/hynek) did on 7 | their article [TIL: Easier Crediting of Contributors on GitHub](https://hynek.me/til/easier-crediting-contributors-github/). 8 | 9 | ## Installation 10 | 11 | You need to have [GitHub CLI](https://cli.github.com/) installed, and then: 12 | 13 | ```bash 14 | gh extension install Kludex/gh-co-author 15 | ``` 16 | 17 | ## Usage 18 | 19 | There's a single command available: 20 | 21 | ```bash 22 | gh co-author AUTHOR 23 | ``` 24 | -------------------------------------------------------------------------------- /gh-co-author: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This is stolen from Hynek Schlawack's article: 3 | # https://hynek.me/til/easier-crediting-contributors-github/ 4 | # 5 | # All credits to Hynek Schlawack. 6 | 7 | set -e 8 | 9 | help() { 10 | echo "Usage: gh co-author AUTHOR" >&2 11 | echo 12 | echo "Generate \`Co-authored-by\` trailer for commit messages." 13 | echo 14 | echo "Arguments:" 15 | echo " AUTHOR [required] GitHub username of the author." 16 | echo 17 | echo "Commands:" 18 | echo " help Show this help message." 19 | } 20 | 21 | co_author() { 22 | account=$1 23 | data=$(curl -s https://api.github.com/users/$account) 24 | id=$(echo $data | jq .id) 25 | name=$(echo $data | jq --raw-output '.name // .login') 26 | 27 | printf "Co-authored-by: %s <%d+%s@users.noreply.github.com>\n" "$name" $id $account 28 | } 29 | 30 | while [[ "$#" -gt 0 ]]; do 31 | case "$1" in 32 | -h | --help) 33 | help 34 | exit 1 35 | ;; 36 | *) 37 | co_author $1 38 | exit 0 39 | ;; 40 | esac 41 | done 42 | 43 | help 44 | exit 1 45 | --------------------------------------------------------------------------------