Created
October 9, 2019 18:50
-
-
Save djeikyb/b438f04eb6b374ec1e75c346a1d4092e to your computer and use it in GitHub Desktop.
clone all repos in a gitlab 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/sh | |
die() { | |
log "$@" | |
exit 1 | |
} | |
log() { | |
printf "$SELF: %s\n" "$@" >&2 | |
} | |
requireCommand() { | |
command -v $1 >/dev/null 2>&1 || die "'$1' is required, but not found" | |
} | |
requireCommand "jq" | |
requireCommand "curl" | |
token="$1" | |
group="$2" | |
host='http://example.com' | |
url="${host}/api/v4/groups/${group}?private_token=$token" | |
rs_json=$(curl --fail --silent --show-error "$url") | |
[ $? -ne 0 ] && die "gitlab group api call failed" | |
[ -z "$rs_json" ] && die "empty response from gitlab group api" | |
list_repos() { | |
printf '%s' "$1" | jq '.projects[].ssh_url_to_repo' | tr -d '"' | |
[ $? -ne 0 ] && die "failed to process response from gitlab group api" | |
} | |
for repo in $(list_repos "$rs_json"); do | |
git clone "$repo" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on Dinesh Balasubramanian's answer: https://stackoverflow.com/a/56679722/659715