diff --git a/R/findAuthorsQcers.R b/R/findAuthorsQcers.R new file mode 100644 index 0000000..6fc07d6 --- /dev/null +++ b/R/findAuthorsQcers.R @@ -0,0 +1,27 @@ +#' @noRd +findAuthorsQcers <- function(.repoHistory, .qcLog) { + + qclog <- + .qcLog %>% + dplyr::transmute(file, rev = as.character(revf), reviewer) %>% + dplyr::filter(rev != "0") %>% + dplyr::distinct() + + rH_qclog <- + .repoHistory %>% + dplyr::left_join(qclog, by = c("file", "rev")) %>% + dplyr::arrange(file, -as.numeric(rev)) %>% + dplyr::group_by(file) %>% + tidyr::fill(reviewer, .direction = "down") %>% + dplyr::ungroup() + + out <- list() + + out$authors <- rH_qclog %>% dplyr::filter(is.na(reviewer) | author != reviewer) + + out$qcers <- rH_qclog %>% dplyr::filter(author == reviewer) + + stopifnot(nrow(.repoHistory) == nrow(out$authors) + nrow(out$qcers)) + + return(out) +} \ No newline at end of file diff --git a/tests/testthat/test-findAuthorsQcers.R b/tests/testthat/test-findAuthorsQcers.R new file mode 100644 index 0000000..a829c86 --- /dev/null +++ b/tests/testthat/test-findAuthorsQcers.R @@ -0,0 +1,23 @@ +create_test_svn() + +review::logAccept("script/data-assembly/da-functions.R") + +qclog <- logRead() +df_history <- repoHistory() + +authors_qcers <- findAuthorsQcers(.repoHistory = df_history, .qcLog = qclog) + +test_that("findAuthorsQcers works as expected", { + + expect_equal(length(authors_qcers), 2) + expect_equal(names(authors_qcers), c("authors", "qcers")) + expect_true(inherits(authors_qcers, "list")) + expect_true(inherits(authors_qcers$authors, "data.frame")) + + expect_true(all(authors_qcers$qcers$author == authors_qcers$qcers$reviewer)) + expect_true(all(is.na(authors_qcers$authors$reviewer) | + authors_qcers$authors$author != authors_qcers$authors$reviewer)) + + expect_true(nrow(authors_qcers$authors %>% dplyr::distinct(file, rev)) == nrow(authors_qcers$authors)) + +})