Skip to content

Commit 0f46010

Browse files
authored
feat(Script): initial github-add-repo-admin.sh (#5)
1 parent c0cf62d commit 0f46010

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env /bin/bash
2+
set -euo pipefail
3+
4+
###
5+
## GLOBAL VARIABLES
6+
###
7+
GITHUB_TOKEN=${GITHUB_TOKEN:-''}
8+
ORG=${ORG:-''}
9+
API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
10+
REPO_ADMIN=${REPO_ADMIN:-''}
11+
12+
get_repo_pagination () {
13+
repo_pages=$(curl -H "Authorization: token ${GITHUB_TOKEN}" -I "${API_URL_PREFIX}/orgs/${ORG}/repos?per_page=100" | grep -Eo '&page=[0-9]+' | grep -Eo '[0-9]+' | tail -1;)
14+
echo "${repo_pages:-1}"
15+
}
16+
17+
limit_repo_pagination () {
18+
seq "$(get_repo_pagination)"
19+
}
20+
21+
process_repos () {
22+
for PAGE in $(limit_repo_pagination); do
23+
24+
for i in $(curl -H "Authorization: token ${GITHUB_TOKEN}" -s "${API_URL_PREFIX}/orgs/${ORG}/repos?page=${PAGE}&per_page=100&sort=full_name" | jq -r 'sort_by(.name) | .[] | .name'); do
25+
26+
# Give internal repo admin team permissions on the repo
27+
curl -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${REPO_ADMIN}/repos/${ORG}/${i}" -d '{"permission":"admin"}';
28+
29+
done
30+
done
31+
}
32+
33+
process_repos

0 commit comments

Comments
 (0)