diff options
author | nicoo <nicoo@mur.at> | 2023-12-08 02:57:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-08 02:57:38 +0100 |
commit | 1d7f14656a699e61e549f16e8e3e406241a31c87 (patch) | |
tree | 99f2c78fcc8505e8a7c94db3e7c8f6ca706ef801 /maintainers/scripts/get-maintainer.sh | |
parent | 09dc04054ba2ff1f861357d0e7e76d021b273cd7 (diff) | |
download | nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.tar nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.tar.gz nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.tar.bz2 nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.tar.lz nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.tar.xz nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.tar.zst nixlib-1d7f14656a699e61e549f16e8e3e406241a31c87.zip |
maintainers-list.nix: Document (current) invitation process, add get-maintainer.sh (#267084)
* maintainer-list: Document automatic invites to @NixOS/nixpkgs-maintainers * maintainers/scripts: Add `get-maintainer.sh` Supports querying `maintainers-list.nix` by Nix attribute, email address, github name or id, matrix account, or name. * maintainers/scripts/get-maintainer.sh: More verbose help message * maintainers/scripts/get-maintainer.sh: Fix (some) `shellcheck` lints * maintainers/scripts: Add README * maintainers/scripts/get-maintainer.sh: Put inline documentation at the top of the file * maintainers/scripts: Document this is not a stable interfact to nixpkgs Co-authored-by: Silvan Mosberger <github@infinisil.com> * scripts/README: Add example for `get-maintainer.sh` --------- Co-authored-by: Silvan Mosberger <github@infinisil.com>
Diffstat (limited to 'maintainers/scripts/get-maintainer.sh')
-rwxr-xr-x | maintainers/scripts/get-maintainer.sh | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/maintainers/scripts/get-maintainer.sh b/maintainers/scripts/get-maintainer.sh new file mode 100755 index 000000000000..3061d2ccc72f --- /dev/null +++ b/maintainers/scripts/get-maintainer.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p jq ncurses +# shellcheck shell=bash + +# Get a nixpkgs maintainer's metadata as a JSON object +# see HELP_MESSAGE just below, or README.md. + +set -euo pipefail + +declare -A SELECTORS=( [handle]= [email]= [github]= [githubId]= [matrix]= [name]= ) +HELP_MESSAGE="usage: '$0' [selector] value +examples: + get-maintainer.sh nicoo + get-maintainer.sh githubId 1155801 + +\`selector\` defaults to 'handle', can be one of: + ${!SELECTORS[*]} +" + +MAINTAINERS_DIR="$(dirname "$0")/.." + +die() { + tput setaf 1 # red + echo "'$0': $*" + tput setaf 0 # back to black + exit 1 +} + +listAsJSON() { + nix-instantiate --eval --strict --json "${MAINTAINERS_DIR}/maintainer-list.nix" +} + +parseArgs() { + [ $# -gt 0 -a $# -lt 3 ] || { + echo "$HELP_MESSAGE" + die "invalid number of arguments (must be 1 or 2)" + } + + if [ $# -eq 1 ]; then + selector=handle + else + selector="$1" + shift + fi + [ -z "${SELECTORS[$selector]-n}" ] || { + echo "Valid selectors are:" "${!SELECTORS[@]}" >&2 + die "invalid selector '$selector'" + } + + value="$1" + shift +} + +query() { + # explode { a: A, b: B, ... } into A + {handle: a}, B + {handle: b}, ... + local explode="to_entries[] | .value + { \"handle\": .key }" + + # select matching items from the list + # TODO(nicoo): Support approximate matching for `name` ? + local select + case "$selector" in + githubId) + select="select(.${selector} == $value)" + ;; + *) + select="select(.${selector} == \"$value\")" + esac + + echo "$explode | $select" +} + +parseArgs "$@" +listAsJSON | jq -e "$(query)" |