Browse Source

Add script for listing repos of a user or group on GitLab.com

master
JustAnotherArchivist 1 month ago
parent
commit
22744fe908
1 changed files with 40 additions and 0 deletions
  1. +40
    -0
      gitlab.com-list-repos

+ 40
- 0
gitlab.com-list-repos View File

@@ -0,0 +1,40 @@
#!/bin/bash
set -euo pipefail

if [[ $# -ne 1 || "$1" == '-h' || "$1" == '--help' ]]
then
echo "Usage: $0 USER_OR_GROUP_NAME" >&2
exit 1
fi
name="$1"

scriptpath="$(cd "$(dirname "$0")"; pwd -P)"

page="$("${scriptpath}/curl-ua" firefox -s "https://gitlab.com/${name}")"
if grep -q -F '<a data-target="div#activity" data-action="activity" data-toggle="tab" href="' <<<"${page}"
then
echo "User" >&2
url="https://gitlab.com/api/v4/users/${name}/projects?per_page=100"
elif grep -q -F '<li class="home active"><a title="Group details" href="' <<<"${page}"
then
echo "Group" >&2
url="https://gitlab.com/api/v4/groups/${name}/projects?per_page=100&include_subgroups=true"
else
echo "Error: unknown page type" >&2
exit 1
fi

{
pipe=$(mktemp -u); mkfifo "${pipe}"; exec 3<>"${pipe}"; rm "${pipe}"; unset pipe # For the disgusting HTTP header treatment
"${scriptpath}/curl-ua" firefox -sv "${url}" 2> >(grep '^< x-total-pages: ' | sed 's,^.*: ,,' | tr -d '\r' >&3)
declare -i nPages=$(head -1 <&3)
if [[ ${nPages} -ge 2 ]]
then
for ((page=2; page<=${nPages}; ++page))
do
echo -n $'\r'"Requesting page ${page} of ${nPages}" >&2
"${scriptpath}/curl-ua" firefox -s "${url}&page=${page}"
done
echo >&2
fi
} | grep -Po '"path_with_namespace":\s*"\K[^"]+' | sed 's,^,https://gitlab.com/,'

Loading…
Cancel
Save