#!/bin/bash -e API='https://gitlab.com/api/v4' function get_tag_urls() { local repo="$1" local tag="$2" curl -sSL "$API/projects/$repo/releases/$tag" | \ jq -r '.assets.links[] | select(.name | test(".apk$")) | .url' } function get_urls() { local repo="$1" curl -sSL "$API/projects/$repo/releases" | \ jq -r '.[0].assets.links[] | select(.name | test(".apk$")) | .url' } function get_repo_name_from_url() { printf '%s' \ "$(grep -Po '(?<=gitlab.com/)[\w\d-]+/[\w\d-]+' <<< "$1")" | \ jq -sRr '@uri' } function main() { local repo; repo="$(get_repo_name_from_url "$1")" local tag="$2" if [ -z "$tag" ]; then get_urls "$repo" else get_tag_urls "$repo" "$tag" fi } main "$@"