Skip to content

Commit

Permalink
Record date that an issue was first noticed
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed May 22, 2024
1 parent 8ce5547 commit 1cad4f0
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 16 deletions.
57 changes: 47 additions & 10 deletions R/record_issues.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @title Record package issues.
#' @export
#' @keywords package check data management
#' @description Record R-multiverse package issues in compact JSON files.
#' @description Record R-multiverse package issues in
#' package-specific JSON files.
#' @section Package checks for production:
#' Functions like [check_versions()] and [check_descriptions()]
#' perform health checks for all packages in R-multiverse.
Expand All @@ -12,6 +13,16 @@
#' [record_versions()] updates the version number history
#' of releases in R-multiverse, and [record_issues()] gathers
#' together all the issues about R-multiverse packages.
#' @section Issue files:
#' For each package with observed problems, [record_issues()] writes
#' an issue file. This issue file is a JSON list with one element
#' per type of failing check. Each element has an informative name
#' (for example, `checks`, `descriptions`, or `versions`)
#' and a list of diagnostic information.
#'
#' Each issue file also has a `date` field. This date the day that
#' an issue was first noticed. It automatically resets the next time
#' all package are resolved.
#' @return `NULL` (invisibly).
#' @inheritParams check_checks
#' @inheritParams check_versions
Expand Down Expand Up @@ -49,11 +60,12 @@ record_issues <- function(
output = "issues",
mock = NULL
) {
today <- mock$today %|||% format(Sys.Date(), fmt = "yyyy-mm-dd")
list() |>
issues(check_checks(repo, mock$checks), "checks") |>
issues(check_descriptions(repo, mock$descriptions), "descriptions") |>
issues(check_versions(versions = versions), "versions") |>
overwrite_issues(output = output)
overwrite_issues(output = output, today = today)
invisible()
}

Expand All @@ -64,14 +76,39 @@ issues <- function(total, subset, category) {
total
}

overwrite_issues <- function(issues, output) {
overwrite_issues <- function(issues, output, today) {
packages <- list.files(output)
dates <- lapply(
X = packages,
FUN = function(path) {
jsonlite::read_json(file.path(output, path), simplifyVector = TRUE)$date
}
)
names(dates) <- packages
unlink(output, recursive = TRUE)
dir.create(output)
for (package in names(issues)) {
jsonlite::write_json(
x = issues[[package]],
path = file.path(output, package),
pretty = TRUE
)
}
lapply(
X = names(issues),
FUN = overwrite_package_issues,
issues = issues,
output = output,
today = today,
dates = dates
)
}

overwrite_package_issues <- function(
package,
issues,
output,
today,
dates
) {
path <- file.path(output, package)
issues[[package]]$date <- dates[[package]] %|||% today
jsonlite::write_json(
x = issues[[package]],
path = file.path(output, package),
pretty = TRUE
)
}
16 changes: 15 additions & 1 deletion man/record_issues.Rd

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

75 changes: 70 additions & 5 deletions tests/testthat/test-record_issues.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ test_that("record_issues() mocked", {
versions = mock_versions(),
mock = list(
checks = mock_checks,
descriptions = mock_descriptions
descriptions = mock_descriptions,
today = "2024-01-01"
),
output = output
)
Expand Down Expand Up @@ -37,7 +38,8 @@ test_that("record_issues() mocked", {
"_winbinary" = "src-failure",
"_status" = "src-failure",
"_buildurl" = file.path(runs, "8487512222")
)
),
date = "2024-01-01"
)
)
expect_equal(
Expand All @@ -56,7 +58,8 @@ test_that("record_issues() mocked", {
),
descriptions = list(
remotes = matrix(c("hyunjimoon/SBC", "stan-dev/cmdstanr"), nrow = 1)
)
),
date = "2024-01-01"
)
)
expect_equal(
Expand All @@ -70,7 +73,8 @@ test_that("record_issues() mocked", {
hash_current = "hash_0.0.1",
version_highest = "1.0.0",
hash_highest = "hash_1.0.0"
)
),
date = "2024-01-01"
)
)
expect_equal(
Expand All @@ -84,11 +88,72 @@ test_that("record_issues() mocked", {
hash_current = "hash_1.0.0-modified",
version_highest = "1.0.0",
hash_highest = "hash_1.0.0"
)
),
date = "2024-01-01"
)
)
})

test_that("record_issues() date works", {
output <- tempfile()
record_issues(
versions = mock_versions(),
mock = list(
checks = mock_checks,
descriptions = mock_descriptions,
today = "2024-01-01"
),
output = output
)
record_issues(
versions = mock_versions(),
mock = list(
checks = mock_checks,
descriptions = mock_descriptions
),
output = output
)
for (file in list.files(output, full.names = TRUE)) {
date <- jsonlite::read_json(file, simplifyVector = TRUE)$date
expect_equal(date, "2024-01-01")
}
never_fixed <- c(
"httpgd",
"INLA",
"stantargets",
"string2path",
"tidytensor",
"version_decremented"
)
once_fixed <- c(
"audio.whisper",
"polars",
"SBC",
"tidypolars",
"version_unmodified"
)
lapply(file.path(output, once_fixed), unlink)
record_issues(
versions = mock_versions(),
mock = list(
checks = mock_checks,
descriptions = mock_descriptions
),
output = output
)
for (package in never_fixed) {
path <- file.path(output, package)
date <- jsonlite::read_json(path, simplifyVector = TRUE)$date
expect_equal(date, "2024-01-01")
}
today <- format(Sys.Date(), fmt = "yyyy-mm-dd")
for (package in once_fixed) {
path <- file.path(output, package)
date <- jsonlite::read_json(path, simplifyVector = TRUE)$date
expect_equal(date, today)
}
})

test_that("record_issues() on a small repo", {
output <- tempfile()
versions <- tempfile()
Expand Down

0 comments on commit 1cad4f0

Please sign in to comment.