Skip to content

Commit

Permalink
Merge pull request #132 from inbo/codeowners
Browse files Browse the repository at this point in the history
version 0.4.0
  • Loading branch information
ThierryO authored Jul 19, 2024
2 parents d767206 + f6ec490 commit 5649985
Show file tree
Hide file tree
Showing 39 changed files with 424 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "checklist: A Thorough and Strict Set of Checks for R Packages and Source Code",
"version": "0.3.6",
"version": "0.4.0",
"license": "GPL-3.0",
"upload_type": "software",
"description": "<p>An opinionated set of rules for R packages and R source code projects.<\/p>",
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ identifiers:
value: 10.5281/zenodo.4028303
- type: url
value: https://inbo.github.io/checklist/
version: 0.3.6
version: 0.4.0
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: checklist
Title: A Thorough and Strict Set of Checks for R Packages and Source Code
Version: 0.3.6
Version: 0.4.0
Authors@R: c(
person("Thierry", "Onkelinx", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8804-4216", affiliation = "Research Institute for Nature and Forest (INBO)")),
Expand Down Expand Up @@ -59,5 +59,5 @@ Config/checklist/keywords: quality control; documentation; publication
Encoding: UTF-8
Language: en-GB
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
SystemRequirements: Pandoc (>= 1.17.2)
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
maintainer="Thierry Onkelinx <[email protected]>"

## for apt to be noninteractive
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true

## Install nano
RUN apt-get update \
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### GNU GENERAL PUBLIC LICENSE
# GNU GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export(organisation)
export(prepare_ghpages)
export(read_checklist)
export(read_organisation)
export(set_license)
export(set_tag)
export(setup_package)
export(setup_project)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# checklist 0.4.0

* Updated `README.md`.
* Improved support for `organisation`.
* Add `set_license()`.
* `check_filename()` allows a `CODEOWNERS` file.
* The checklist summary displays the unstaged git changes.
* The GitHub Action on packages installs the `roxygen2` version listed in the
`DESCRIPTION` of the package it checks.

# checklist 0.3.6

* Add an `organisation` class to store organisation rules different from those
Expand Down
59 changes: 43 additions & 16 deletions R/check_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ Please send a pull request if you need support for this license.",
official <- official[-3]
current <- current[-3]
}
problems <- c(
problems,
"LICENSE.md doesn't match the version in the checklist package"[
(length(current) != length(official)) || any(current != official)
]
if ((length(current) != length(official)) || any(current != official)) {
problems <- c(
problems, "LICENSE.md doesn't match the version in the checklist package"
)
set_license(x)
}
x$add_error(
errors = problems,
item = "license", keep = FALSE
Expand All @@ -291,19 +291,46 @@ Please send a pull request if you need support for this license.",
check_authors <- function(this_desc, org) {
assert_that(inherits(org, "organisation"))
authors <- this_desc$get_authors()
stopifnot(
"TO DO: handle funder not equal to rightsholder" =
(is.na(org$get_rightsholder) && is.na(org$get_funder)) ||
(org$get_rightsholder == org$get_funder)
)
rightsholder <- person(
given = org$get_rightsholder, role = c("cph", "fnd"), email = org$get_email
email <- c(NULL, org$get_email[!is.na(org$get_email)])
if (!is.na(org$get_rightsholder)) {
if (!is.na(org$get_funder)) {
if (org$get_rightsholder == org$get_funder) {
rightsholder <- person(
given = org$get_rightsholder, role = c("cph", "fnd"), email = email
)
funder <- NULL
} else {
rightsholder <- person(
given = org$get_rightsholder, role = "cph", email = email
)
funder <- person(given = org$get_funder, role = "fnd")
}
} else {
rightsholder <- person(
given = org$get_rightsholder, role = "cph", email = email
)
funder <- NULL
}
} else if (!is.na(org$get_funder)) {
rightsholder <- NULL
funder <- person(given = org$get_funder, role = "fnd")
}

problems <- c(
sprintf(
"`%s` must be listed as copyright holder and use `%s` as email.",
org$get_rightsholder, org$get_email
)[
!is.null(rightsholder) && !is.na(org$get_rightsholder) &&
!rightsholder %in% authors
],
sprintf(
"`%s` must be listed as funder without email.",
org$get_funder
)[!is.null(funder) && !is.na(org$get_funder) && !funder %in% authors]
)
problems <- sprintf(
"`%s` must be listed as copyright holder and funder and use `%s` as email.",
org$get_rightsholder, org$get_email
)[!is.na(org$get_rightsholder) && !rightsholder %in% authors]
authors <- authors[!authors %in% rightsholder]
authors <- authors[!authors %in% funder]
vapply(
authors, FUN.VALUE = vector(mode = "list", length = 1L),
FUN = function(author) {
Expand Down
2 changes: 1 addition & 1 deletion R/check_filename.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ check_filename <- function(x = ".") {
paste(
c(
"\\.[a-zA-Z]+ignore", "\\.Rprofile", "\\.[a-zA-Z]+\\.(json|yml)",
"CITATION", "DESCRIPTION", "NAMESPACE", "CITATION\\.cff",
"CITATION", "CODEOWNERS", "DESCRIPTION", "NAMESPACE", "CITATION\\.cff",
"README\\.R?md", "NEWS\\.md",
"CODE_OF_CONDUCT\\.md", "CONTRIBUTING\\.md", "LICENSE(\\.md)?",
"SUPPORT\\.md", "SECURITY\\.md", "FUNDING\\.yml",
Expand Down
2 changes: 1 addition & 1 deletion R/check_spelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ rstudio_source_markers <- function(issues) { # nocov start
"`%s` not found in the dictionary or wordlist for %s.", issues$message,
issues$language
)
issues <- issues[order(issues$file, issues$line, issues$column), ]
issues <- unique(issues[order(issues$file, issues$line, issues$column), ])
issues$file <- as.character(issues$file)
# request source markers
rstudioapi::callFun(
Expand Down
3 changes: 2 additions & 1 deletion R/citation_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ description_communities <- function(communities, org) {
)
}
list(
meta = list(community = communities), warnings = character(0)
meta = list(community = split_community(communities)),
warnings = character(0)
)
}
15 changes: 11 additions & 4 deletions R/citation_meta_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,20 @@ validate_citation <- function(meta) {
rightsholder_id <- roles$contributor[roles$role == "copyright holder"]
funder_id <- roles$contributor[roles$role == "funder"]
notes <- c(
"no rightsholder listed"[
!is.na(org$get_rightsholder) && length(rightsholder_id) == 0
],
"no funder listed"[!is.na(org$get_funder) && length(funder_id) == 0],
sprintf("rightsholder differs from `%s`", org$get_rightsholder)[
!is.na(org$get_rightsholder) &&
authors$given[authors$id == rightsholder_id] != org$get_rightsholder
!is.na(org$get_rightsholder) && length(rightsholder_id) >= 1 &&
!any(
authors$given[authors$id %in% rightsholder_id] %in%
org$get_rightsholder
)
],
sprintf("funder differs from `%s`", org$get_funder)[
!is.na(org$get_funder) &&
authors$given[authors$id == funder_id] != org$get_funder
!is.na(org$get_funder) && length(funder_id) >= 1 &&
!any(org$get_funder %in% authors$given[authors$id == funder_id])
]
)
errors <- c(
Expand Down
18 changes: 1 addition & 17 deletions R/create_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,7 @@ create_package <- function(
git_add("README.Rmd", repo = repo)

# add LICENSE.md
license_file <- path(path, "LICENSE.md")
switch(
license, "GPL-3" = path("generic_template", "gplv3.md"),
"MIT" = path("generic_template", "mit.md")
) |>
system.file(package = "checklist") |>
file_copy(license_file)
if (license == "MIT") {
paste0("YEAR: ", format(Sys.Date(), "%Y")) |>
c(sprintf("COPYRIGHT HOLDER: %s", org$get_rightsholder)) |>
writeLines(path(path, "LICENSE"))
git_add("LICENSE", repo = repo)
mit <- readLines(license_file)
mit[3] <- gsub("<YEAR>", format(Sys.Date(), "%Y"), mit[3])
mit[3] <- gsub("<COPYRIGHT HOLDER>", org$get_rightsholder, mit[3])
writeLines(mit, license_file)
}
set_license(x)
git_add("LICENSE.md", repo = repo)

# Add code of conduct
Expand Down
4 changes: 3 additions & 1 deletion R/default_organisation.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#' @family both
default_organisation <- function(org = organisation$new()) {
assert_that(inherits(org, "organisation"))
R_user_dir("checklist", which = "config") |>
target <- R_user_dir("checklist", which = "config")
dir_create(target)
target |>
path("organisation.yml") |>
write_yaml(x = org$template)
return(invisible(NULL))
Expand Down
5 changes: 3 additions & 2 deletions R/organisation_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ organisation <- R6Class(
#' - `rightsholder`: the rightsholder.
#' Defaults to `"Research Institute for Nature and Forest (INBO)"`.
#' Set to `NA_character_` in case you don't want to set a rightsholder.
#' - `organisation`: a named list with one or more organisation defaults.
#' - `organisation`: a named list with one or more organisation default
#' rules.
#' The names of the element must match the e-mail domain name of the
#' organisation.
#' Every element should be a named list containing ´affiliation` and
#' Every element should be a named list containing `affiliation` and
#' `orcid`.
#' `affiliation` is a character vector with the approved organisation
#' names in one or more languages.
Expand Down
7 changes: 6 additions & 1 deletion R/read_checklist.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ read_checklist <- function(x = ".") {
}
assert_that(
is_file(checklist_file),
msg = sprintf("no checklist.yml found `%s` or its parents", x)
msg = paste(
"No checklist.yml found at `%1$s` or its parents.",
"\nRun `checklist::setup_package(\"%1$s\")` or",
"`checklist::setup_project(\"%1$s\")`."
) |>
sprintf(path_real(x))
)

# read existing check list file
Expand Down
51 changes: 51 additions & 0 deletions R/set_license.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#' Set the proper license
#' @inheritParams read_checklist
#' @family setup
#' @export
#' @importFrom assertthat assert_that
#' @importFrom desc description
#' @importFrom fs file_copy file_exists path
set_license <- function(x = ".") {
x <- read_checklist(x = x)
license_file <- path(x$get_path, "LICENSE.md")
if (x$package) {
assert_that(
file_exists(path(x$get_path, "DESCRIPTION")),
msg = sprintf("No `DESCRIPTION` file found at %s", x$get_path)
)
this_desc <- description$new(file = path(x$get_path, "DESCRIPTION"))
assert_that(
this_desc$has_fields("License"),
msg = "`DESCRIPTION` has no `License`field."
)
switch(
this_desc$get_field("License"),
"GPL-3" = path("generic_template", "gplv3.md"),
"MIT" = path("generic_template", "mit.md"),
"MIT + file LICENSE" = path("generic_template", "mit.md"),
stop(
sprintf("`%s` license is not available", this_desc$get_field("License"))
)
) |>
system.file(package = "checklist") |>
file_copy(license_file, overwrite = TRUE)
if (!grepl("^MIT", this_desc$get_field("License"))) {
return(invisible(NULL))
}
this_desc$get_author(role = "cph") |>
format(include = c("given", "family")) |>
paste(collapse = ", ") -> cph
paste0("YEAR: ", format(Sys.Date(), "%Y")) |>
c(sprintf("COPYRIGHT HOLDER: %s", cph)) |>
writeLines(path(x$get_path, "LICENSE"))
mit <- readLines(license_file)
mit[3] <- gsub("<YEAR>", format(Sys.Date(), "%Y"), mit[3])
mit[3] <- gsub("<COPYRIGHT HOLDER>", cph, mit[3])
writeLines(mit, license_file)
return(invisible(NULL))
}
path("generic_template", "cc_by_4_0.md") |>
system.file(package = "checklist") |>
file_copy(license_file, overwrite = TRUE)
return(invisible(NULL))
}
11 changes: 10 additions & 1 deletion R/setup_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ setup_package <- function(path = ".", license = c("GPL-3", "MIT")) {

# add checklist.yml
if (!file_exists(path(path, "checklist.yml"))) {
x <- checklist$new(x = path, language = "en-GB", package = TRUE)
if (descript$has_fields("Language")) {
x <- checklist$new(
x = path, language = descript$get_field("Language"), package = TRUE
)
} else {
x <- checklist$new(x = path, language = "en-GB", package = TRUE)
descript$set("Language", "en-GB")
path(x$get_path, "DESCRIPTION") |>
descript$write()
}
x$set_required()
x$set_ignore(c(".github", "LICENSE.md"))
write_checklist(x)
Expand Down
5 changes: 1 addition & 4 deletions R/setup_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ setup_project <- function(path = ".") {
x$set_default(c("en-GB", "nl-BE", "fr-FR")[answer])

if ("license" %in% checks && !file_exists(path(path, "LICENSE.md"))) {
insert_file(
repo = repo, filename = "cc_by_4_0.md", template = "generic_template",
target = path, new_name = "LICENSE.md"
)
set_license(x)
}

x$set_required(checks = checks)
Expand Down
10 changes: 2 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,11 @@ checklist_diff <- function(root) {
if (inherits(try(git_info(repo = root), silent = TRUE), "try-error")) {
return(invisible(NULL))
}
branch_info <- git_branch_list(repo = root)
branch_info$ref[
grep("/main$", branch_info$ref) |>
c(grep("/master$", branch_info$ref)) |>
head(1)
] |>
git_diff(repo = root) -> changes
changes <- git_diff(repo = root)
if (length(changes) == 0) {
return(invisible(NULL))
}
cli_h1("git diff")
cli_h1("unstaged changes")
changes$patch |>
gsub(pattern = "^.*?index.*?\n.*?\n", replacement = "") |>
strsplit(split = "\n") |>
Expand Down
Loading

0 comments on commit 5649985

Please sign in to comment.