The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.3 KiB

  1. #!/bin/bash
  2. set -euo pipefail
  3. if [[ $# -ne 1 || "$1" == '-h' || "$1" == '--help' ]]
  4. then
  5. echo "Usage: $0 USER_OR_GROUP_NAME" >&2
  6. exit 1
  7. fi
  8. name="$1"
  9. scriptpath="$(cd "$(dirname "$0")"; pwd -P)"
  10. page="$("${scriptpath}/curl-ua" firefox -s "https://gitlab.com/${name}")"
  11. if grep -q -F '<a data-target="div#activity" data-action="activity" data-toggle="tab" href="' <<<"${page}"
  12. then
  13. echo "User" >&2
  14. url="https://gitlab.com/api/v4/users/${name}/projects?per_page=100"
  15. elif grep -q -F '<li class="home active"><a title="Group details" href="' <<<"${page}"
  16. then
  17. echo "Group" >&2
  18. url="https://gitlab.com/api/v4/groups/${name}/projects?per_page=100&include_subgroups=true"
  19. else
  20. echo "Error: unknown page type" >&2
  21. exit 1
  22. fi
  23. {
  24. pipe=$(mktemp -u); mkfifo "${pipe}"; exec 3<>"${pipe}"; rm "${pipe}"; unset pipe # For the disgusting HTTP header treatment
  25. "${scriptpath}/curl-ua" firefox -sv "${url}" 2> >(grep '^< x-total-pages: ' | sed 's,^.*: ,,' | tr -d '\r' >&3)
  26. declare -i nPages=$(head -1 <&3)
  27. if [[ ${nPages} -ge 2 ]]
  28. then
  29. for ((page=2; page<=${nPages}; ++page))
  30. do
  31. echo -n $'\r'"Requesting page ${page} of ${nPages}" >&2
  32. "${scriptpath}/curl-ua" firefox -s "${url}&page=${page}"
  33. done
  34. echo >&2
  35. fi
  36. } | grep -Po '"path_with_namespace":\s*"\K[^"]+' | sed 's,^,https://gitlab.com/,'