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.
 
 

60 lines
1.7 KiB

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