Created
April 2, 2020 19:17
-
-
Save rtyler/7d4a03dcc1dbc513c04c9e5a431c367c to your computer and use it in GitHub Desktop.
Generate a CSV dump of project information 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 | |
# | |
# This script can be used as a starting point for generating a spreadsheet of | |
# GitLab projects, with their properties, from an existing GitLab instance | |
# | |
# You must set a GitLab access token via the GITLAB_TOKEN env variable | |
# | |
# Invoke with ./gitlab-to-csv.sh <gitlab hostname> | |
FILENAME=projects.csv | |
echo "path,archived,namespace_kind" > ${FILENAME} | |
for i in $(seq 1 100); do | |
echo ">> Fetching page ${i}.." | |
curl --silent --fail \ | |
-o - \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${GITLAB_TOKEN}" \ | |
"https://${1}/api/v4/projects?per_page=100&page=${i}" \ | |
| jq -e -r ".[] | [.path_with_namespace, .archived, .namespace.kind] | @csv" \ | |
>> ${FILENAME} | |
if [ $? -ne 0 ]; then | |
echo ">> Exiting after $i pages, $(wc -l $FILENAME) written to ${FILENAME}"; | |
exit; | |
fi; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment