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

Add QC report #113

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3443a57
Add function for deleting files in SVN and QC log
michaelmcd18 Jun 17, 2024
39226e4
Update
michaelmcd18 Jun 18, 2024
0bad951
Update tests
michaelmcd18 Jun 18, 2024
f83c9c6
Update README
michaelmcd18 Jun 25, 2024
aeb66f0
Add QC report
michaelmcd18 Jul 11, 2024
70ac6a4
Update pkgdown
michaelmcd18 Jul 11, 2024
9c17b7e
Update pkgdown
michaelmcd18 Jul 11, 2024
c321631
Update tests
michaelmcd18 Jul 11, 2024
953a2fb
Merge pull request #109 from metrumresearchgroup/add-cheatsheet
graceannobrien Jul 25, 2024
7989a1d
display entire file diff argument
andersone1 Jul 30, 2024
d17b6f7
PR number
andersone1 Jul 30, 2024
74c3606
include github io in description
andersone1 Jul 30, 2024
049b69e
addtional url
andersone1 Jul 30, 2024
20e2dc9
Merge pull request #115 from metrumresearchgroup/show-all
andersone1 Jul 30, 2024
b76b60b
Add 4.2 and 4.3
michaelmcd18 Jul 1, 2024
43b9a94
Update tests
michaelmcd18 Jun 26, 2024
d0f5c32
Add diff tools vignette
michaelmcd18 Jun 26, 2024
a65aa86
Add getCommitHistory and mock up svnLog updates
michaelmcd18 Jul 30, 2024
8eeb366
Revert svnLog
michaelmcd18 Aug 2, 2024
fa3675c
Revert svnLog
michaelmcd18 Aug 2, 2024
ffac156
Update function
michaelmcd18 Aug 2, 2024
a90332b
Update function name
michaelmcd18 Aug 2, 2024
7553b97
Add function to pkgdown
michaelmcd18 Aug 2, 2024
759a078
Update version
michaelmcd18 Aug 5, 2024
092c769
Merge pull request #117 from metrumresearchgroup/release/3.9.1.9002
michaelmcd18 Aug 6, 2024
cc4101e
Update buildCompare.R
andersone1 Sep 18, 2024
bd5acce
Update DESCRIPTION
andersone1 Sep 18, 2024
64b5926
Merge pull request #122 from metrumresearchgroup/andersone1-patch-1
michaelmcd18 Sep 19, 2024
7320795
Update logDelete
michaelmcd18 Sep 19, 2024
74a228b
remove author warning from diffQCed
andersone1 Oct 24, 2024
dbb4e1f
Rename function
michaelmcd18 Oct 28, 2024
f147737
Update NEWS
michaelmcd18 Oct 28, 2024
4b097f8
Update logRemove
michaelmcd18 Oct 28, 2024
d82d18e
Update documentation
michaelmcd18 Oct 28, 2024
6437a55
Merge branch 'main' into file-delete
michaelmcd18 Oct 28, 2024
04bb107
Update the QC report
michaelmcd18 Oct 28, 2024
c1e83fc
Update pkgdown
michaelmcd18 Oct 28, 2024
7f46b1b
Add fileSummary function
michaelmcd18 Oct 28, 2024
ff707cb
Update pkgdown
michaelmcd18 Oct 28, 2024
560dfd2
Styler on code
michaelmcd18 Oct 28, 2024
56e4965
edits to file summary
andersone1 Oct 30, 2024
9079dac
Update fileSummary
michaelmcd18 Oct 30, 2024
742cbb6
use svn log
andersone1 Oct 31, 2024
01ea408
Add findAuthorsQcers
michaelmcd18 Oct 31, 2024
fa5c0b2
NEWS and test
andersone1 Oct 31, 2024
0ebe9b1
Merge pull request #105 from metrumresearchgroup/file-delete
andersone1 Oct 31, 2024
5574bb7
Add QC report
michaelmcd18 Jul 11, 2024
b36386c
Update pkgdown
michaelmcd18 Jul 11, 2024
47dc717
Update tests
michaelmcd18 Jul 11, 2024
5a7a71f
Update the QC report
michaelmcd18 Oct 28, 2024
b9be24c
Merge branch 'qc-report' of github.com:metrumresearchgroup/review int…
andersone1 Oct 31, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
r: 4.0.5
- os: ubuntu-20.04
r: 4.1.3
- os: ubuntu-20.04
r: 4.2.3
- os: ubuntu-20.04
r: 4.3.1
- os: ubuntu-latest
r: release
env:
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: review
Title: QC Management and Helpers
Version: 3.9.1
Version: 3.9.1.9003
Authors@R:
c(
person(given = "Eric", family = "Anderson", email = "[email protected]", role = c("aut")),
Expand All @@ -9,12 +9,12 @@ Authors@R:
)
Description: Functions for managing logs of reviews of subversioned
files (http://subversion.apache.org/).
URL: https://github.com/metrumresearchgroup/review
URL: https://github.com/metrumresearchgroup/review, https://metrumresearchgroup.github.io/review/
BugReports: https://github.com/metrumresearchgroup/review/issues
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
dplyr,
magrittr (>= 2.0.3),
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ export(diffFiles)
export(diffPreviousRevisions)
export(diffQced)
export(dirSummary)
export(fileSummary)
export(getQcedRevision)
export(logAccept)
export(logAssign)
export(logCreate)
export(logPending)
export(logRemove)
export(logSummary)
export(renderQCReport)
export(renderQCSummary)
export(repoHistory)
export(svnExport)
export(svnLog)
export(with_demoRepo)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# review development

## New features and changes

- `logRemove` added to package to assist with removing files from the QC log. (#105)

- `diffFiles` can now display the entire file that is being diffed. (#115)

- Added `repoHistory` function to return history of all commits in the repository. (#116)

# review 3.9.1

## New features and changes
Expand Down
4 changes: 2 additions & 2 deletions R/buildCompare.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ buildCompare <- function(.dfpaths, .side_by_side, .headings, .show_on_load = TRU

}

base_path.i <- .dfpaths$path2[i]
compare_path.i <- .dfpaths$path1[i]
base_path.i <- .dfpaths$path1[i]
compare_path.i <- .dfpaths$path2[i]


# Unique IDs for HTML elements
Expand Down
7 changes: 5 additions & 2 deletions R/diffFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' @param .banner_2 Header for second file in viewer
#' @param .side_by_side Logical. Should diffs be displayed side by side?
#' @param .ignore_white_space Logical. Should white space be ignored?
#' @param .display_entire_file Logical. Should the entire file be displayed?
#' @examples
#' with_demoRepo({
#' diffFiles(.file_1 = "script/data-assembly.R",
Expand All @@ -26,7 +27,8 @@ diffFiles <- function(.file_1,
.banner_1 = NULL,
.banner_2 = NULL,
.side_by_side = TRUE,
.ignore_white_space = FALSE) {
.ignore_white_space = FALSE,
.display_entire_file = FALSE) {

if (is.null(.banner_1)) {
.banner_1 = basename(.file_1)
Expand All @@ -43,7 +45,8 @@ diffFiles <- function(.file_1,
mode = ifelse(.side_by_side, "sidebyside", "unified"),
tar.banner = .banner_1,
cur.banner = .banner_2,
ignore.white.space = .ignore_white_space
ignore.white.space = .ignore_white_space,
context = ifelse(.display_entire_file, -1, 2)
)

}
7 changes: 5 additions & 2 deletions R/diffPreviousRevisions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @param .current_revision current revision (defaults to local copy)
#' @param .side_by_side Logical. Should diffs be displayed side by side?
#' @param .ignore_white_space Logical. Should white space be ignored?
#' @param .display_entire_file Logical. Should the entire file be displayed?
#'
#' @examples
#' with_demoRepo({
Expand All @@ -22,7 +23,8 @@ diffPreviousRevisions <- function(.file,
.previous_revision,
.current_revision = NULL,
.side_by_side = TRUE,
.ignore_white_space = FALSE){
.ignore_white_space = FALSE,
.display_entire_file = FALSE){

previousCurrent <-
getPreviousCurrent(
Expand All @@ -42,7 +44,8 @@ diffPreviousRevisions <- function(.file,
.banner_1 = previousCurrent$.previous_revision_header,
.banner_2 = previousCurrent$.current_revision_header,
.side_by_side = .side_by_side,
.ignore_white_space = .ignore_white_space
.ignore_white_space = .ignore_white_space,
.display_entire_file = .display_entire_file
)

}
20 changes: 7 additions & 13 deletions R/diffQced.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#' @param .file file path from working directory
#' @param .side_by_side Logical. Should diffs be displayed side by side?
#' @param .ignore_white_space Logical. Should white space be ignored?
#' @param .display_entire_file Logical. Should the entire file be displayed?
#'
#' @examples
#' with_demoRepo({
#' diffQced("script/data-assembly.R")
#' })
#'
#' @export
diffQced <- function(.file, .side_by_side = TRUE, .ignore_white_space = FALSE){
diffQced <- function(.file,
.side_by_side = TRUE,
.ignore_white_space = FALSE,
.display_entire_file = FALSE){

up_to_date <-
tryCatch(
Expand All @@ -38,26 +42,16 @@ diffQced <- function(.file, .side_by_side = TRUE, .ignore_white_space = FALSE){
file_log <- svnLog(.file)
file_info <- file_log %>% dplyr::slice(1)

authors_last_qc <-
file_log %>%
dplyr::filter(rev > qced_revision) %>%
dplyr::pull(author)

cli::cli_h2(glue::glue("QC diff for: ", .file))
cli::cli_inform(glue::glue("Last QCed Revision: ", qced_revision))
cli::cli_inform(glue::glue("Last Author: ", file_info$author))

this_user <- Sys.info()[["user"]]

if (this_user %in% authors_last_qc) {
cli::cli_alert_warning(glue::glue("'{this_user}' has modified '{basename(.file)}' since last QC"))
}

diffPreviousRevisions(
.file = .file,
.previous_revision = qced_revision,
.side_by_side = .side_by_side,
.ignore_white_space = .ignore_white_space
.ignore_white_space = .ignore_white_space,
.display_entire_file = .display_entire_file
)

}
144 changes: 144 additions & 0 deletions R/fileSummary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#' Summarize revision and QC history for a file
#'
#' @description
#' Generates a comprehensive summary of the revision and quality control (QC) history
#' for a file. The function reports:
#' * QC status (up to date, needs QC, or not assigned)
#' * Presence in the QC log
#' * Historical information about previous authors
#' * Historical information about previous QC reviewers
#'
#' @param .file File path.
#'
#' @details
#' The function prints a formatted summary to the console and invisibly returns
#' the data for programmatic use. Non-existent files generate warnings and are
#' skipped. Files not found in the repository history are also skipped.
#'
#' QC status can be:
#' * "QC up to date" - Latest revision has been QC'd
#' * "Needs QC" - New changes need review
#' * "Not assigned" - File not in QC system
#'
#' @examples
#' \dontrun{
#' # Analyze a single script file
#' fileSummary("script/data-assembly/study-101.R")
#'
#' # Process all files in a directory
#' purrr::walk(list.files("script/data-assembly", full.names = TRUE), ~ fileSummary(.file = .x))
#' }
#'
#' @export
fileSummary <- function(.file) {
if (length(.file) != 1) {
stop("'.file' must be a single file path")
}

if (!file.exists(.file)) {
warning(paste0(.file, " does not exist"))
return(invisible(NULL))
}

# Initialize output list
out <- list()
out$qclog <- cli::col_red("No")
out$qcstatus <- cli::col_magenta("Not assigned")
out$prevQC <- "No previous QC"

# Get repo history and QC log

# Get repo commit history for the file
script_history <- svnLog(.file)
script_history$date <- as.Date(script_history$datetime)

qc_log <- logRead()

if (nrow(script_history) == 0) {
warning(paste0(.file, " has no svn history"))
return(invisible(NULL))
}

# Get last revision of the file
last_rev <- as.numeric(script_history$rev[1])

# Filter QC log to file of interest
qc_file <- qc_log[qc_log$file == .file, ]

# Check if file is in QC log
if (nrow(qc_file) > 0) {

out$qclog <- cli::col_green("Yes")

# Process QC history
qc_file_filtered <- qc_file %>% dplyr::filter(revf != 0)

# For cases where no QC has been previously completed
if (nrow(qc_file_filtered) == 0) {

out$qcstatus <- cli::col_red("Needs QC")

} else {

qc_rev <-
qc_file_filtered %>%
dplyr::arrange(-as.numeric(revf)) %>%
dplyr::slice(1) %>%
dplyr::pull(revf) %>%
as.numeric()

out$prevQC <-
qc_file_filtered %>%
dplyr::arrange(-as.numeric(revf)) %>%
dplyr::group_by(reviewer) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
dplyr::transmute(VALUE = paste0(
reviewer, ", ",
as.numeric(difftime(Sys.Date(), as.Date(time), units = "days")),
" days ago"
)) %>%
dplyr::pull()

out$qcstatus <-
ifelse(
last_rev > qc_rev,
cli::col_red("Needs QC"),
cli::col_green("QC up to date")
)

}

}

# Process author history
out$authors <-
script_history %>%
dplyr::group_by(author) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
dplyr::arrange(-as.numeric(rev)) %>%
dplyr::transmute(VALUE = paste0(
author, ", ",
as.numeric(difftime(Sys.Date(), date, units = "days")),
" days ago"
)) %>%
dplyr::pull()

# Print summary
cli::cli_h2(glue::glue(.file, " summary"))
cli::cli_inform(glue::glue("In QC log: ", out$qclog))
cli::cli_inform(glue::glue("QC status: ", out$qcstatus))

cli::cli_verbatim("") # line break
cli::cli_inform("Previous QCer(s): ")
names(out$prevQC) <- rep(">", length(out$prevQC))
cli::cli_bullets(out$prevQC)

cli::cli_verbatim("") # line break
cli::cli_inform("Previous author(s): ")
names(out$authors) <- rep(">", length(out$authors))
cli::cli_bullets(out$authors)

return(invisible(out))
}
27 changes: 27 additions & 0 deletions R/findAuthorsQcers.R
Original file line number Diff line number Diff line change
@@ -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)
}
24 changes: 24 additions & 0 deletions R/logRemove.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Remove file from QClog
#'
#' @description
#' This function facilitates deleting a file from the QClog.csv file.
#' When run, all rows associated with the file will be deleted and
#' removed from the QC log.
#'
#' @param .filepath current file path of file to be removed
#'
#' @export
logRemove <- function(.filepath) {

qclog <- logRead()
qclog2 <- qclog[qclog$file != .filepath, ]

# Check current file path exists
if(nrow(qclog) == nrow(qclog2)) {
stop(paste0(.filepath, " does not exist in QClog.csv"))
}

cli::cli_alert_info(glue::glue("Deleted '{.filepath}' from QClog.csv"))

logWrite(qclog2, file = "QClog.csv")
}
Loading
Loading