Skip to content

Commit

Permalink
Feature: main now supported (#44)
Browse files Browse the repository at this point in the history
* Feature: main now support

* Update docs
  • Loading branch information
csgillespie authored Jun 29, 2021
1 parent 2ecaac0 commit 0ccff5d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -25,4 +25,4 @@ Suggests:
testthat
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
21 changes: 15 additions & 6 deletions R/check_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()")
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions R/create_tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 12 additions & 8 deletions inst/good_pkg/R/check_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()")
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions inst/good_pkg/R/create_tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions man/check_version.Rd

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

4 changes: 2 additions & 2 deletions man/create_tag.Rd

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

0 comments on commit 0ccff5d

Please sign in to comment.