Created
February 14, 2021 23:21
-
-
Save knl/c6a62b6ce60a096b46189a80860a0359 to your computer and use it in GitHub Desktop.
Disable actions on all owned repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#!nix-shell -p gitAndTools.hub | |
#!nix-shell -p jq | |
#!nix-shell -p bash | |
#!nix-shell -i bash | |
# Author: Nikola Knezevic | |
# Description: Will disable all actions on all repositories where the given | |
# token is the owner. | |
# Requirements: | |
# - GITHUB_TOKEN with a personal access token with 'repo' rights. | |
set -eufo pipefail | |
hub api --paginate "/user/repos?affiliation=owner" \ | |
| jq -r '.[] | .full_name' \ | |
| while read -r ghRepo; do | |
printf "'%s': " "${ghRepo}" | |
read -r isEnabled < <( \ | |
hub api "/repos/${ghRepo}/actions/permissions" \ | |
| jq -r '.enabled' | |
) | |
printf "\e[1m%s\e[0m" "${isEnabled}" | |
if [[ "${isEnabled}" == "true" ]]; then | |
hub api -XPUT "/repos/${ghRepo}/actions/permissions" \ | |
-F enabled=false \ | |
&& printf "\e[4D\e[1m%s\e[0m" "DISABLED" | |
fi | |
printf "\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment