# -rw-r--r-- 1.1 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh

set -e

TOKEN=''
USERNAME=fnux
PATTERN='^rpms/erlang-.*$'
GROUP=erlang-maint-sig

query () {
	content_header="Content-Type: application/x-www-form-urlencoded"
	authorization_header="Authorization: token $TOKEN"

	method=$1
	url=$2

	curl -s -X "$method" -H "$authorization_header" -H "$content_header" "$url" -d "$3"
}

next="https://src.fedoraproject.org/api/0/projects?username=$USERNAME"
projects=""
echo '> Fetching projects:'
while [ "$next" != "null" ]; do
	echo "Querying $next..."
	raw=$(query GET "$next")
	next=$(echo "$raw" | jq -r .pagination.next)
	projects="$projects $(echo "$raw" | jq -r .projects[].fullname)"
done

echo "> Checking access groups:"
for name in $(echo "$projects" | grep -E "$PATTERN"); do
	if query GET "https://src.fedoraproject.org/api/0/$name" \
		| jq .access_groups.admin | grep $GROUP > /dev/null; then
		echo "$name is in $GROUP"
	else
		echo "$name is NOT in $GROUP"
		echo "    Adding $GROUP as admin..."
		query POST "https://src.fedoraproject.org/api/0/$name/git/modifyacls" \
			"user_type=group&name=$GROUP&acl=admin" > /dev/null
	fi
done