Skip to content

Instantly share code, notes, and snippets.

@meriororen
Created September 7, 2020 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meriororen/3eefff64ee42eae8dd095a31c951ef31 to your computer and use it in GitHub Desktop.
Save meriororen/3eefff64ee42eae8dd095a31c951ef31 to your computer and use it in GitHub Desktop.
protect and unprotect all master branches in a group
#!/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