diff --git a/NEWS.md b/NEWS.md index 73c129872..e4ebb3786 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,7 @@ on the Connect server. (#272, #447) - New `lock_content()` and `unlock_content()` functions for locking and unlocking content items. (#453) +- Updated git-backed deployment functions to use v1 APIs (#459) # connectapi 0.8.0 diff --git a/R/content.R b/R/content.R index f3a1eef6d..794506c26 100644 --- a/R/content.R +++ b/R/content.R @@ -63,11 +63,6 @@ Content <- R6::R6Class( url <- v1_url("content", self$content$guid, "bundles", bundle_id) self$connect$DELETE(url) }, - #' @description Get this (remote) content item. - internal_content = function() { - url <- unversioned_url("applications", self$content$guid) - self$connect$GET(url) - }, #' @description Update this content item. #' @param ... Content fields. update = function(...) { @@ -161,18 +156,13 @@ Content <- R6::R6Class( #' @param key The job key. job = function(key) { warn_experimental("job") - url <- unversioned_url( - "applications", - self$content$guid, - "job", - key - ) + guid <- self$content$guid + url <- unversioned_url("applications", guid, "job", key) res <- self$connect$GET(url) - content_guid <- self$content$guid purrr::map( list(res), - ~ purrr::list_modify(.x, app_guid = content_guid) + ~ purrr::list_modify(.x, app_guid = guid) )[[1]] }, #' @description Terminate a single job for this content item. @@ -189,11 +179,8 @@ Content <- R6::R6Class( #' @description Return the variants for this content. variants = function() { warn_experimental("variants") - url <- unversioned_url( - "applications", - self$content$guid, - "variants" - ) + guid <- self$content$guid + url <- unversioned_url("applications", guid, "variants") self$connect$GET(url) }, #' @description Set a tag for this content. @@ -330,29 +317,60 @@ Content <- R6::R6Class( body = body ) }, + #' @description Get Git repository details + #' @return NULL if no repo is set, otherwise a list with fields: + #' - repository + #' - branch + #' - directory + #' - polling + #' - last_error + #' - last_known_commit + repository = function() { + con <- self$connect + error_if_less_than(con$version, "2022.10.0") + guid <- self$content$guid + resp <- con$GET( + v1_url("content", guid, "repository"), + parser = NULL + ) + if (httr::status_code(resp) == 404) { + # 404 means there is no repository set + return(NULL) + } + con$raise_error(resp) + httr::content(resp, as = "parsed") + }, #' @description Adjust Git polling. - #' @param enabled Polling enabled. - repo_enable = function(enabled = TRUE) { - warn_experimental("repo_enable") - self$connect$PUT( - unversioned_url("applications", self$content$guid, "repo"), - body = list( - enabled = enabled - ) + #' @param polling Polling enabled. + repo_enable = function(polling = TRUE) { + con <- self$connect + error_if_less_than(con$version, "2022.10.0") + guid <- self$content$guid + con$PATCH( + v1_url("content", guid, "repository"), + body = list(polling = polling) ) }, #' @description Adjust Git repository #' @param repository Git repository URL #' @param branch Git repository branch - #' @param subdirectory Git repository directory - repo_set = function(repository, branch, subdirectory) { - warn_experimental("repo_set") - self$connect$POST( - unversioned_url("applications", self$content$guid, "repo"), + #' @param directory Git repository directory + #' @param polling Whether to check for updates + repo_set = function( + repository, + branch = "main", + directory = ".", + polling = FALSE + ) { + guid <- self$content$guid + error_if_less_than(self$connect$version, "2022.10.0") + self$connect$PUT( + v1_url("content", guid, "repository"), body = list( repository = repository, branch = branch, - subdirectory = subdirectory + directory = directory, + polling = polling ) ) }, diff --git a/R/git.R b/R/git.R index 4837299c1..6c8af65c6 100644 --- a/R/git.R +++ b/R/git.R @@ -117,7 +117,6 @@ deploy_repo <- function( ... ) { validate_R6_class(client, "Connect") - warn_experimental("deploy_repo") content_metadata <- content_ensure( connect = client, @@ -131,7 +130,7 @@ deploy_repo <- function( deployed_content$repo_set( repository = repository, branch = branch, - subdirectory = subdirectory + directory = subdirectory ) task <- deployed_content$deploy() @@ -143,48 +142,36 @@ deploy_repo <- function( #' @export deploy_repo_enable <- function(content, enabled = TRUE) { validate_R6_class(content, "Content") - warn_experimental("deploy_repo_enable") - invisible(content$repo_enable(enabled)) - invisible(content$get_content_remote()) - return(content) + content$repo_enable(enabled) + content$get_content_remote() + content } #' @rdname deploy_repo #' @export deploy_repo_update <- function(content) { validate_R6_class(content, "Content") - warn_experimental("deploy_repo_update") - scoped_experimental_silence() con <- content$connect - internal_meta <- content$internal_content() - repo_data <- tryCatch( - { - internal_meta$git - }, - error = function(e) { - message(e) - return(NULL) - } - ) + repo_data <- content$repository() if (is.null(repo_data)) { stop(glue::glue( - "Content item '{internal_meta$guid}' is not git-backed content" + "Content item '{content$content$guid}' is not git-backed content" )) } - branch_status <- repo_check_branches_ref(con, repo_data$repository_url) + branch_status <- repo_check_branches_ref(con, repo_data$repository) if (!repo_data$branch %in% names(branch_status)) { stop(glue::glue( - "Branch '{repo_data$branch}' was no longer found on repository '{repo_data$repository_url}'" + "Branch '{repo_data$branch}' was no longer found on repository '{repo_data$repository}'" )) } if ( identical(repo_data$last_known_commit, branch_status[[repo_data$branch]]) ) { message(glue::glue( - "No changes were found in the Git repository: {repo_data$repository_url}@{repo_data$branch}" + "No changes were found in the Git repository: {repo_data$repository}@{repo_data$branch}" )) return(content) } diff --git a/R/variant.R b/R/variant.R index a526f3946..17cb55d19 100644 --- a/R/variant.R +++ b/R/variant.R @@ -87,12 +87,8 @@ Variant <- R6::R6Class( #' @param guid User GUID. remove_subscriber = function(guid) { warn_experimental("subscribers") - path <- unversioned_url( - "variants", - self$variant$id, - "subscribers", - guid - ) + id <- self$variant$id + path <- unversioned_url("variants", id, "subscribers", guid) self$connect$DELETE(path) }, #' @description Add named subscribers. diff --git a/man/Content.Rd b/man/Content.Rd index b2d9656b1..c10a910aa 100644 --- a/man/Content.Rd +++ b/man/Content.Rd @@ -52,7 +52,6 @@ Other R6 classes: \item \href{#method-Content-get_bundles}{\code{Content$get_bundles()}} \item \href{#method-Content-bundle_download}{\code{Content$bundle_download()}} \item \href{#method-Content-bundle_delete}{\code{Content$bundle_delete()}} -\item \href{#method-Content-internal_content}{\code{Content$internal_content()}} \item \href{#method-Content-update}{\code{Content$update()}} \item \href{#method-Content-danger_delete}{\code{Content$danger_delete()}} \item \href{#method-Content-get_url}{\code{Content$get_url()}} @@ -72,6 +71,7 @@ Other R6 classes: \item \href{#method-Content-environment_set}{\code{Content$environment_set()}} \item \href{#method-Content-environment_all}{\code{Content$environment_all()}} \item \href{#method-Content-deploy}{\code{Content$deploy()}} +\item \href{#method-Content-repository}{\code{Content$repository()}} \item \href{#method-Content-repo_enable}{\code{Content$repo_enable()}} \item \href{#method-Content-repo_set}{\code{Content$repo_set()}} \item \href{#method-Content-packages}{\code{Content$packages()}} @@ -159,16 +159,6 @@ Delete a content bundle. } \if{html}{\out{}} } -} -\if{html}{\out{
connectapi::Content$get_content_remote()connectapi::Content$get_dashboard_url()connectapi::Content$get_url()connectapi::Content$internal_content()connectapi::Content$job()connectapi::Content$jobs()connectapi::Content$packages()connectapi::Content$register_job_kill_order()connectapi::Content$repo_enable()connectapi::Content$repo_set()connectapi::Content$repository()connectapi::Content$tag_delete()connectapi::Content$tag_set()connectapi::Content$tags()connectapi::Content$get_content_remote()connectapi::Content$get_dashboard_url()connectapi::Content$get_url()connectapi::Content$internal_content()connectapi::Content$job()connectapi::Content$jobs()connectapi::Content$packages()connectapi::Content$register_job_kill_order()connectapi::Content$repo_enable()connectapi::Content$repo_set()connectapi::Content$repository()connectapi::Content$tag_delete()connectapi::Content$tag_set()connectapi::Content$tags()connectapi::Content$get_content_remote()connectapi::Content$get_dashboard_url()connectapi::Content$get_url()connectapi::Content$internal_content()connectapi::Content$job()connectapi::Content$jobs()connectapi::Content$packages()connectapi::Content$register_job_kill_order()connectapi::Content$repo_enable()connectapi::Content$repo_set()connectapi::Content$repository()connectapi::Content$tag_delete()connectapi::Content$tag_set()connectapi::Content$tags()connectapi::Content$environment_set()connectapi::Content$get_bundles()connectapi::Content$get_content_remote()connectapi::Content$internal_content()connectapi::Content$packages()connectapi::Content$permissions()connectapi::Content$permissions_add()connectapi::Content$register_job_kill_order()connectapi::Content$repo_enable()connectapi::Content$repo_set()connectapi::Content$repository()connectapi::Content$tag_delete()connectapi::Content$tag_set()connectapi::Content$tags()connectapi::Content$environment_set()connectapi::Content$get_bundles()connectapi::Content$get_content_remote()connectapi::Content$internal_content()connectapi::Content$packages()connectapi::Content$permissions()connectapi::Content$permissions_add()connectapi::Content$register_job_kill_order()connectapi::Content$repo_enable()connectapi::Content$repo_set()connectapi::Content$repository()connectapi::Content$tag_delete()connectapi::Content$tag_set()connectapi::Content$tags()connectapi::Content$environment_set()connectapi::Content$get_bundles()connectapi::Content$get_content_remote()connectapi::Content$internal_content()connectapi::Content$packages()connectapi::Content$permissions()connectapi::Content$permissions_add()connectapi::Content$register_job_kill_order()connectapi::Content$repo_enable()connectapi::Content$repo_set()connectapi::Content$repository()connectapi::Content$tag_delete()connectapi::Content$tag_set()connectapi::Content$tags()