Created
May 16, 2026 08:40
-
-
Save luoling8192/624f1c6cfc29725cb53be03476ecaba1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| set -euo pipefail | |
| if [[ $# -lt 1 || -z "${1:-}" ]]; then | |
| echo "usage: ${0##*/} <github-username>" >&2 | |
| exit 1 | |
| fi | |
| account=$1 | |
| if ! data=$(gh api "users/$account" 2>/dev/null); then | |
| echo "error: failed to fetch user '$account' (check gh auth status)" >&2 | |
| exit 1 | |
| fi | |
| id=$(jq -r '.id // empty' <<<"$data") | |
| name=$(jq -r '.name // .login // empty' <<<"$data") | |
| if [[ -z "$id" || -z "$name" ]]; then | |
| echo "error: user '$account' not found or response malformed" >&2 | |
| exit 1 | |
| fi | |
| printf 'Co-authored-by: %s <%s+%s@users.noreply.github.com>\n' "$name" "$id" "$account" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment