Skip to content

Instantly share code, notes, and snippets.

@djeikyb
Created October 9, 2019 18:50
Show Gist options
  • Save djeikyb/b438f04eb6b374ec1e75c346a1d4092e to your computer and use it in GitHub Desktop.
Save djeikyb/b438f04eb6b374ec1e75c346a1d4092e to your computer and use it in GitHub Desktop.
clone all repos in a gitlab group
#!/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
@djeikyb
Copy link
Author

djeikyb commented Oct 9, 2019

based on Dinesh Balasubramanian's answer: https://stackoverflow.com/a/56679722/659715

for repo in $(curl "https://<your-host>/api/v4/groups/<group_id>?private_token=<your_private_token>" | jq .projects[].ssh_url_to_repo | tr -d '"'); do git clone $repo; done;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment