Skip to content

Instantly share code, notes, and snippets.

@joshjohanning
Last active March 30, 2023 18:09
Show Gist options
  • Save joshjohanning/63c2d7d1085fb0230b485b6129374dac to your computer and use it in GitHub Desktop.
Save joshjohanning/63c2d7d1085fb0230b485b6129374dac to your computer and use it in GitHub Desktop.
export gitlab merge requests
#!/bin/bash
# credits @tspascoal
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <project_id> - obtain the numeric project ID from the project/repo's home page"
exit 1
fi
if [ -z "$GL_TOKEN" ]; then
echo "define GL_TOKEN env var ie: export GL_TOKEN=glpat_abc"
exit 1
fi
PROJECT_ID=$1
PAGE=1
while true
do
URL="https://gitlab.example.com/api/v4/projects/$PROJECT_ID/merge_requests?per_page=100&page=$PAGE"
RESPONSE=$(curl -s --header "PRIVATE-TOKEN: $GL_TOKEN" $URL)
echo "$RESPONSE" | jq -r -c '.[] | { id, description, web_url}'
# 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