From 3f671e4b830538d3e84d4d6751ace9f9f237c60b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 4 Aug 2022 16:43:22 +0000 Subject: [PATCH 1/3] added allow_regex to help with issue #172 --- R/buildtrigger_objects.R | 21 ++++++++++++++------- R/buildtriggers.R | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/R/buildtrigger_objects.R b/R/buildtrigger_objects.R index a9e09df6..9a9ba085 100644 --- a/R/buildtrigger_objects.R +++ b/R/buildtrigger_objects.R @@ -177,14 +177,19 @@ is.gar_webhookConfig <- function(x) { #' @noRd GitRepoSource <- function(uri, ref, - repoType = c("GITHUB","CLOUD_SOURCE_REPOSITORIES")){ + repoType = c("GITHUB","CLOUD_SOURCE_REPOSITORIES"), + allow_regex = FALSE){ assert_that( is.string(uri), - is.string(ref), - isTRUE(grepl("^refs/", ref)), - !grepl("[^A-Za-z0-9/.]", ref) # regex not allowed + is.string(ref) ) + if (!allow_regex) { + assert_that( + isTRUE(grepl("^refs/", ref)), + !grepl("[^A-Za-z0-9/.]", ref) # regex not allowed + ) + } repoType <- match.arg(repoType) @@ -202,7 +207,7 @@ is.gitRepoSource <- function(x){ inherits(x, "gar_gitRepoSource") } -as.gitRepoSource <- function(x){ +as.gitRepoSource <- function(x, allow_regex = FALSE){ if(!is.buildtrigger_repo(x)){ stop("is not buildtrigger_repo") } @@ -222,7 +227,8 @@ as.gitRepoSource <- function(x){ uri = sprintf("https://github.com/%s/%s", x$repo$owner, x$repo$name), ref = ref, - repoType = "GITHUB" + repoType = "GITHUB", + allow_regex = allow_regex ) ) } @@ -242,7 +248,8 @@ as.gitRepoSource <- function(x){ uri = sprintf("https://source.developers.google.com/p/%s/r/%s", x$repo$projectId, x$repo$repoName), ref = ref, - repoType = "CLOUD_SOURCE_REPOSITORIES" + repoType = "CLOUD_SOURCE_REPOSITORIES", + allow_regex = allow_regex ) ) } diff --git a/R/buildtriggers.R b/R/buildtriggers.R index 6d8fb726..65cd05cb 100644 --- a/R/buildtriggers.R +++ b/R/buildtriggers.R @@ -293,7 +293,7 @@ cr_buildtrigger <- function(build, if (!is.null(sourceToBuild)) { assert_that(is.buildtrigger_repo(sourceToBuild)) - sourceToBuild <- as.gitRepoSource(sourceToBuild) + sourceToBuild <- as.gitRepoSource(sourceToBuild, allow_regex = TRUE) } trigger_cloudsource <- NULL From d76f8f89762190d0a01b3cb651a46d5bbaf4f4e1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 4 Aug 2022 16:53:19 +0000 Subject: [PATCH 2/3] added lintr stuff to pass codefactor --- R/buildtrigger_objects.R | 22 +++++++++++----------- R/buildtriggers.R | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/R/buildtrigger_objects.R b/R/buildtrigger_objects.R index 9a9ba085..fd436ea8 100644 --- a/R/buildtrigger_objects.R +++ b/R/buildtrigger_objects.R @@ -138,7 +138,7 @@ is.gar_pubsubConfig <- function(x) { inherits(x, "gar_pubsubConfig") } -as.gar_pubsubConfig <- function(x){ +as.gar_pubsubConfig <- function(x) { PubsubConfig( subscription = x$subscription, topic = x$topic, @@ -178,7 +178,7 @@ is.gar_webhookConfig <- function(x) { GitRepoSource <- function(uri, ref, repoType = c("GITHUB","CLOUD_SOURCE_REPOSITORIES"), - allow_regex = FALSE){ + allow_regex = FALSE) { assert_that( is.string(uri), @@ -203,20 +203,20 @@ GitRepoSource <- function(uri, ) } -is.gitRepoSource <- function(x){ +is.gitRepoSource <- function(x) { inherits(x, "gar_gitRepoSource") } -as.gitRepoSource <- function(x, allow_regex = FALSE){ - if(!is.buildtrigger_repo(x)){ +as.gitRepoSource <- function(x, allow_regex = FALSE) { + if (!is.buildtrigger_repo(x)) { stop("is not buildtrigger_repo") } - if(is.gar_GitHubEventsConfig(x$repo)){ + if (is.gar_GitHubEventsConfig(x$repo)) { - if(!is.null(x$repo$push$tag)){ + if (!is.null(x$repo$push$tag)) { ref <- paste0("refs/tags/", x$repo$push$tag) - } else if(!is.null(x$repo$push$branch)){ + } else if (!is.null(x$repo$push$branch)) { ref <- paste0("refs/heads/", x$repo$push$branch) } else { stop("No refs/ found", call. = FALSE) @@ -233,11 +233,11 @@ as.gitRepoSource <- function(x, allow_regex = FALSE){ ) } - if(is.gar_RepoSource(x$repo)){ + if (is.gar_RepoSource(x$repo)) { - if(!is.null(x$repo$tagName)){ + if (!is.null(x$repo$tagName)) { ref <- paste0("refs/tags/", x$repo$tagName) - } else if(!is.null(x$repo$branchName)){ + } else if (!is.null(x$repo$branchName)) { ref <- paste0("refs/heads/", x$repo$branchName) } else { stop("No refs/ found", call. = FALSE) diff --git a/R/buildtriggers.R b/R/buildtriggers.R index 65cd05cb..39967a08 100644 --- a/R/buildtriggers.R +++ b/R/buildtriggers.R @@ -366,7 +366,7 @@ as.buildTriggerResponse <- function(x) { o$build <- as.gar_Build(x$build) } - if (!is.null(o$pubsubConfig)){ + if (!is.null(o$pubsubConfig)) { o$pubsubConfig <- as.gar_pubsubConfig(o$pubsubConfig) } @@ -484,7 +484,7 @@ cr_buildtrigger_copy <- function(buildTrigger, } if (!is.null(disabled)) buildTrigger$disabled <- disabled - if(!is.null(sourceToBuild)) buildTrigger$sourceToBuild <- sourceToBuild + if (!is.null(sourceToBuild)) buildTrigger$sourceToBuild <- sourceToBuild buildTrigger <- as.BuildTrigger(buildTrigger) url <- sprintf( From 2ee722ed08040bd6106b84b8ab2fa13a6f821f6f Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 4 Aug 2022 16:55:06 +0000 Subject: [PATCH 3/3] added spacing for lintr --- R/buildtrigger_objects.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/buildtrigger_objects.R b/R/buildtrigger_objects.R index fd436ea8..b46d291e 100644 --- a/R/buildtrigger_objects.R +++ b/R/buildtrigger_objects.R @@ -177,7 +177,7 @@ is.gar_webhookConfig <- function(x) { #' @noRd GitRepoSource <- function(uri, ref, - repoType = c("GITHUB","CLOUD_SOURCE_REPOSITORIES"), + repoType = c("GITHUB", "CLOUD_SOURCE_REPOSITORIES"), allow_regex = FALSE) { assert_that( @@ -199,7 +199,7 @@ GitRepoSource <- function(uri, ref = ref, repoType = repoType ), - class = c("gar_gitRepoSource","list") + class = c("gar_gitRepoSource", "list") ) }