Skip to content

Commit

Permalink
Improve linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Feb 27, 2024
1 parent 2d6b569 commit aa16983
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 41 deletions.
72 changes: 48 additions & 24 deletions R/cff_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
14 changes: 10 additions & 4 deletions R/cff_gha_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -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?
#'
Expand All @@ -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{
Expand Down
13 changes: 10 additions & 3 deletions R/cff_git_hook.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
#'
Expand Down
8 changes: 6 additions & 2 deletions R/cff_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
8 changes: 4 additions & 4 deletions man/cff_gha_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/cff_git_hook.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/cff_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa16983

Please sign in to comment.