Skip to content

Commit

Permalink
Allow appending urls in use_github_links() (r-lib#1834)
Browse files Browse the repository at this point in the history
* Allow appending urls in use_github_links()

* account for no existing URL field

* Add NEWS bullet

* Use desc$set_list in use_description_field

* let use_description_field() construct url list

also let it handle overwrite behaviour

* Update tests, lean more on desc

* Use github_url_from_git_remotes() and mock that

* Consolidate tests

* Update code comment in use_description_field

* Move skips to top of tests
  • Loading branch information
ateucher authored May 4, 2023
1 parent 5031980 commit e05947f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# usethis (development version)

* `use_github_links()` by default now appends the GitHub url to existing urls in
in the `URL` field of DESCRIPTION, rather than replacing existing urls (#1805).

* `use_upkeep_issue()` is a new function to facilitate regular maintenance of
your package. Similar to `use_release_issue()`, it opens an issue in your repo
with a checklist of maintenance tasks. It will include additional bullets
Expand Down
5 changes: 1 addition & 4 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,8 @@ use_github_links <- function(auth_token = deprecated(),
}

check_is_package("use_github_links()")
tr <- target_repo(github_get = TRUE)

gh <- gh_tr(tr)
res <- gh("GET /repos/{owner}/{repo}")
gh_url <- res$html_url
gh_url <- github_url_from_git_remotes()

proj_desc_field_update("URL", gh_url, overwrite = overwrite, append = TRUE)

Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/github.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# use_github_links() aborts or appends URLs when it should

Code
use_github_links(overwrite = FALSE)
Condition
Error:
! URL has a different value in DESCRIPTION. Use `overwrite = TRUE` to overwrite.

42 changes: 42 additions & 0 deletions tests/testthat/test-github.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
test_that("use_github_links populates empty URL field", {
skip_if_no_git_user()
local_interactive(FALSE)
create_local_package()
use_git()

local_mocked_bindings(
github_url_from_git_remotes = function() "https://github.com/OWNER/REPO"
)

# when no URL field
use_github_links()
expect_equal(proj_desc()$get_urls(), "https://github.com/OWNER/REPO")
expect_equal(
proj_desc()$get_field("BugReports"),
"https://github.com/OWNER/REPO/issues"
)
})

test_that("use_github_links() aborts or appends URLs when it should", {
skip_if_no_git_user()
local_interactive(FALSE)
create_local_package()
use_git()

local_mocked_bindings(
github_url_from_git_remotes = function() "https://github.com/OWNER/REPO"
)

d <- proj_desc()
d$set_urls(c("https://existing.url", "https://existing.url1"))
d$write()

expect_snapshot(use_github_links(overwrite = FALSE), error = TRUE)

use_github_links(overwrite = TRUE)
expect_equal(
proj_desc()$get_urls(),
c("https://existing.url", "https://existing.url1",
"https://github.com/OWNER/REPO")
)
})

0 comments on commit e05947f

Please sign in to comment.