Skip to content

Commit

Permalink
Move responsibility for checking FLEDGE_TEST_NOGH
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 22, 2023
1 parent 970afed commit 5aafcc1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
27 changes: 18 additions & 9 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ init_release_impl <- function(which, force) {
}

pre_release_impl <- function(force) {
# check PAT scopes for PR for early abort
check_gh_pat("repo")

cli_h1("1. Opening Pull Request for release branch")

main_branch <- get_main_branch()
Expand All @@ -153,9 +156,8 @@ pre_release_impl <- function(force) {
cli_alert("Opening draft pull request with contents from {.file cran-comments.md}.")
}

if (!nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) {
create_pull_request(get_branch_name(), main_branch, remote_name, force)
}
create_pull_request(get_branch_name(), main_branch, remote_name, force)

# user action items
if (fledge_chatty()) {
cli_h1("2. User Action Items")
Expand Down Expand Up @@ -477,9 +479,7 @@ post_release_impl <- function() {
# Begin extension points
# End extension points

if (!nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) {
create_github_release()
}
create_github_release()

merge_main_into_post_release()

Expand All @@ -505,6 +505,11 @@ post_release_impl <- function() {
create_github_release <- function() {
if (fledge_chatty()) cli_alert("Creating GitHub release.")

if (nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) {
cli_alert("Omitting in test.")
return(invisible())
}

slug <- github_slug()
tag <- get_tag_info()

Expand All @@ -516,7 +521,7 @@ create_github_release <- function() {
if (fledge_chatty()) {
cli_alert("Release {.url {release$html_url}} already exists.")
}
return()
return(invisible())
}

out <- gh(
Expand Down Expand Up @@ -593,8 +598,8 @@ check_post_release <- function() {
cli_alert("Checking presence and scope of {.var GITHUB_PAT}.")
}

# FIXME: Distinguish between public and private repo?
if (!nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) check_gh_pat("repo")
# Need PAT for creating GitHub release
check_gh_pat("repo")

if (!no_change(main_branch)) {
cli_abort(c(
Expand Down Expand Up @@ -640,6 +645,10 @@ is_ignored <- function(path) {
}

create_pull_request <- function(release_branch, main_branch, remote_name, force) {
if (nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) {
return(invisible())
}

# FIXME: Use gh() to determine if we need to create the pull request
create <- TRUE

Expand Down
1 change: 1 addition & 0 deletions R/utils-gh-pat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
check_gh_pat <- function(needed_scopes = "repo") {
# Checks are always successful if no GitHub is requested
if (nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) {
return(TRUE)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/_snaps/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
post_release()
Message
> Checking presence and scope of `GITHUB_PAT`.
> Creating GitHub release.
> Omitting in test.
> Switching to branch main.
> Pulling main.
Resetting main to origin/main
Expand Down Expand Up @@ -299,6 +301,8 @@
post_release()
Message
> Checking presence and scope of `GITHUB_PAT`.
> Creating GitHub release.
> Omitting in test.
> Switching to branch main.
> Pulling main.
Resetting main to origin/main
Expand Down Expand Up @@ -414,6 +418,8 @@

Code
post_release()
Message
> Omitting in test.
Condition
Error in `merge_main_into_post_release()`:
! Merging the main branch into the release branch failed.
Expand Down

0 comments on commit 5aafcc1

Please sign in to comment.