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

fix: do not return "" if there is no github URL in DESCRIPTION #311

Merged
merged 11 commits into from
Feb 7, 2025
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: altdoc
Title: Package Documentation Websites with 'Quarto', 'Docsify', 'Docute', or 'MkDocs'
Version: 0.5.0
Version: 0.5.0.9000
Authors@R:
c(person(given = "Etienne",
family = "Bacher",
Expand Down
6 changes: 5 additions & 1 deletion R/import_readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
}
}

tar_file <- fs::path_join(c(tar_dir, "README.md"))
if (tool == "quarto_website") {
tar_file <- fs::path_join(c(tar_dir, "index.md"))
} else {
tar_file <- fs::path_join(c(tar_dir, "README.md"))
}
src_file <- fs::path_join(c(src_dir, "README.md"))
fs::file_copy(src_file, tar_file, overwrite = TRUE)
.check_md_structure(tar_file)
Expand Down
3 changes: 1 addition & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
)

if (length(.gh_urls) == 0) {
return("")
return(NULL)
}

.gh_url <- .gh_urls[grep("github.com", .gh_urls)]
Expand All @@ -58,7 +58,6 @@
.gh_url <- gsub("#.*", "", .gh_url)
.gh_url <- unique(.gh_url)

if (length(.gh_url) == 0) .gh_url <- ""
return(.gh_url)
}

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Package: testpkg.altdoc.noURL
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <[email protected]>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
R6
7 changes: 7 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(examplesIf_false)
export(examplesIf_true)
export(hello_base)
export(hello_r6)
importFrom(R6,R6Class)
9 changes: 9 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# foobar 1.1.0

* thanks @foo-bar for their contribution (#111)

* thanks @foo2- for their contribution (#11)

* thanks @JohnDoe, @JaneDoe

* this should not be linked: [email protected]
12 changes: 12 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/R/examplesIf_false.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Examples If FALSE
#'
#' @param x A parameter
#'
#' @return Some value
#' @export
#'
#' @examplesIf 2 + 2 == 5
#' examplesIf_false()
examplesIf_false <- function() {
print("Hello, world!")
}
12 changes: 12 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/R/examplesIf_true.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Examples If TRUE
#'
#' @param x A parameter
#'
#' @return Some value
#' @export
#'
#' @examplesIf 2 + 2 == 4
#' examplesIf_true()
examplesIf_true <- function() {
print("Hello, world!")
}
28 changes: 28 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/R/hello_base.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' Base function
#'
#' @param x A parameter
#'
#' @details
#' Some code with weird symbols: `pl$when(condition)` and `pl$then(output)`
#'
#' Some equations: \eqn{\partial Y / \partial X = a + \varepsilon/2}
#'
#'
#' @return Some value
#' @export
#'
#' @seealso \code{\link[base]{print}}, \code{\link{hello_r6}}
#'
#' @references Ihaka R, Gentleman R (1996).
#' R: A Language for Data Analysis and Graphics.
#' \emph{Journal of Computational and Graphical Statistics}. \bold{5}(3), 299--314.
#' \doi{10.2307/139080}
#'
#' @examples
#' hello_base()
#'
#' mtcars$drat <- mtcars$drat + 1
#' head(mtcars[["drat"]], 2)
hello_base <- function(x = 2) {
print("Hello, world!")
}
32 changes: 32 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/R/hello_r6.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Create a "conductor" tour
#'
#' blah blah blah
#' @importFrom R6 R6Class
#' @export
hello_r6 <- R6::R6Class(
"Conductor",
private = list(x = 1),

public = list(
#' @details
#' Initialise `Conductor`.
initialize = function() {
},

#' @param session A valid Shiny session. If `NULL` (default), the function
#' attempts to get the session with `shiny::getDefaultReactiveDomain()`.
#'
#' @details
#' Initialise `Conductor`.
init = function(session = NULL) {
},

#' @param title Title of the popover.
#'
#' @details
#' Add a step in a `Conductor` tour.

step = function(title = NULL) {
}
)
)
41 changes: 41 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
output: github_document
default-image-extension: ""
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# testpkg.altdoc

<!-- badges: start -->
[![R-universe status badge](https://grantmcdermott.r-universe.dev/badges/plot2)](https://grantmcdermott.r-universe.dev)
<!-- badges: end -->

The goal of testpkg.altdoc is to ...

## Installation

You can install the development version of testpkg.altdoc like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(testpkg.altdoc)
summary(cars)
```

36 changes: 36 additions & 0 deletions tests/testthat/examples/testpkg.altdoc.noURL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# testpkg.altdoc

<!-- badges: start -->

[![R-universe status
badge](https://grantmcdermott.r-universe.dev/badges/plot2)](https://grantmcdermott.r-universe.dev)
<!-- badges: end -->

The goal of testpkg.altdoc is to …

## Installation

You can install the development version of testpkg.altdoc like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(testpkg.altdoc)
summary(cars)
#> speed dist
#> Min. : 4.0 Min. : 2.00
#> 1st Qu.:12.0 1st Qu.: 26.00
#> Median :15.0 Median : 36.00
#> Mean :15.4 Mean : 42.98
#> 3rd Qu.:19.0 3rd Qu.: 56.00
#> Max. :25.0 Max. :120.00
```
25 changes: 23 additions & 2 deletions tests/testthat/test-render_docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ test_that("quarto: no error for basic workflow", {

### generate docs
install.packages(".", repos = NULL, type = "source")
fs::file_move("README.Rmd", "README.qmd") # special thing quarto
setup_docs("quarto_website")
expect_no_error(render_docs(verbose = .on_ci()))

Expand All @@ -150,6 +149,29 @@ test_that("quarto: no error for basic workflow", {
# expect_snapshot(.readlines("docs/vignettes/test.html"))
})

# https://github.com/etiennebacher/altdoc/issues/307
test_that("quarto: no error for basic workflow, no Github URL", {
skip_on_cran()
skip_if(.is_windows() && .on_ci(), "Windows on CI")

### setup: create a temp package using the structure of testpkg.altdoc.noURL
path_to_example_pkg <- fs::path_abs(
test_path("examples/testpkg.altdoc.noURL")
)
create_local_project()
fs::dir_delete("R")
fs::dir_copy(path_to_example_pkg, ".")
all_files <- list.files("testpkg.altdoc.noURL", full.names = TRUE)
for (i in all_files) {
fs::file_move(i, ".")
}
fs::dir_delete("testpkg.altdoc.noURL")

install.packages(".", repos = NULL, type = "source")
setup_docs("quarto_website")
expect_no_error(render_docs(verbose = .on_ci()))
})

test_that("quarto: autolink", {
skip_on_cran()
skip_if(.is_windows() && .on_ci(), "Windows on CI")
Expand All @@ -167,7 +189,6 @@ test_that("quarto: autolink", {

### generate docs
install.packages(".", repos = NULL, type = "source")
fs::file_move("README.Rmd", "README.qmd") # special thing quarto
setup_docs("quarto_website")
expect_no_error(render_docs(verbose = .on_ci()))

Expand Down
Loading