Skip to content

Instantly share code, notes, and snippets.

@rtyler
Created April 2, 2020 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtyler/7d4a03dcc1dbc513c04c9e5a431c367c to your computer and use it in GitHub Desktop.
Save rtyler/7d4a03dcc1dbc513c04c9e5a431c367c to your computer and use it in GitHub Desktop.
Generate a CSV dump of project information from GitLab
#!/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