Skip to content

Commit

Permalink
refactor: replace httr with httr2 (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Oct 2, 2023
2 parents dc005fd + 4b603bf commit 12fb287
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Imports:
desc (>= 1.4.1),
devtools,
glue,
httr,
httr2,
lifecycle,
pandoc,
purrr (>= 0.3.2),
Expand Down
4 changes: 2 additions & 2 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ confirm_submission <- function(url) {
}

get_confirm_url <- function(url) {
parsed <- httr::parse_url(url)
parsed <- httr2::url_parse(url)

parsed$query$policy_check2 <- "on"
parsed$query$policy_check3 <- "on"
Expand All @@ -357,7 +357,7 @@ get_confirm_url <- function(url) {
}
parsed$query$confirm_submit <- utils::URLencode("Upload Package to CRAN")

httr::build_url(parsed)
httr2::url_build(parsed)
}

#' @description
Expand Down
2 changes: 1 addition & 1 deletion R/parse-news-items.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ harvest_pr_data <- function(message) {
}

has_internet <- function() {
# impossible as fledge imports httr that imports curl :-)
# impossible as fledge imports httr2 that imports curl :-)
if (!rlang::is_installed("curl")) {
return(FALSE)
}
Expand Down
29 changes: 19 additions & 10 deletions R/submit.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,36 @@ upload_cran <- function(pkg, built_path) {

# Initial upload ---------
cli::cli_alert_info("Uploading package & comments")

# impossible as fledge imports httr2 that imports curl :-)
if (!rlang::is_installed("curl")) {
cli::cli_abort("Must install the curl package")
}
body <- list(
pkg_id = "",
name = maint_name,
email = maint_email,
uploaded_file = httr::upload_file(built_path, "application/x-gzip"),
uploaded_file = curl::form_file(built_path, type = "application/x-gzip"),
comment = comments,
upload = "Upload package"
)
r <- httr::POST(cran_submission_url, body = body)
r <- httr2::request(cran_submission_url) %>%
httr2::req_body_multipart(!!!body) %>%
httr2::req_perform()

# If a 404 likely CRAN is closed for maintenance, try to get the message
if (httr::status_code(r) == 404) {
if (httr2::resp_status(r) == 404) {
msg <- ""
try({
r2 <- httr::GET(sub("index2", "index", cran_submission_url))
msg <- extract_cran_msg(httr::content(r2, "text"))
r2 <- httr2::request(sub("index2", "index", cran_submission_url)) %>%
httr2::req_perform()
msg <- extract_cran_msg(httr2::resp_body_string(r2))
})
stop("Submission failed:", msg, call. = FALSE)
}

httr::stop_for_status(r)
new_url <- httr::parse_url(r$url)
httr2::resp_check_status(r)
new_url <- httr2::url_parse(r$url)

# Confirmation -----------
cli::cli_alert_info("Confirming submission")
Expand All @@ -99,9 +107,10 @@ upload_cran <- function(pkg, built_path) {
policy_check = "1/",
submit = "Submit package"
)
r <- httr::POST(cran_submission_url, body = body)
httr::stop_for_status(r)
new_url <- httr::parse_url(r$url)
r <- httr2::request(cran_submission_url) %>%
httr2::req_body_multipart(!!!body)
httr2::resp_check_status(r)
new_url <- httr2::url_parse(r$url)
if (new_url$query$submit == "1") {
cli::cli_alert_success("Package submission successful")
cli::cli_alert_info("Check your email for confirmation link.")
Expand Down

0 comments on commit 12fb287

Please sign in to comment.