-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the recording of package version/check issues
- Loading branch information
Showing
10 changed files
with
218 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' @title Record package issues. | ||
#' @export | ||
#' @description Record package check and version issues in individual JSON | ||
#' files. | ||
#' @return `NULL` (invisibly). | ||
#' @param manifest Character of length 1, file path to a JSON manifest | ||
#' tracking release versions of packages. | ||
#' @param output Character of length 1, file path to the folder to record | ||
#' new package issues. Each call to `record_issues()` overwrites the | ||
#' contents of the repo. | ||
record_issues <- function( | ||
manifest = "versions.json", | ||
output = "issues" | ||
) { | ||
issues_version <- version_issues(manifest) | ||
issues <- issues_version # Will include check issues too later. | ||
overwrite_issues(issues, output) | ||
invisible() | ||
} | ||
|
||
overwrite_issues <- function(issues, output) { | ||
unlink(output, recursive = TRUE) | ||
dir.create(output) | ||
for (index in seq_len(nrow(issues))) { | ||
row <- vctrs::vec_slice(x = issues, i = index) | ||
jsonlite::write_json(row, file.path(output, row$package)) | ||
} | ||
} | ||
|
||
version_issues <- function(manifest) { | ||
manifest <- jsonlite::read_json(path = manifest, simplifyVector = TRUE) | ||
aligned <- (manifest$version_current == manifest$version_highest) & | ||
(manifest$hash_current == manifest$hash_highest) | ||
aligned[is.na(aligned)] <- TRUE | ||
out <- manifest[!aligned,, drop = FALSE] # nolint | ||
if (nrow(out)) { | ||
out$version_okay <- FALSE | ||
} | ||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
test_that("version_issues() in a mock repo", { | ||
# Temporary files used in the mock test. | ||
manifest <- tempfile() | ||
# First update to the manifest. | ||
contents <- data.frame( | ||
package = c( | ||
"package_unmodified", | ||
"version_decremented", | ||
"version_incremented", | ||
"version_unmodified" | ||
), | ||
version_current = rep("1.0.0", 4L), | ||
hash_current = rep("hash_1.0.0", 4L) | ||
) | ||
record_versions(manifest = manifest, current = contents) | ||
expect_equal( | ||
version_issues(manifest), | ||
data.frame( | ||
package = character(0L), | ||
version_current = character(0L), | ||
hash_current = character(0L) | ||
) | ||
) | ||
# Update the manifest after no changes to packages or versions. | ||
suppressMessages( | ||
record_versions(manifest = manifest, current = contents) | ||
) | ||
expect_equal( | ||
version_issues(manifest), | ||
data.frame( | ||
package = character(0L), | ||
version_current = character(0L), | ||
hash_current = character(0L), | ||
version_highest = character(0L), | ||
hash_highest = character(0L) | ||
) | ||
) | ||
# Update the packages in all the ways indicated above. | ||
index <- contents$package == "version_decremented" | ||
contents$version_current[index] <- "0.0.1" | ||
contents$hash_current[index] <- "hash_0.0.1" | ||
index <- contents$package == "version_incremented" | ||
contents$version_current[index] <- "2.0.0" | ||
contents$hash_current[index] <- "hash_2.0.0" | ||
index <- contents$package == "version_unmodified" | ||
contents$version_current[index] <- "1.0.0" | ||
contents$hash_current[index] <- "hash_1.0.0-modified" | ||
for (index in seq_len(2L)) { | ||
record_versions( | ||
manifest = manifest, | ||
current = contents | ||
) | ||
out <- version_issues(manifest) | ||
rownames(out) <- NULL | ||
expect_equal( | ||
out, | ||
data.frame( | ||
package = c("version_decremented", "version_unmodified"), | ||
version_current = c("0.0.1", "1.0.0"), | ||
hash_current = c("hash_0.0.1", "hash_1.0.0-modified"), | ||
version_highest = c("1.0.0", "1.0.0"), | ||
hash_highest = c("hash_1.0.0", "hash_1.0.0"), | ||
version_okay = c(FALSE, FALSE) | ||
) | ||
) | ||
} | ||
# Remove temporary files | ||
unlink(manifest) | ||
}) | ||
|
||
test_that("record_issues() in a mock repo", { | ||
# Temporary files used in the mock test. | ||
manifest <- tempfile() | ||
output <- tempfile() | ||
# First update to the manifest. | ||
contents <- data.frame( | ||
package = c( | ||
"package_unmodified", | ||
"version_decremented", | ||
"version_incremented", | ||
"version_unmodified" | ||
), | ||
version_current = rep("1.0.0", 4L), | ||
hash_current = rep("hash_1.0.0", 4L) | ||
) | ||
record_versions(manifest = manifest, current = contents) | ||
record_issues(manifest = manifest, output = output) | ||
expect_equal(list.files(output), character(0L)) | ||
# Update the manifest after no changes to packages or versions. | ||
suppressMessages( | ||
record_versions(manifest = manifest, current = contents) | ||
) | ||
record_issues(manifest = manifest, output = output) | ||
expect_equal(list.files(output), character(0L)) | ||
# Update the packages in all the ways indicated above. | ||
index <- contents$package == "version_decremented" | ||
contents$version_current[index] <- "0.0.1" | ||
contents$hash_current[index] <- "hash_0.0.1" | ||
index <- contents$package == "version_incremented" | ||
contents$version_current[index] <- "2.0.0" | ||
contents$hash_current[index] <- "hash_2.0.0" | ||
index <- contents$package == "version_unmodified" | ||
contents$version_current[index] <- "1.0.0" | ||
contents$hash_current[index] <- "hash_1.0.0-modified" | ||
for (index in seq_len(2L)) { | ||
record_versions( | ||
manifest = manifest, | ||
current = contents | ||
) | ||
record_issues(manifest = manifest, output = output) | ||
expect_equal( | ||
sort(list.files(output)), | ||
sort(c("version_decremented", "version_unmodified")) | ||
) | ||
out <- jsonlite::read_json(file.path(output, "version_decremented")) | ||
expect_equal( | ||
unlist(out, recursive = TRUE), | ||
c( | ||
package = "version_decremented", | ||
version_current = "0.0.1", | ||
hash_current = "hash_0.0.1", | ||
version_highest = "1.0.0", | ||
hash_highest = "hash_1.0.0", | ||
version_okay = FALSE | ||
) | ||
) | ||
out <- jsonlite::read_json(file.path(output, "version_unmodified")) | ||
expect_equal( | ||
unlist(out, recursive = TRUE), | ||
c( | ||
package = "version_unmodified", | ||
version_current = "1.0.0", | ||
hash_current = "hash_1.0.0-modified", | ||
version_highest = "1.0.0", | ||
hash_highest = "hash_1.0.0", | ||
version_okay = FALSE | ||
) | ||
) | ||
} | ||
# Remove temporary files | ||
unlink(manifest) | ||
}) |
Oops, something went wrong.