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 allow_regex to help with issue #172 #198

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
41 changes: 24 additions & 17 deletions R/buildtrigger_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -194,24 +199,24 @@ GitRepoSource <- function(uri,
ref = ref,
repoType = repoType
),
class = c("gar_gitRepoSource","list")
class = c("gar_gitRepoSource", "list")
)
}

is.gitRepoSource <- function(x){
is.gitRepoSource <- function(x) {
inherits(x, "gar_gitRepoSource")
}

as.gitRepoSource <- function(x){
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)
Expand All @@ -222,16 +227,17 @@ 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
)
)
}

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)
Expand All @@ -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
)
)
}
Expand Down
6 changes: 3 additions & 3 deletions R/buildtriggers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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(
Expand Down