diff --git a/DESCRIPTION b/DESCRIPTION index 8f564f1..17fefe3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: inteRgrate Title: Opinionated Package Coding Styles -Version: 1.0.17 +Version: 1.0.18 Authors@R: person(given = "Jumping", family = "Rivers", @@ -25,4 +25,4 @@ Suggests: testthat Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 diff --git a/NEWS.md b/NEWS.md index 1340f1f..6f0a846 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# inteRgrate 1.0.18 _2021-06-28_ + * Add support for main + # inteRgrate 1.0.17 _2021-04-10_ * Add more exclusions (again) diff --git a/R/check_version.R b/R/check_version.R index 1c7ffb0..7c8a0e0 100644 --- a/R/check_version.R +++ b/R/check_version.R @@ -4,14 +4,20 @@ is_tagging_branch = function() { !is.na(Sys.getenv("CI_COMMIT_TAG", Sys.getenv("TRAVIS_TAG", NA))) } +get_origin_name = function() { + origin = system2("git", c("branch"), stdout = TRUE) + origin = stringr::str_trim(origin) + is_main = any(stringr::str_detect(origin, "^main$")) + if (is_main) "main" else "master" +} has_pkg_changed = function(repo) { current_branch = get_current_branch() sha_range = get_sha_range() - if (current_branch != "master") { - system2("git", args = c("remote", "set-branches", "--add", "origin", "master")) - system2("git", args = "fetch") + if (!(current_branch %in% c("master", "main"))) { + system2("git", args = c("remote", "set-branches", "--add", "origin", get_origin_name())) + system2("git", args = c("fetch", "origin", get_origin_name())) committed_files = system2("git", args = c("diff", "--name-only", repo), stdout = TRUE) } else { @@ -55,10 +61,13 @@ has_pkg_changed = function(repo) { #' #' Technically we only check for a change in the Version line of the DESCRIPTION file, not an #' actual version increase. -#' @param repo Default origin/master. The repo to compare against. +#' @param repo Default origin/master or origin/main. The repo to compare against. #' @inheritParams check_pkg #' @export -check_version = function(repo = "origin/master", path = ".") { +check_version = function(repo = NULL, path = ".") { + if (is.null(repo)) { + repo = paste0("origin/", get_origin_name()) + } op = setwd(path) on.exit(setwd(op)) cli::cli_h3("Checking version...check_version()") @@ -71,7 +80,7 @@ check_version = function(repo = "origin/master", path = ".") { current_branch = get_current_branch() ## Check if version has been updated - if (current_branch != "master") { + if (!(current_branch %in% c("master", "main"))) { des_diff = system2("git", args = c("diff", "--unified=0", repo, "DESCRIPTION"), stdout = TRUE) diff --git a/R/create_tag.R b/R/create_tag.R index 1aba104..4ddba6b 100644 --- a/R/create_tag.R +++ b/R/create_tag.R @@ -19,10 +19,10 @@ globalVariables(c("token", "project")) #' #' If the version contains an in development component (e.g. X.Y.Z.9001), by #' default a tag isn't created. -#' @param branch The branch where the tagging will occur. Default master. +#' @param branch The branch where the tagging will occur. Default master or main. #' @param in_development Logical default FALSE. #' @export -create_tag = function(branch = "master", in_development = FALSE) { +create_tag = function(branch = get_origin_name(), in_development = FALSE) { cli::cli_h3("Creating a tag...create_tag()") if (isTRUE(.check$error)) { cli::cli_alert_info("No tagging: fix checking errors") diff --git a/inst/good_pkg/R/check_version.R b/inst/good_pkg/R/check_version.R index 3dc95ed..d37e157 100644 --- a/inst/good_pkg/R/check_version.R +++ b/inst/good_pkg/R/check_version.R @@ -4,14 +4,13 @@ is_tagging_branch = function() { !is.na(Sys.getenv("CI_COMMIT_TAG", Sys.getenv("TRAVIS_TAG", NA))) } - has_pkg_changed = function(repo) { current_branch = get_current_branch() sha_range = get_sha_range() - if (current_branch != "master") { - system2("git", args = c("remote", "set-branches", "--add", "origin", "master")) - system2("git", args = "fetch") + if (!(current_branch %in% c("master", "main"))) { + system2("git", args = c("remote", "set-branches", "--add", "origin", get_origin_name())) + system2("git", args = c("fetch", "origin", get_origin_name())) committed_files = system2("git", args = c("diff", "--name-only", repo), stdout = TRUE) } else { @@ -42,17 +41,22 @@ has_pkg_changed = function(repo) { #' Version check #' #' Check if the package version has been updated compared to the a -#' master repo (default is origin/master). This ensures that when branches are merged +#' master/main repo (default is origin/master). +#' This ensures that when branches are merged #' the package version is bumped. #' #' Files listed in .Rbuildignore don't count as changes. #' #' Technically we only check for a change in the Version line of the DESCRIPTION file, not an #' actual version increase. -#' @param repo Default origin/master. The repo to compare against. +#' @param repo If NULL, then defaults to origin/master or origin/mian. +#' The repo to compare against. #' @inheritParams check_pkg #' @export -check_version = function(repo = "origin/master", path = ".") { +check_version = function(repo = NULL, path = ".") { + if (is.null(repo)) { + repo = paste0("origin/", get_origin_name()) + } op = setwd(path) on.exit(setwd(op)) cli::cli_h3("Checking version...check_version()") @@ -65,7 +69,7 @@ check_version = function(repo = "origin/master", path = ".") { current_branch = get_current_branch() ## Check if version has been updated - if (current_branch != "master") { + if (!(current_branch %in% get_origin_name())) { des_diff = system2("git", args = c("diff", "--unified=0", repo, "DESCRIPTION"), stdout = TRUE) diff --git a/inst/good_pkg/R/create_tag.R b/inst/good_pkg/R/create_tag.R index 406293f..ee485ca 100644 --- a/inst/good_pkg/R/create_tag.R +++ b/inst/good_pkg/R/create_tag.R @@ -19,10 +19,10 @@ globalVariables(c("token", "project")) #' #' If the version contains an in development component (e.g. X.Y.Z.9001), by #' default a tag isn't created. -#' @param branch The branch where the tagging will occur. Default master. +#' @param branch The branch where the tagging will occur. Default master or main. #' @param in_development Logical default FALSE. #' @export -create_tag = function(branch = "master", in_development = FALSE) { +create_tag = function(branch = get_origin_name(), in_development = FALSE) { cli::cli_h3("Creating a tag...create_tag()") if (!is_gitlab() && !is_github()) { cli::cli_alert_info("No tagging: doesn't seem to be a CI process") diff --git a/man/check_version.Rd b/man/check_version.Rd index eb96d04..60f2b6b 100644 --- a/man/check_version.Rd +++ b/man/check_version.Rd @@ -4,10 +4,10 @@ \alias{check_version} \title{Version check} \usage{ -check_version(repo = "origin/master", path = ".") +check_version(repo = NULL, path = ".") } \arguments{ -\item{repo}{Default origin/master. The repo to compare against.} +\item{repo}{Default origin/master or origin/main. The repo to compare against.} \item{path}{Location of the package} } diff --git a/man/create_tag.Rd b/man/create_tag.Rd index 33b605a..0ebd552 100644 --- a/man/create_tag.Rd +++ b/man/create_tag.Rd @@ -4,10 +4,10 @@ \alias{create_tag} \title{Auto-tagging via CI} \usage{ -create_tag(branch = "master", in_development = FALSE) +create_tag(branch = get_origin_name(), in_development = FALSE) } \arguments{ -\item{branch}{The branch where the tagging will occur. Default master.} +\item{branch}{The branch where the tagging will occur. Default master or main.} \item{in_development}{Logical default FALSE.} }