Created
September 7, 2020 10:39
-
-
Save meriororen/3eefff64ee42eae8dd095a31c951ef31 to your computer and use it in GitHub Desktop.
protect and unprotect all master branches in a group
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
#!/bin/bash | |
all_project_ids=`curl --header "PRIVATE-TOKEN: ${gitlab_access}" \ | |
"https://gitlab.com/api/v4/projects?membership=true&simple=true&per_page=100" | jq '.[] | select(.path_with_namespace|test("'${filter}'")) | .id'` | |
if [ "$1" == "protect" ]; then | |
# protecc | |
for i in $all_project_ids; do | |
curl --request POST --header "PRIVATE-TOKEN: ${gitlab_access}"\ | |
"https://gitlab.com/api/v4/projects/${i}/protected_branches?name=master&push_access_level=30&merge_access_level=30&unprotect_access_level=40" | |
done | |
fi | |
if [ "$1" == "unprotect" ]; then | |
# unprotecc | |
for i in $all_project_ids; do | |
curl --request DELETE --header "PRIVATE-TOKEN: ${gitlab_access}"\ | |
"https://gitlab.com/api/v4/projects/${i}/protected_branches/master" | |
done | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment