Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added trigger list #185

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# googleCloudRunner 0.5.0.9000

* ...
* Added `full` flag argument to `cr_buildtrigger_list` to return a column `build`, which is a list of the builds.

# googleCloudRunner 0.5.0

Expand Down
22 changes: 19 additions & 3 deletions R/buildtriggers.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ cr_buildtrigger_delete <- function(triggerId, projectId = cr_project_get()) {
#'
#' @family BuildTrigger functions
#' @param projectId ID of the project for which to list BuildTriggers
#' @param full Return the trigger list with the build information from
#' \code{\link{cr_buildtrigger_get}}
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @seealso \link{cr_build_list} which merges with this list
Expand All @@ -120,7 +122,8 @@ cr_buildtrigger_delete <- function(triggerId, projectId = cr_project_get()) {
#'
#' cr_buildtrigger_list()
#' }
cr_buildtrigger_list <- function(projectId = cr_project_get()) {
cr_buildtrigger_list <- function(projectId = cr_project_get(),
full = FALSE) {
url <- sprintf(
"https://cloudbuild.googleapis.com/v1/projects/%s/triggers",
projectId
Expand All @@ -142,24 +145,37 @@ cr_buildtrigger_list <- function(projectId = cr_project_get()) {

parse_files <- function(x) {
if (is.null(bts_df[[x]])) {
return(NA)
return(rep(NA, length = nrow(bts_df)))
}
unlist(lapply(bts_df[[x]], paste, collapse = ", "))
}

data.frame(
df <- data.frame(
stringsAsFactors = FALSE,
buildTriggerName = bts_df$name,
buildTriggerId = bts_df$id,
buildTriggerCreateTime = bts_df$createTime,
filename = bts_df$filename,
filename = if (is.null(bts_df$filename)) rep(NA, nrow(bts_df)) else bts_df$filename,
description = bts_df$description,
github_name = paste0(bts_df$github$owner, "/", bts_df$github$name),
ignoredFiles = parse_files("ignoredFiles"),
includedFiles = parse_files("includedFiles"),
tags = parse_files("tags"),
disabled = if (!is.null(bts_df$disabled)) bts_df$disabled else NA
)
if (full) {
if (NROW(df) == 0 || length(df) == 0) return(NULL)
trigger_data <- lapply(df$buildTriggerId, function(triggerId) {
x <- cr_buildtrigger_get(triggerId = triggerId,
projectId = projectId)
data.frame(buildTriggerId = triggerId, build = I(list(x)),
stringsAsFactors = FALSE)
})
trigger_data <- do.call(rbind, trigger_data)
df <- merge(df, trigger_data, all = TRUE, sort = FALSE)
}
df
}

parse_buildtrigger_list <- function(x) {
Expand Down
5 changes: 4 additions & 1 deletion man/cr_buildtrigger_list.Rd

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

11 changes: 11 additions & 0 deletions tests/testthat/test-triggers.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ test_that("[Online] Test Build Triggers", {
info <- cr_buildtrigger_get("0a3cade0-425f-4adc-b86b-14cde51af674")
expect_equal(info$name, "package-checks")
})

test_that("[Online] Test Build Triggers with Builds", {
skip_on_ci()
skip_on_cran()

the_list <- cr_buildtrigger_list(full = TRUE)
expect_true("build" %in% names(the_list))
if (nrow(the_list) > 0) {
expect_true(is.list(the_list$build))
}
})