usethis icon indicating copy to clipboard operation
usethis copied to clipboard

Update expected paths in `use_rscloud_badge()`

Open gvelasq opened this issue 1 year ago • 0 comments

I recently learned that the default paths for RStudio Cloud projects, both for individual projects and for projects inside shared spaces, have been changed such that the word content is now used instead of project in the path. As far as I can tell, this is an undocumented change.

# old
https://rstudio.cloud/project/<project-id>
https://rstudio.cloud/spaces/<space-id>/project/<project-id>

# new
https://rstudio.cloud/content/<project-id>
https://rstudio.cloud/spaces/<space-id>/content/<project-id>

This is a breaking change for the function I contributed in #1584 and #1589, use_rscloud_badge(), which expects that paths passed via the url argument will include project. While valid paths that use project will be redirected by RStudio Cloud to the same path using content instead, all new paths obtained from RStudio Cloud, via the dropdown (...) > Share Project Link or from copy/pasting the URL, will use content and thus will cause use_rscloud_badge() to return an error:

library(httr2)
library(usethis)
library(withr)

# 1. define helper function ----
check_rscloud_url <- function(url) {
  req_perform(request(url))
}

# 2. confirm 'project' containing url is a valid url ----
project_url <- "https://rstudio.cloud/project/3584129"
check_rscloud_url(project_url)
#> <httr2_response>
#> GET https://rstudio.cloud/project/3584129
#> Status: 200 OK
#> Content-Type: text/html
#> Body: In memory (643 bytes)

# 3. confirm 'content' containing url is a valid url ----
content_url <- "https://rstudio.cloud/content/3584129"
check_rscloud_url(content_url)
#> <httr2_response>
#> GET https://rstudio.cloud/content/3584129
#> Status: 200 OK
#> Content-Type: text/html
#> Body: In memory (643 bytes)

# 4. confirm use_rscloud_badge(content_url) returns an error ----
with_tempdir({
  create_project(tempdir())
  use_readme_md()
  use_rscloud_badge(content_url)
})
#> ✔ Setting active project to '/private/var/folders/qf/
#> yt27gctx33x4pvc255t0w9zc0000gp/T/RtmpggYsT7'
#> ✔ Creating 'R/'
#> ✔ Writing a sentinel file '.here'
#> • Build robust paths within your project via `here::here()`
#> • Learn more at <https://here.r-lib.org>
#> ✔ Setting active project to '<no active project>'
#> ✔ Setting active project to '/private/var/folders/qf/yt27gctx33x4pvc255t0w9zc0000gp/T/RtmpggYsT7'
#> ✔ Writing 'README.md'
#> Error: `usethis::use_rscloud_badge()` requires a link to an existing RStudio Cloud project of the form 'https://rstudio.cloud/project/<project-id>' or 'https://rstudio.cloud/spaces/<space-id>/project/<project-id>'.

Created on 2022-09-09 with reprex v2.0.2

This would be a relatively easy fix and I'd be happy to submit a PR if helpful. One question for the maintainers would be, since paths that contain project are still technically valid URLs, should we soft deprecate the use of paths containing project or should we require that all paths use content moving forward?

gvelasq avatar Sep 10 '22 06:09 gvelasq