Skip to content

Commit

Permalink
use github-latest release as "latest" (#114)
Browse files Browse the repository at this point in the history
Closes #113.

piggyback's "latest" adjusted to match github's definition of latest
  • Loading branch information
tanho63 authored Dec 29, 2023
1 parent f970fd5 commit ee4c797
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ provides the code to create the release in the error body.
* `pb_download()` now tries to uses browser download URLs (i.e. `pb_download_url()`)
before trying API download URLs. This should reduce/eliminate effect of API rate
limits for pb_download. [#109]
* `"latest"` release now aligns with GitHub's "latest" release definition [#113]

# piggyback 0.1.5

Expand Down
16 changes: 14 additions & 2 deletions R/pb_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ pb_releases <- function(repo = guess_repo(),
return(invisible(data.frame()))
}

latest_release <- gh::gh(
"/repos/:owner/:repo/releases/latest",
owner = r[[1]],
repo = r[[2]],
.token = .token
) |>
getElement("tag_name")

out <- data.frame(
release_name = .extract_chr(releases, "name"),
release_id = .extract_int(releases, "id"),
release_body = .extract_chr(releases, "body"),
tag_name = .extract_chr(releases, "tag_name"),
draft = .extract_lgl(releases, "draft"),
latest = .extract_chr(releases, "tag_name") %in% latest_release,
created_at = .extract_chr(releases, "created_at"),
published_at = .extract_chr(releases, "published_at"),
html_url = .extract_chr(releases, "html_url"),
Expand Down Expand Up @@ -140,8 +149,11 @@ pb_info <- function(repo = guess_repo(),
))
}

# if tag is latest, set tag to first tag present in releases
if(identical(tag, "latest") && !"latest" %in% releases$tag_name) tag <- releases$tag_name[[1]]
# if tag is "latest" (and no tag is literally named "latest"), set tag to
# GitHub's idea of latest release tag
if(identical(tag, "latest") && !"latest" %in% releases$tag_name) {
tag <- releases$tag_name[releases$latest]
}

# if tag is present, filter the releases to search to just the tags requested
if(!is.null(tag)) releases <- releases[releases$tag_name %in% tag,]
Expand Down
8 changes: 4 additions & 4 deletions R/pb_upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ pb_upload <- function(file,
releases <- pb_releases(repo = repo,.token = .token)

if(tag == "latest" && length(releases$tag_name) > 0 && !"latest" %in% releases$tag_name) {
tag <- releases$tag_name[releases$latest]
if(getOption("piggyback.verbose", default = interactive())){
cli::cli_alert_info("Uploading to latest release: {.val {releases$tag_name[[1]]}}.")
cli::cli_alert_info("Uploading to latest release: {.val {tag}}.")
}
tag <- releases$tag_name[[1]]
}

if(!tag %in% releases$tag_name) {
Expand Down Expand Up @@ -83,8 +83,8 @@ pb_upload <- function(file,
}

pb_upload_file <- function(file,
repo = guess_repo(),
tag = "latest",
repo,
tag,
name = NULL,
overwrite = "use_timestamps",
use_timestamps = NULL,
Expand Down

0 comments on commit ee4c797

Please sign in to comment.