waagent: 2.11.1.12 -> 2.12.0.2 (#357728)
[NixPkgs.git] / maintainers / scripts / check-maintainer-github-handles.sh
bloba5555ca9e909e100c258a17effadc719f88a5998
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p jq parallel
4 # Example how to work with the `lib.maintainers` attrset.
5 # Can be used to check whether all user handles are still valid.
7 set -o errexit -o noclobber -o nounset -o pipefail
8 shopt -s failglob inherit_errexit
10 function 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
27 # because of github’s hard request limits, this can take some time
28 429) sleep 2
29 printf "."
30 checkCommits "$user"
31 ret=$?
33 *) printf "BAD STATUS: $(tail -n1 "$tmp") for %s\n" "$user"; ret=1
34 ret=1
36 esac
37 rm "$tmp"
38 return $ret
40 export -f checkCommits
42 function 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"
56 export -f checkUser
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
61 nix-instantiate -A lib.maintainers --eval --strict --json \
62 | jq -r '.[]|.github|select(.)' \
63 | parallel -j5 checkUser
65 # To check some arbitrary users:
66 # parallel -j100 checkUser ::: "eelco" "profpatsch" "Profpatsch" "a"