Skip to content

Commit e05947f

Browse files
authored
Allow appending urls in use_github_links() (#1834)
* 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
1 parent 5031980 commit e05947f

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# usethis (development version)
22

3+
* `use_github_links()` by default now appends the GitHub url to existing urls in
4+
in the `URL` field of DESCRIPTION, rather than replacing existing urls (#1805).
5+
36
* `use_upkeep_issue()` is a new function to facilitate regular maintenance of
47
your package. Similar to `use_release_issue()`, it opens an issue in your repo
58
with a checklist of maintenance tasks. It will include additional bullets

R/github.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,8 @@ use_github_links <- function(auth_token = deprecated(),
219219
}
220220

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

224-
gh <- gh_tr(tr)
225-
res <- gh("GET /repos/{owner}/{repo}")
226-
gh_url <- res$html_url
223+
gh_url <- github_url_from_git_remotes()
227224

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

tests/testthat/_snaps/github.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# use_github_links() aborts or appends URLs when it should
2+
3+
Code
4+
use_github_links(overwrite = FALSE)
5+
Condition
6+
Error:
7+
! URL has a different value in DESCRIPTION. Use `overwrite = TRUE` to overwrite.
8+

tests/testthat/test-github.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
test_that("use_github_links populates empty URL field", {
2+
skip_if_no_git_user()
3+
local_interactive(FALSE)
4+
create_local_package()
5+
use_git()
6+
7+
local_mocked_bindings(
8+
github_url_from_git_remotes = function() "https://github.com/OWNER/REPO"
9+
)
10+
11+
# when no URL field
12+
use_github_links()
13+
expect_equal(proj_desc()$get_urls(), "https://github.com/OWNER/REPO")
14+
expect_equal(
15+
proj_desc()$get_field("BugReports"),
16+
"https://github.com/OWNER/REPO/issues"
17+
)
18+
})
19+
20+
test_that("use_github_links() aborts or appends URLs when it should", {
21+
skip_if_no_git_user()
22+
local_interactive(FALSE)
23+
create_local_package()
24+
use_git()
25+
26+
local_mocked_bindings(
27+
github_url_from_git_remotes = function() "https://github.com/OWNER/REPO"
28+
)
29+
30+
d <- proj_desc()
31+
d$set_urls(c("https://existing.url", "https://existing.url1"))
32+
d$write()
33+
34+
expect_snapshot(use_github_links(overwrite = FALSE), error = TRUE)
35+
36+
use_github_links(overwrite = TRUE)
37+
expect_equal(
38+
proj_desc()$get_urls(),
39+
c("https://existing.url", "https://existing.url1",
40+
"https://github.com/OWNER/REPO")
41+
)
42+
})

0 commit comments

Comments
 (0)