From 884119b06421b2bbe6258177631562db06520be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 25 Sep 2023 10:45:20 +0200 Subject: [PATCH 1/2] refactor: replace httr with httr2 --- DESCRIPTION | 2 +- R/auto.R | 4 ++-- R/parse-news-items.R | 2 +- R/submit.R | 29 +++++++++++++++++++---------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index df6880cf7..a8443564d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,7 @@ Imports: desc (>= 1.4.1), devtools, glue, - httr, + httr2, lifecycle, pandoc, purrr (>= 0.3.2), diff --git a/R/auto.R b/R/auto.R index 3f826ed78..3a435caf5 100644 --- a/R/auto.R +++ b/R/auto.R @@ -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" @@ -357,7 +357,7 @@ get_confirm_url <- function(url) { } parsed$query$confirm_submit <- utils::URLencode("Upload Package to CRAN") - httr::build_url(parsed) + httr::url_build(parsed) } #' @description diff --git a/R/parse-news-items.R b/R/parse-news-items.R index c641fef3b..fa321d2ea 100644 --- a/R/parse-news-items.R +++ b/R/parse-news-items.R @@ -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) } diff --git a/R/submit.R b/R/submit.R index 37003d575..a12aa7f3f 100644 --- a/R/submit.R +++ b/R/submit.R @@ -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") @@ -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.") From 4b603bf7ebbe192ca186f9d7e82f14277d789567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 25 Sep 2023 11:18:14 +0200 Subject: [PATCH 2/2] oops --- R/auto.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/auto.R b/R/auto.R index 3a435caf5..4776e97f6 100644 --- a/R/auto.R +++ b/R/auto.R @@ -357,7 +357,7 @@ get_confirm_url <- function(url) { } parsed$query$confirm_submit <- utils::URLencode("Upload Package to CRAN") - httr::url_build(parsed) + httr2::url_build(parsed) } #' @description