Skip to content

Instantly share code, notes, and snippets.

@jayvdb
Last active July 6, 2022 01:12
Show Gist options
  • Save jayvdb/51148aab5820ecfce1f245f2305b8439 to your computer and use it in GitHub Desktop.
Save jayvdb/51148aab5820ecfce1f245f2305b8439 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o nounset
set -o pipefail
GITHUB_ORG=..
GITHUB_API_USER=..
# GITHUB_TOKEN=..
BRANCH_NAME=..
function _ghctl_all_active {
repos_page=1
while true; do
repos_counter=0
api_result=$(curl -s "https://$GITHUB_API_USER:[email protected]/orgs/${GITHUB_ORG}/repos?per_page=100&page=$repos_page")
#echo $api_result | jq ".[].name"
for repo in $(echo "$api_result" | jq -r ".[].name"); do
#echo "Processing $repo"
repo_api_result=$(curl -s "https://$GITHUB_API_USER:[email protected]/repos/${GITHUB_ORG}/$repo")
#echo $repo_api_result | jq ".topics"
is_active="0"
for topic in $(echo "$repo_api_result" | jq -r ".topics[]"); do
#echo "topic: $topic"
if [[ "$topic" == "active" ]]; then
is_active="1"
fi
done
if [[ $is_active == "1" ]]; then
echo "Selected $repo"
ghctl create protection -r $repo -b "$BRANCH_NAME" --minapprove 1
# This was not done as it looks like it might overwrite/reset
# other settings not specified on the cmdline.
#ghctl update repo --name $repo --nomergecommit --norebasemerge
fi
((repos_counter+=1))
done
((repos_page+=1))
[[ $repos_counter == 100 ]] || break
done
}
_ghctl_all_active
github:
repo:
name: ansible-playbooks
private: true
defaultBranch: main
pages:
issues: false
projects: false
wiki: false
merge:
allowMergeCommit: false
allowSquashMerge: true
allowRebaseMerge: false
branches:
- name: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment