Skip to content

Commit

Permalink
feat: Use a single request for latest-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Jul 24, 2023
1 parent ba2aa33 commit 509f004
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
3 changes: 1 addition & 2 deletions bin/latest-stable
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
# shellcheck source=../lib/utils.bash
. "${plugin_dir}/lib/utils.bash"

latest_release_tag=$(gh_query "releases/latest" | tag_names)
version="$(list_assets "$latest_release_tag" | sort_versions | tail -n1 | xargs echo)"
version="$(list_all_versions | tail -n1 | xargs echo)"

printf "%s\n" "$version"
4 changes: 1 addition & 3 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
# shellcheck source=../lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

# The releases response also includes all the assets, so we can just use that
# instead of querying the assets for each release separately
gh_query "releases" | get_versions | sort_versions | xargs echo
list_all_versions | xargs echo
31 changes: 10 additions & 21 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,16 @@ gh_query() {
"https://api.github.com/repos/$OWNER/$REPO/$url_rest" || fail "Could not curl $url_rest"
}

# Get the tag names from a list of releases (or a single release) provided by
# the GitHub API. Reads from stdin.
tag_names() {
grep -oE '"tag_name": "[^"]*"' | cut -d '"' -f 4
}

get_versions() {
grep -oE '"name": "[0-9]+\.[0-9]+-[0-9]+\.[0-9]+\.[0-9]+"' | # Must not be an M0 version
cut -d '"' -f 4 | # Extract the asset name
uniq
}

# Given a tag, list its scala-ammonite versions
list_assets() {
local release_id
release_id=$(gh_query "releases/tags/$1" |
grep -oE '"id": [0-9]+' |
cut -d ':' -f 2 |
sed -E "s/(^ +)|\"//g" | # Trim
head -n 1)
gh_query "releases/$release_id/assets" | get_versions
list_all_versions() {
# The releases response also includes all the assets, so we can just use that
# instead of querying the assets for each release separately
gh_query "releases" |
# Must not be an M0 version
grep -oE '"name": "[0-9]+\.[0-9]+-[0-9]+\.[0-9]+\.[0-9]+"' |
# Extract the asset names
cut -d '"' -f 4 |
uniq |
sort_versions
}

download_release() {
Expand Down

0 comments on commit 509f004

Please sign in to comment.