Skip to content

Instantly share code, notes, and snippets.

@sonic2kk
Created November 10, 2022 01:35
Show Gist options
  • Save sonic2kk/e0b53de05c07cae3fd719c46c1ec96b3 to your computer and use it in GitHub Desktop.
Save sonic2kk/e0b53de05c07cae3fd719c46c1ec96b3 to your computer and use it in GitHub Desktop.
Bash function for fetching last N tags from GitHub repo
#!/usr/bin/env bash
GHURL="https://github.com"
WGET="wget"
function fetchGitHubTags {
PROJURL="$1"
N="$2"
RELEASESURL="${PROJURL}/releases"
TAGSURL="${PROJURL}/tags"
TAGSGREP="${RELEASESURL#"$GHURL"}/tag"
mapfile -t BASETAGS < <("$WGET" -q "${TAGSURL}" -O - 2> >(grep -v "SSL_INIT") | grep -oE "${TAGSGREP}[^\"]+" | sort -urV | grep -m "$N" "$TAGSGREP")
for TAG in "${BASETAGS[@]}"; do
basename "$TAG"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment