Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
82 changes: 50 additions & 32 deletions R/content.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...) {
Expand Down Expand Up @@ -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.
Expand All @@ -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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just reformatting so that I can see the whole URL on one line--helps to grep the repo to find the remaining v0 endpoints in use.

self$connect$GET(url)
},
#' @description Set a tag for this content.
Expand Down Expand Up @@ -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
)
)
},
Expand Down
31 changes: 9 additions & 22 deletions R/git.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ deploy_repo <- function(
...
) {
validate_R6_class(client, "Connect")
warn_experimental("deploy_repo")

content_metadata <- content_ensure(
connect = client,
Expand All @@ -131,7 +130,7 @@ deploy_repo <- function(
deployed_content$repo_set(
repository = repository,
branch = branch,
subdirectory = subdirectory
directory = subdirectory
)

task <- deployed_content$deploy()
Expand All @@ -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)
}
Expand Down
8 changes: 2 additions & 6 deletions R/variant.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 28 additions & 15 deletions man/Content.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ContentTask.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/EnvironmentR6.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/Vanity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading