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