Created
March 31, 2023 18:50
-
-
Save joshjohanning/fbeaa2e85dd250579e868f7cdbb3a5db to your computer and use it in GitHub Desktop.
export group members from gitlab
This file contains 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 | |
# usage: | |
# ./gitlab-export-users-in-group.sh 2 > users.csv | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <group_id> - obtain from the overview page of your group" | |
exit 1 | |
fi | |
if [ -z "$GL_TOKEN" ]; then | |
echo "define GL_TOKEN env var" | |
exit 1 | |
fi | |
echo "source,target" | |
PROJECT_ID=$1 | |
PAGE=1 | |
while true | |
do | |
URL="https://joshjohanning-refactored-space-broccoli-4j4vwg549593jr57-80.preview.app.github.dev/api/v4/groups/$PROJECT_ID/members?per_page=100&page=$PAGE" | |
RESPONSE=$(curl -s --header "PRIVATE-TOKEN: $GL_TOKEN" $URL) | |
echo "$RESPONSE" | jq '.[].username' | tr -d '"' | sed 's/$/,/' | |
# Break loop when there are no more pages | |
if [ "$RESPONSE" = "[]" ] | |
then | |
break | |
fi | |
PAGE=$((PAGE+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment