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

feat: PR must open from the main window #816

Merged
merged 3 commits into from
Nov 22, 2024
Merged
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: 22 additions & 19 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,32 @@ plan_release <- function(
}

local_options(usethis.quiet = TRUE)
with_repo(plan_release_impl(which, force))
local_repo()

plan_release_impl(which, force)
}

plan_release_impl <- function(which, force) {
# Checking if it's an orphan branch: https://github.com/r-lib/gert/issues/139
stopifnot(get_branch_name() != "HEAD")

# Do we need bump_version() first?
if (!no_change()) {
cli_abort(c(
"Aborting release process because not all changes were recorded.",
i = "Run {.run fledge::bump_version()}, then rerun {.run fledge::plan_release()}"
))
}

# Check PAT early
check_gh_pat("repo")

fledgeling <- read_fledgling()
orig_fledgeling <- read_fledgling()

fledgeling <- update_news_impl(
default_commit_range(),
which = "dev",
fledgeling = orig_fledgeling,
no_change_message = NA_character_
)

if (!identical(fledgeling, orig_fledgeling)) {
write_fledgling(fledgeling)
finalize_version_impl(push = TRUE)
}

new_version <- fledge_guess_version(fledgeling[["version"]], which)

if (!force) {
Expand Down Expand Up @@ -123,15 +130,14 @@ plan_release_impl <- function(which, force) {
push_to_new(remote_name, force)

if (fledge_chatty()) {
cli_alert("Opening draft pull request with contents from {.file cran-comments.md}.")
cli_alert("Opening pull request with instructions.")
}

create_pull_request(get_branch_name(), main_branch, remote_name, force)

has_src <- pkgbuild::pkg_has_src()

if (is_installed("job") && rstudioapi::isAvailable() && !nzchar(Sys.getenv("FLEDGE_TEST_NOGH"))) {
inject(job::empty(title = "create_pull_request", {
asNamespace("fledge")$create_pull_request(!!get_branch_name(), !!main_branch, !!remote_name, !!force)
}))
inject(job::empty(title = "check_win_devel", {
devtools::check_win_devel()
}))
Expand Down Expand Up @@ -162,8 +168,6 @@ plan_release_impl <- function(which, force) {
cli_end()
}
} else {
create_pull_request(get_branch_name(), main_branch, remote_name, force)

# user action items
if (fledge_chatty()) {
cli_h1("3. User Action Items")
Expand Down Expand Up @@ -405,7 +409,7 @@ get_cransplainer_update <- function(package) {

cransplainer <- paste0(
"- [x] ", checked_on, ", problems found: ", url, "\n",
paste0("- [ ] ", details$result, ": ", details$flavors, "\n", details$message, collapse = "\n")
paste0("- [ ] ", details$result, ": ", details$flavors, "\n", substr(details$message, 1, 2000), collapse = "\n")
)

paste0(cransplainer, "\n\nCheck results at: ", url)
Expand Down Expand Up @@ -752,8 +756,7 @@ create_pull_request <- function(release_branch, main_branch, remote_name, force)
)
}

# FIXME: Use response from gh() call to open URL
usethis::pr_view()
utils::browseURL(pr[["html_url"]])
}

# FIXME: Align with new-style release
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/auto-full-cycle-main-nopush.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.1 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/auto-full-cycle-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.1 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/auto-full-cycle-pre.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.1.0 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
21 changes: 19 additions & 2 deletions tests/testthat/_snaps/auto-full-cycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
Code
plan_release("next")
Message
> Digesting messages from 1 commits.
> Digesting messages from 3 commits.
v Found 1 NEWS-worthy entry.

-- Updating NEWS --

> Adding new entries to 'NEWS.md'.

-- Updating Version --

v Package version bumped to 0.0.0.9001.
> Added header to 'NEWS.md'.
> Committing changes.

-- Tagging Version --

> Creating tag v0.0.0.9001 with tag message derived from 'NEWS.md'.
> Pushing main.
> Force-pushing tag v0.0.0.9001.
Output
+------------------+
| |
Expand All @@ -19,7 +36,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.1 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/auto-pre.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Code
plan_release("next")
Message
> Digesting messages from 1 commits.
> Digesting messages from 2 commits.
Output
+------------------+
| |
Expand All @@ -28,7 +28,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.1 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/auto-release-abandon.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.0.9900 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down Expand Up @@ -71,7 +71,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.0.9900 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
32 changes: 1 addition & 31 deletions tests/testthat/_snaps/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,6 @@
Error in `gert::git_branch_create()`:
! Failed to find git reference 'blop'

# plan_release() works

Code
plan_release("next")
Message
> Digesting messages from 1 commits.
Output
+------------------+
| |
| plan_release |
| |
+------------------+
Message

-- 1. Creating a release branch and getting ready ------------------------------
> Creating branch cran-0.0.1.
> Switching to branch cran-0.0.1.
> Committing changes.

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.1 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
* Run `urlchecker::url_update()`.
* Check all items in 'cran-comments.md'.
* Review 'NEWS.md'.
* Run `fledge::release()`.

# plan_release() -- force

Code
Expand Down Expand Up @@ -79,7 +49,7 @@

-- 2. Opening Pull Request for release branch ----------------------------------
> Pushing cran-0.0.0.9900 to remote origin.
> Opening draft pull request with contents from 'cran-comments.md'.
> Opening pull request with instructions.

-- 3. User Action Items --------------------------------------------------------
* Run `devtools::check_win_devel()`.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-auto-full-cycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ test_that("full cycle", {
gert::git_commit("* Add cool bla.")

local_fledge_quiet()
bump_version()
finalize_version(push = TRUE)

# Deliberately without bump_version()

## init release ----
withr::local_envvar("FLEDGE_TEST_NOGH" = "no-github-no-mocking-needed-yay")
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-auto-pre.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ test_that("plan_release() works", {
tempdir_remote <- withr::local_tempdir(pattern = "remote")
create_remote(tempdir_remote)

## TODO: add test for bump_version() not run?
local_fledge_quiet()
bump_version()

expect_fledge_snapshot({
plan_release("next")
})
Expand Down
17 changes: 0 additions & 17 deletions tests/testthat/test-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ test_that("create_release_branch() works", {
})
})

test_that("plan_release() works", {
withr::local_envvar("FLEDGE_TEST_NOGH" = "blop")
withr::local_envvar("FLEDGE_DONT_BOTHER_CRAN_THIS_IS_A_TEST" = "yes-a-test")
local_demo_project(quiet = TRUE)

tempdir_remote <- withr::local_tempdir(pattern = "remote")
create_remote(tempdir_remote)

local_fledge_quiet()
bump_version()

expect_fledge_snapshot({
plan_release("next")
})
expect_true(gert::git_branch_exists("cran-0.0.1"))
})

test_that("plan_release() -- force", {
withr::local_envvar("FLEDGE_TEST_NOGH" = "blop")
withr::local_envvar("FLEDGE_DONT_BOTHER_CRAN_THIS_IS_A_TEST" = "yes-a-test")
Expand Down