Skip to content

Commit

Permalink
fixes #2030 while not breaking #2122, for most common use case
Browse files Browse the repository at this point in the history
  • Loading branch information
pearsonca committed Nov 20, 2023
1 parent 5a0a31f commit c58541d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ repo_auto_link <- function(pkg, text) {

if (!is.null(url$user)) {
user_link <- paste0("\\1<a href='", url$user, "\\2'>@\\2</a>")
text <- gsub("(\\s|^|\\()@([-\\w]+)", user_link, text, perl = TRUE)
text <- gsub("(p>|\\s|^|\\()@([-\\w]+)", user_link, text, perl = TRUE)
}

if (!is.null(url$issue)) {
issue_link <- paste0("<a href='", url$issue, "\\2'>#\\2</a>")
text <- gsub("(\\(|\\s)#(\\d+)", paste0("\\1", issue_link), text, perl = TRUE)
text <- gsub("(p>|\\(|\\s)#(\\d+)", paste0("\\1", issue_link), text, perl = TRUE)

if (!is.null(pkg$repo$jira_projects)) {
issue_link <- paste0("<a href='", url$issue, "\\1\\2'>\\1\\2</a>")
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ test_that("authors are automatically linked", {
expect_equal(repo_auto_link(pkg, "@y"), "<a href='TEST/y'>@y</a>")
expect_equal(repo_auto_link(pkg, " @y"), " <a href='TEST/y'>@y</a>")
expect_equal(repo_auto_link(pkg, "(@y)"), "(<a href='TEST/y'>@y</a>)")

expect_equal(repo_auto_link(pkg, "<p>@y some other text.</p>"), "<p><a href='TEST/y'>@y</a> some other text.</p>")
})

test_that("issues are automatically linked", {
pkg <- list(repo = repo_meta(issue = "TEST/"))
expect_equal(repo_auto_link(pkg, "(#123"), "(<a href='TEST/123'>#123</a>")
expect_equal(repo_auto_link(pkg, "in #123"), "in <a href='TEST/123'>#123</a>")
expect_equal(repo_auto_link(pkg, "<p>#123 some other text.</p>"), "<p><a href='TEST/123'>#123</a> some other text.</p>")
expect_equal(repo_auto_link(pkg, "<p><a href='TEST/123/'>#123</a></p>"), "<p><a href='TEST/123/'>#123</a></p>")
})

test_that("already linked issues aren't re-linked", {
pkg <- list(repo = repo_meta(issue = "TEST/"))
expect_equal(repo_auto_link(pkg, "<p><a href='NOT/ABC/'>#123</a></p>"), "<p><a href='NOT/ABC/'>#123</a></p>")
})

test_that("URLs with hash (#) are preserved", {
Expand Down

0 comments on commit c58541d

Please sign in to comment.