Skip to content

Commit

Permalink
pr_push() can now push to repo with no pr (r-lib#990) (r-lib#991)
Browse files Browse the repository at this point in the history
* pr_push() now handles repo with no pr (r-lib#990)

Fixes r-lib#990

The is the  minimal fix, maybe too terse. A more expressive
solution comes in a separate commit, to allow reverting it if you
prefer the shorter solution.

The tests will also come in a separate commit because they test
the internal `pr_find()` instead of the exported `pr_push()`. You
may want to revert that upcomming commit too.

* Test pr_find() handles repo with no pr (r-lib#990)

* New is_new_pr() (more expressive version of r-lib#990)

* Simplify and record why this is needed

* Move into manual tests folder

* Rewrite as manual test

* Update NEWS bullet

* Update wordlist

Co-authored-by: Jennifer (Jenny) Bryan <[email protected]>
  • Loading branch information
maurolepore and jennybc authored Jan 31, 2020
1 parent 92b76a4 commit 1da0ecb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# usethis (development version)

* `pr_push()` works with gh v1.1.0 (and earlier versions), for a repository with no open pull requests (#990, @maurolepore).

* New `use_github_actions()`, `use_github_action_check_release()`, `use_github_action_check_full()`,
`use_github_action_pr_commands()`, `use_github_actions_tidy()` to set up a GitHub Actions
for a package (@jimhester).
Expand Down
4 changes: 3 additions & 1 deletion R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ pr_find <- function(owner,
.token = check_github_token(allow_empty = TRUE)
)

if (identical(prs[[1]], "")) {
# prs has length zero if gh >= v1.1.0 and is "" for earlier versions
if (length(prs) < 1 || identical(prs[[1]], "")) {
return(character())
}

Expand All @@ -391,3 +392,4 @@ pr_find <- function(owner,

urls[refs == pr_branch & user == pr_owner]
}

2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ frontmatter
fs
funder
gc
gh
Git's
github
gitignore
Expand All @@ -49,6 +50,7 @@ gzip
hexb
Homebrew
hostname
href
http
https
HTTPS
Expand Down
12 changes: 12 additions & 0 deletions tests/manual/manual-pr-find.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# key property of maurolepore/with-no-pr is that there are no open PRs

pkgload::unload("devtools"); devtools::load_all(); attachNamespace("devtools")

# this should not error
prs <- pr_find("maurolepore", repo = "with-no-pr", pr_branch = "new")

# for gh >= v1.1.0
testthat::expect_equal(prs, character())

# for gh < v1.1.0
testthat::expect_equal(prs, "")

0 comments on commit 1da0ecb

Please sign in to comment.