diff --git a/R/cff_create.R b/R/cff_create.R index d43ff43c..2e14f2b7 100644 --- a/R/cff_create.R +++ b/R/cff_create.R @@ -124,6 +124,48 @@ cff_create <- function(x, keys = list(), cff_version = "1.2.0", cli::cli_abort(msg) } + # Detect sources and build cff + result_parsed <- detect_sources( + x, cff_version, gh_keywords, + dependencies, authors_roles + ) + + desc_path <- result_parsed[["desc_path"]] + instpack <- result_parsed[["instpack"]] + cffobjend <- result_parsed[["cffobjend"]] + + + + # Add software dependencies + if (dependencies) { + deps <- parse_dependencies(desc_path, instpack) + + cffobjend$references <- unique(c(cffobjend$references, deps)) + } + + # Additional keys + if (!is.null(keys)) { + keys <- fuzzy_keys(keys) + cffobjendmod <- cffobjend[setdiff(names(cffobjend), names(keys))] + cffobjend <- modifyList(cffobjendmod, keys, keep.null = FALSE) + cffobjend <- as.cff(cffobjend) + } + + + # Order + cffobjend <- cffobjend[cff_schema_keys()] + + # Enhance authors info + if (!is.null(cffobjend$`preferred-citation`)) { + cffobjend$`preferred-citation`$authors <- enhance_pref_authors(cffobjend) + } + cffobjend <- as.cff(cffobjend) + cffobjend +} + +detect_sources <- function(x, cff_version = "1.2.0", + gh_keywords = TRUE, dependencies = TRUE, + authors_roles = c("aut", "cre")) { instpack <- as.character(installed.packages()[, "Package"]) # Set initially citobj to NULL @@ -183,29 +225,11 @@ cff_create <- function(x, keys = list(), cff_version = "1.2.0", cffobjend <- merge_desc_cit(cffobj, citobj) - # Add software dependencies - if (dependencies) { - deps <- parse_dependencies(desc_path, instpack) - - cffobjend$references <- unique(c(cffobjend$references, deps)) - } + # Return collected info - # Additional keys - if (!is.null(keys)) { - keys <- fuzzy_keys(keys) - cffobjendmod <- cffobjend[setdiff(names(cffobjend), names(keys))] - cffobjend <- modifyList(cffobjendmod, keys, keep.null = FALSE) - cffobjend <- as.cff(cffobjend) - } - - - # Order - cffobjend <- cffobjend[cff_schema_keys()] - - # Enhance authors info - if (!is.null(cffobjend$`preferred-citation`)) { - cffobjend$`preferred-citation`$authors <- enhance_pref_authors(cffobjend) - } - cffobjend <- as.cff(cffobjend) - cffobjend + list( + desc_path = desc_path, + instpack = instpack, + cffobjend = cffobjend + ) } diff --git a/R/cff_gha_update.R b/R/cff_gha_update.R index 22ffedf7..5d53b0bc 100644 --- a/R/cff_gha_update.R +++ b/R/cff_gha_update.R @@ -2,13 +2,14 @@ #' #' @description #' -#' This function would install a GitHub Action on your repo. The action +#' This function would install a +#' [GitHub Action](https://github.com/features/actions) on your repo. The action #' will update your `CITATION.cff` when any of these events occur: #' - You publish a new release of the package. #' - Your `DESCRIPTION` or `inst/CITATION` are modified. #' - The action can be run also manually. #' -#' @param path Project directory +#' @param path Project directory. #' @param overwrite Logical. If already present, do you want to overwrite your #' action? #' @@ -17,8 +18,13 @@ #' @details #' #' Triggers on your action can be modified, see -#' [Events that trigger -#' workflows](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows). +#' ```{r, echo=FALSE, results='asis'} +#' +#' cat(paste0(" [Events that trigger workflows]", +#' "(https://docs.github.com/en/actions/learn-github-actions/", +#' "events-that-trigger-workflows).")) +#' +#' ``` #' #' @examples #' \dontrun{ diff --git a/R/cff_git_hook.R b/R/cff_git_hook.R index f1c2d7aa..55e1bbd9 100644 --- a/R/cff_git_hook.R +++ b/R/cff_git_hook.R @@ -2,8 +2,15 @@ #' #' @description #' -#' Install a [pre-commit -#' hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks) +#' Install a +#' +#' ```{r, echo=FALSE, results='asis'} +#' +#' cat(paste0(" [pre-commit hook]", +#' "(https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks", +#' "#_committing_workflow_hooks) ")) +#' +#' ``` #' that remembers you to update your `CITATION.cff` file. #' #' @name cff_git_hook @@ -26,7 +33,7 @@ #' following conditions are met: #' - You included in a commit your `DESCRIPTION` or `inst/CITATION` file, you #' are not including your `CITATION.cff` and the `CITATION.cff` file is -#' "older" than any of your `DESCRIPTION` or `inst/CITATION` file, or +#' "older" than any of your `DESCRIPTION` or `inst/CITATION` file. #' - You have updated your `CITATION.cff` but you are not including it on #' your commit. #' diff --git a/R/cff_read.R b/R/cff_read.R index 7dc337b8..0dd87517 100644 --- a/R/cff_read.R +++ b/R/cff_read.R @@ -81,14 +81,18 @@ #' head(from_cff_file, 7) #' #' # Create cff object from DESCRIPTION -#' from_desc <- cff_read(system.file("examples/DESCRIPTION_basic", package = "cffr")) +#' from_desc <- cff_read(system.file("examples/DESCRIPTION_basic", +#' package = "cffr" +#' )) #' #' from_desc #' #' # Create cff object from BibTex #' #' if (requireNamespace("bibtex", quietly = TRUE)) { -#' from_bib <- cff_read(system.file("examples/example.bib", package = "cffr")) +#' from_bib <- cff_read(system.file("examples/example.bib", +#' package = "cffr" +#' )) #' #' # First item only #' from_bib[[1]] diff --git a/man/cff_gha_update.Rd b/man/cff_gha_update.Rd index 65568d81..c45049d9 100644 --- a/man/cff_gha_update.Rd +++ b/man/cff_gha_update.Rd @@ -7,7 +7,7 @@ cff_gha_update(path = ".", overwrite = FALSE) } \arguments{ -\item{path}{Project directory} +\item{path}{Project directory.} \item{overwrite}{Logical. If already present, do you want to overwrite your action?} @@ -16,7 +16,8 @@ action?} Invisible, this function is called by its side effects. } \description{ -This function would install a GitHub Action on your repo. The action +This function would install a +\href{https://github.com/features/actions}{GitHub Action} on your repo. The action will update your \code{CITATION.cff} when any of these events occur: \itemize{ \item You publish a new release of the package. @@ -25,8 +26,7 @@ will update your \code{CITATION.cff} when any of these events occur: } } \details{ -Triggers on your action can be modified, see -\href{https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows}{Events that trigger workflows}. +Triggers on your action can be modified, see \href{https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows}{Events that trigger workflows}. } \examples{ \dontrun{ diff --git a/man/cff_git_hook.Rd b/man/cff_git_hook.Rd index 2a614676..85a7f720 100644 --- a/man/cff_git_hook.Rd +++ b/man/cff_git_hook.Rd @@ -14,7 +14,8 @@ cff_git_hook_remove() Invisible. This function is called for its side effects. } \description{ -Install a \href{https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks}{pre-commit hook} +Install a +\href{https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks}{pre-commit hook} that remembers you to update your \code{CITATION.cff} file. } \details{ @@ -27,7 +28,7 @@ following conditions are met: \itemize{ \item You included in a commit your \code{DESCRIPTION} or \code{inst/CITATION} file, you are not including your \code{CITATION.cff} and the \code{CITATION.cff} file is -"older" than any of your \code{DESCRIPTION} or \code{inst/CITATION} file, or +"older" than any of your \code{DESCRIPTION} or \code{inst/CITATION} file. \item You have updated your \code{CITATION.cff} but you are not including it on your commit. } diff --git a/man/cff_read.Rd b/man/cff_read.Rd index a443541f..6e97814b 100644 --- a/man/cff_read.Rd +++ b/man/cff_read.Rd @@ -92,14 +92,18 @@ from_cff_file <- cff_read(system.file("examples/CITATION_basic.cff", head(from_cff_file, 7) # Create cff object from DESCRIPTION -from_desc <- cff_read(system.file("examples/DESCRIPTION_basic", package = "cffr")) +from_desc <- cff_read(system.file("examples/DESCRIPTION_basic", + package = "cffr" +)) from_desc # Create cff object from BibTex if (requireNamespace("bibtex", quietly = TRUE)) { - from_bib <- cff_read(system.file("examples/example.bib", package = "cffr")) + from_bib <- cff_read(system.file("examples/example.bib", + package = "cffr" + )) # First item only from_bib[[1]]