1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p jq parallel
3
4# Example how to work with the `lib.maintainers` attrset.
5# Can be used to check whether all user handles are still valid.
6
7set -o errexit -o noclobber -o nounset -o pipefail
8shopt -s failglob inherit_errexit
9
10function checkCommits {
11 local ret status tmp user
12 user="$1"
13 tmp=$(mktemp)
14 curl --silent -w "%{http_code}" \
15 "https://github.com/NixOS/nixpkgs/commits?author=$user" \
16 > "$tmp"
17 # the last line of tmp contains the http status
18 status=$(tail -n1 "$tmp")
19 ret=
20 case $status in
21 200) if <"$tmp" grep -i "no commits found" > /dev/null; then
22 ret=1
23 else
24 ret=0
25 fi
26 ;;
27 # because of github’s hard request limits, this can take some time
28 429) sleep 2
29 printf "."
30 checkCommits "$user"
31 ret=$?
32 ;;
33 *) printf "BAD STATUS: $(tail -n1 "$tmp") for %s\n" "$user"; ret=1
34 ret=1
35 ;;
36 esac
37 rm "$tmp"
38 return $ret
39}
40export -f checkCommits
41
42function checkUser {
43 local user="$1"
44 local status=
45 status="$(curl --silent --head "https://github.com/${user}" | grep Status)"
46 # checks whether a user handle can be found on github
47 if [[ "$status" =~ 404 ]]; then
48 printf "%s\t\t\t\t%s\n" "$status" "$user"
49 # checks whether the user handle has any nixpkgs commits
50 elif checkCommits "$user"; then
51 printf "OK!\t\t\t\t%s\n" "$user"
52 else
53 printf "No Commits!\t\t\t%s\n" "$user"
54 fi
55}
56export -f checkUser
57
58# output the maintainers set as json
59# and filter out the github username of each maintainer (if it exists)
60# then check some at the same time
61nix-instantiate -A lib.maintainers --eval --strict --json \
62 | jq -r '.[]|.github|select(.)' \
63 | parallel -j5 checkUser
64
65# To check some arbitrary users:
66# parallel -j100 checkUser ::: "eelco" "profpatsch" "Profpatsch" "a"