Skip to content

Commit 02cb257

Browse files
Remove v0 fallbacks
1 parent 6505bc8 commit 02cb257

File tree

2 files changed

+48
-63
lines changed

2 files changed

+48
-63
lines changed

R/content.R

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -326,74 +326,63 @@ Content <- R6::R6Class(
326326
)
327327
},
328328
#' @description Get Git repository details
329-
#' @return a list of repo details, or NULL if no repo is set
329+
#' @return NULL if no repo is set, otherwise a list with fields:
330+
#' - repository
331+
#' - branch
332+
#' - directory
333+
#' - polling
334+
#' - last_error
335+
#' - last_known_commit
330336
repository = function() {
331-
GET <- self$get_connect()$GET
337+
con <- self$get_connect()
332338
guid <- self$get_content()$guid
333-
tryCatch(
334-
# TODO: the v1 API returns 404 if no repo is set, so that means we fall
335-
# back to the other API. The new API was added in October 2022, so maybe
336-
# we just don't fall back.
337-
GET(v1_url("content", guid, "repository")),
338-
error = function(e) {
339-
resp <- GET(unversioned_fallback_url("applications", guid))$git
340-
if (!is.null(resp)) {
341-
# NOTE: the v1 and v0 endpoints don't have identical fields
342-
# Rename to match v1 naming
343-
names(resp)[names(resp) == "repository_url"] <- "repository"
344-
names(resp)[names(resp) == "subdirectory"] <- "directory"
345-
names(resp)[names(resp) == "enabled"] <- "polling"
346-
}
347-
resp
348-
}
339+
resp <- con$GET(
340+
v1_url("content", guid, "repository"),
341+
parser = NULL
349342
)
343+
if (httr::status_code(resp) == 404) {
344+
resp <- NULL
345+
} else {
346+
con$raise_error(resp)
347+
resp <- httr::content(resp, as = "parsed")
348+
}
349+
resp
350350
},
351351
#' @description Adjust Git polling.
352-
#' @param enabled Polling enabled.
353-
repo_enable = function(enabled = TRUE) {
352+
#' @param polling Polling enabled.
353+
repo_enable = function(polling = TRUE) {
354+
con <- self$get_connect()
354355
guid <- self$get_content()$guid
355-
tryCatch(
356-
self$get_connect()$PATCH(
357-
v1_url("content", guid, "repository"),
358-
body = list(
359-
polling = enabled
360-
)
361-
),
362-
error = function(e) {
363-
self$get_connect()$PUT(
364-
unversioned_fallback_url("applications", guid, "repo"),
365-
body = list(
366-
enabled = enabled
367-
)
368-
)
369-
}
356+
resp <- con$PATCH(
357+
v1_url("content", guid, "repository"),
358+
body = list(polling = polling)
370359
)
360+
if (httr::status_code(resp) == 404) {
361+
stop("This content item is not git-backed")
362+
}
363+
con$raise_error(resp)
364+
httr::content(resp, as = "parsed")
371365
},
372366
#' @description Adjust Git repository
373367
#' @param repository Git repository URL
374368
#' @param branch Git repository branch
375-
#' @param subdirectory Git repository directory
376-
repo_set = function(repository, branch, subdirectory) {
369+
#' @param directory Git repository directory
370+
#' @param polling Whether to check for updates
371+
repo_set = function(
372+
repository,
373+
branch = "main",
374+
directory = ".",
375+
polling = FALSE
376+
) {
377377
guid <- self$get_content()$guid
378-
tryCatch(
379-
self$get_connect()$PUT(
380-
v1_url("content", guid, "repository"),
381-
body = list(
382-
repository = repository,
383-
branch = branch,
384-
directory = subdirectory
385-
)
386-
),
387-
error = function(e) {
388-
self$get_connect()$POST(
389-
unversioned_fallback_url("applications", guid, "repo"),
390-
body = list(
391-
repository = repository,
392-
branch = branch,
393-
subdirectory = subdirectory
394-
)
395-
)
396-
}
378+
self$get_connect()$PUT(
379+
v1_url("content", guid, "repository"),
380+
body = list(
381+
repository = repository,
382+
branch = branch,
383+
directory = subdirectory,
384+
polling = polling
385+
)
397386
)
398387
},
399388
#' @description Get package dependencies

R/git.R

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ deploy_repo <- function(
117117
...
118118
) {
119119
validate_R6_class(client, "Connect")
120-
warn_experimental("deploy_repo")
121120

122121
content_metadata <- content_ensure(
123122
connect = client,
@@ -143,19 +142,16 @@ deploy_repo <- function(
143142
#' @export
144143
deploy_repo_enable <- function(content, enabled = TRUE) {
145144
validate_R6_class(content, "Content")
146-
warn_experimental("deploy_repo_enable")
147145

148-
invisible(content$repo_enable(enabled))
149-
invisible(content$get_content_remote())
150-
return(content)
146+
content$repo_enable(enabled)
147+
content$get_content_remote()
148+
content
151149
}
152150

153151
#' @rdname deploy_repo
154152
#' @export
155153
deploy_repo_update <- function(content) {
156154
validate_R6_class(content, "Content")
157-
warn_experimental("deploy_repo_update")
158-
scoped_experimental_silence()
159155

160156
con <- content$get_connect()
161157
repo_data <- content$repository()

0 commit comments

Comments
 (0)