Skip to content

Commit

Permalink
Check for SHA's existence
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Dec 17, 2021
1 parent 1bb32d7 commit eec44c8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,16 @@ use_github_release <- function(host = deprecated(),
}

dat <- get_release_data(tr)
news <- get_release_news(SHA = dat$SHA, tr = tr)

release_name <- glue("{dat$Package} {dat$Version}")
tag_name <- glue("v{dat$Version}")
kv_line("Release name", release_name)
kv_line("Tag name", tag_name)
kv_line("SHA", dat$SHA)

check_github_has_SHA(SHA = dat$SHA, tr = tr)

news <- get_release_news(SHA = dat$SHA, tr = tr)

gh <- gh_tr(tr)
release <- gh(
"POST /repos/{owner}/{repo}/releases",
Expand Down Expand Up @@ -271,6 +273,24 @@ get_release_data <- function(tr = target_repo(github_get = TRUE)) {
out
}

check_github_has_SHA <- function(SHA = gert::git_info(repo = git_repo())$commit,
tr = target_repo(github_get = TRUE)) {
safe_gh <- purrr::safely(gh_tr(tr))
SHA_GET <- safe_gh(
"/repos/{owner}/{repo}/git/commits/{commit_sha}",
commit_sha = SHA
)
if (is.null(SHA_GET$error)) {
return()
}
if (inherits(SHA_GET$error, "http_error_404")) {
ui_stop("
Can't find SHA {ui_value(substr(SHA, 1, 7))} in {ui_value(tr$repo_spec)}.
Do you need to push?")
}
ui_stop("Internal error: Unexpected error when checking for SHA on GitHub")
}

get_release_news <- function(SHA = gert::git_info(repo = git_repo())$commit,
tr = target_repo(github_get = TRUE)) {
package <- package_data()
Expand Down

0 comments on commit eec44c8

Please sign in to comment.