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

Provide default to get_fields #19

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Changes from 3 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
19 changes: 14 additions & 5 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ runs:
cat("::group::Define utils\n")
desc_field_append <- function(d, key, value) {
old_values <- d$get_field(key)
old_values_v <- trimws(strsplit(x = old_values, split = ",")[[1]])
old_values_v <- parse_input(old_values)
new_values_v <- unique(c(old_values_v, value))
new_values <- paste(new_values_v, collapse = ", ")
d$set_list(key, new_values)
}
desc_field_clear_if_empty <- function(d, key) {
if (d$has_fields(key) && d$get_field(key) == "") {
if (empty_field(d, key)) {
d$del(key)
}
}
Expand Down Expand Up @@ -220,6 +220,15 @@ runs:
parse_input <- function(input) {
trimws(strsplit(x = gsub("\n", ",", input), split = ",")[[1]])
}

empty_field <- function(d, field) {
d$has_fields(field) && !nzchar(d$get_field(field, ""))
}

get_parsed_input <- function(d, field) {
parse_input(d$get_field(field, ""))
}
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved

log_vars <- function(...) {
args <- list(...)
arg_names <- substitute(...())
Expand Down Expand Up @@ -394,16 +403,16 @@ runs:
}

# skip if already there
if (pkg_ref$ref %in% d$get_field("Config/Needs/DepsDev")) {
if (pkg_ref$ref %in% get_parsed_input(d, "Config/Needs/DepsDev")) {
cli::cli_alert_info("Reference for package {.pkg {pkg}} already exists in the {.field Config/Needs/DepsDev} field. Skipping.")
next()
}

# skip if already in `DepsBranch`
# this is to avoid duplicates - `Deps Branch` takes precedence over `DepsDev`
if (
(!identical(d$get_field("Config/Needs/DepsBranch"), "")) &&
(pkg %in% vapply(d$get_field("Config/Needs/DepsBranch"), function(x) pkgdepends::parse_pkg_ref(x)$package, character(1)))
(!identical(get_parsed_input(d, "Config/Needs/DepsBranch"), "")) &&
(pkg %in% vapply(get_parsed_input(d, "Config/Needs/DepsBranch"), function(x) {if (x == "") { character(1L)} else {pkgdepends::parse_pkg_ref(x)$package}}, character(1)))
) {
cli::cli_alert_info("A reference for package {.pkg {pkg}} already exists in the {.field Config/Needs/DepsBranch} field. Skipping.")
next()
Expand Down
Loading