From 2c143d83181acbdf6085ec5959c1b8eedeff892a Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 15 Oct 2024 12:21:29 +0000 Subject: [PATCH] Move parsing methods for commits, files, users and release logs. --- R/EngineGraphQLGitHub.R | 127 +++++++++++++ R/EngineGraphQLGitLab.R | 110 +++++++++++ R/EngineRestGitLab.R | 62 ++++++ R/GitHost.R | 10 +- R/GitHostGitHub.R | 129 +------------ R/GitHostGitLab.R | 178 +----------------- R/GitStats.R | 12 +- tests/testthat/test-get_commits-GitHub.R | 4 +- tests/testthat/test-get_commits-GitLab.R | 4 +- .../testthat/test-get_files_content-GitHub.R | 6 +- .../testthat/test-get_files_content-GitLab.R | 10 +- tests/testthat/test-get_release-GitHub.R | 4 +- tests/testthat/test-get_release-GitLab.R | 6 +- tests/testthat/test-get_user-GitHub.R | 4 +- tests/testthat/test-get_user-GitLab.R | 4 +- 15 files changed, 337 insertions(+), 333 deletions(-) diff --git a/R/EngineGraphQLGitHub.R b/R/EngineGraphQLGitHub.R index 966a567c..aa20a36f 100644 --- a/R/EngineGraphQLGitHub.R +++ b/R/EngineGraphQLGitHub.R @@ -125,6 +125,45 @@ EngineGraphQLGitHub <- R6::R6Class( return(repos_list_with_commits) }, + # Parses repositories' list with commits into table of commits. + prepare_commits_table = function(repos_list_with_commits, + org) { + commits_table <- purrr::imap(repos_list_with_commits, function(repo, repo_name) { + commits_row <- purrr::map_dfr(repo, function(commit) { + commit_author <- commit$node$author + commit$node$author <- commit_author$name + commit$node$author_login <- if (!is.null(commit_author$user$login)) { + commit_author$user$login + } else { + NA + } + commit$node$author_name <- if (!is.null(commit_author$user$name)) { + commit_author$user$name + } else { + NA + } + commit$node$committed_date <- gts_to_posixt(commit$node$committed_date) + commit$node + }) + commits_row$repository <- repo_name + commits_row + }) %>% + purrr::discard(~ length(.) == 1) %>% + purrr::list_rbind() + if (nrow(commits_table) > 0) { + commits_table <- commits_table %>% + dplyr::mutate( + organization = org, + api_url = self$gql_api_url + ) %>% + dplyr::relocate( + any_of(c("author_login", "author_name")), + .after = author + ) + } + return(commits_table) + }, + # Pull all given files from all repositories of an organization. get_files_from_org = function(org, type, @@ -157,6 +196,30 @@ EngineGraphQLGitHub <- R6::R6Class( return(org_files_list) }, + # Prepare files table. + prepare_files_table = function(files_response, org, file_path) { + if (!is.null(files_response)) { + files_table <- purrr::map(files_response, function(repository) { + purrr::imap(repository, function(file_data, file_name) { + data.frame( + "repo_name" = file_data$repo_name, + "repo_id" = file_data$repo_id, + "organization" = org, + "file_path" = file_name, + "file_content" = file_data$file$text %||% NA, + "file_size" = file_data$file$byteSize, + "repo_url" = file_data$repo_url + ) + }) %>% + purrr::list_rbind() + }) %>% + purrr::list_rbind() + } else { + files_table <- NULL + } + return(files_table) + }, + # Pull all files from all repositories of an organization. get_files_structure_from_org = function(org, type, @@ -186,6 +249,29 @@ EngineGraphQLGitHub <- R6::R6Class( return(files_structure) }, + # Prepare user table. + prepare_user_table = function(user_response) { + if (!is.null(user_response$data$user)) { + user_data <- user_response$data$user + user_data[["name"]] <- user_data$name %||% "" + user_data[["starred_repos"]] <- user_data$starred_repos$totalCount + user_data[["commits"]] <- user_data$contributions$totalCommitContributions + user_data[["issues"]] <- user_data$contributions$totalIssueContributions + user_data[["pull_requests"]] <- user_data$contributions$totalPullRequestContributions + user_data[["reviews"]] <- user_data$contributions$totalPullRequestReviewContributions + user_data[["contributions"]] <- NULL + user_data[["email"]] <- user_data$email %||% "" + user_data[["location"]] <- user_data$location %||% "" + user_data[["web_url"]] <- user_data$web_url %||% "" + user_table <- tibble::as_tibble(user_data) %>% + dplyr::relocate(c(commits, issues, pull_requests, reviews), + .after = starred_repos) + } else { + user_table <- NULL + } + return(user_table) + }, + # Pull release logs from organization get_release_logs_from_org = function(repos_names, org) { release_responses <- purrr::map(repos_names, function(repository) { @@ -201,6 +287,47 @@ EngineGraphQLGitHub <- R6::R6Class( }) %>% purrr::discard(~ length(.$data$repository$releases$nodes) == 0) return(release_responses) + }, + + # Prepare releases table. + prepare_releases_table = function(releases_response, org, date_from, date_until) { + if (!is.null(releases_response)) { + releases_table <- + purrr::map(releases_response, function(release) { + release_table <- purrr::map(release$data$repository$releases$nodes, function(node) { + data.frame( + release_name = node$name, + release_tag = node$tagName, + published_at = gts_to_posixt(node$publishedAt), + release_url = node$url, + release_log = node$description + ) + }) %>% + purrr::list_rbind() %>% + dplyr::mutate( + repo_name = release$data$repository$name, + repo_url = release$data$repository$url + ) %>% + dplyr::relocate( + repo_name, repo_url, + .before = release_name + ) + return(release_table) + }) %>% + purrr::list_rbind() %>% + dplyr::filter( + published_at <= as.POSIXct(date_until) + ) + if (!is.null(date_from)) { + releases_table <- releases_table %>% + dplyr::filter( + published_at >= as.POSIXct(date_from) + ) + } + } else { + releases_table <- NULL + } + return(releases_table) } ), private = list( diff --git a/R/EngineGraphQLGitLab.R b/R/EngineGraphQLGitLab.R index 9b826d3a..3f75ef19 100644 --- a/R/EngineGraphQLGitLab.R +++ b/R/EngineGraphQLGitLab.R @@ -270,6 +270,49 @@ EngineGraphQLGitLab <- R6::R6Class( }, .progress = progress) return(org_files_list) }, + + # Prepare files table. + prepare_files_table = function(files_response, org, file_path) { + if (!is.null(files_response)) { + if (private$response_prepared_by_iteration(files_response)) { + files_table <- purrr::map(files_response, function(response_data) { + purrr::map(response_data$data$project$repository$blobs$nodes, function(file) { + data.frame( + "repo_name" = response_data$data$project$name, + "repo_id" = response_data$data$project$id, + "organization" = org, + "file_path" = file$name, + "file_content" = file$rawBlob, + "file_size" = as.integer(file$size), + "repo_url" = response_data$data$project$webUrl + ) + }) %>% + purrr::list_rbind() + }) %>% + purrr::list_rbind() + } else { + files_table <- purrr::map(files_response, function(project) { + purrr::map(project$repository$blobs$nodes, function(file) { + data.frame( + "repo_name" = project$name, + "repo_id" = project$id, + "organization" = org, + "file_path" = file$name, + "file_content" = file$rawBlob, + "file_size" = as.integer(file$size), + "repo_url" = project$webUrl + ) + }) %>% + purrr::list_rbind() + }) %>% + purrr::list_rbind() + } + } else { + files_table <- NULL + } + return(files_table) + }, + get_files_structure_from_org = function(org, type, repos, @@ -296,6 +339,28 @@ EngineGraphQLGitLab <- R6::R6Class( return(files_structure) }, + # Prepare user table. + prepare_user_table = function(user_response) { + if (!is.null(user_response$data$user)) { + user_data <- user_response$data$user + user_data$name <- user_data$name %||% "" + user_data$starred_repos <- user_data$starred_repos$count + user_data$pull_requests <- user_data$pull_requests$count + user_data$reviews <- user_data$reviews$count + user_data$email <- user_data$email %||% "" + user_data$location <- user_data$location %||% "" + user_data$web_url <- user_data$web_url %||% "" + user_table <- tibble::as_tibble(user_data) %>% + dplyr::mutate(commits = NA, + issues = NA) %>% + dplyr::relocate(c(commits, issues), + .after = starred_repos) + } else { + user_table <- NULL + } + return(user_table) + }, + # Pull all releases from all repositories of an organization. get_release_logs_from_org = function(repos_names, org) { release_responses <- purrr::map(repos_names, function(repository) { @@ -310,6 +375,47 @@ EngineGraphQLGitLab <- R6::R6Class( }) %>% purrr::discard(~ length(.$data$project$releases$nodes) == 0) return(release_responses) + }, + + # Prepare releases table. + prepare_releases_table = function(releases_response, org, date_from, date_until) { + if (length(releases_response) > 0) { + releases_table <- + purrr::map(releases_response, function(release) { + release_table <- purrr::map(release$data$project$releases$nodes, function(node) { + data.frame( + release_name = node$name, + release_tag = node$tagName, + published_at = gts_to_posixt(node$releasedAt), + release_url = node$links$selfUrl, + release_log = node$description + ) + }) %>% + purrr::list_rbind() %>% + dplyr::mutate( + repo_name = release$data$project$name, + repo_url = release$data$project$webUrl + ) %>% + dplyr::relocate( + repo_name, repo_url, + .before = release_name + ) + return(release_table) + }) %>% + purrr::list_rbind() %>% + dplyr::filter( + published_at <= as.POSIXct(date_until) + ) + if (!is.null(date_from)) { + releases_table <- releases_table %>% + dplyr::filter( + published_at >= as.POSIXct(date_from) + ) + } + } else { + releases_table <- NULL + } + return(releases_table) } ), private = list( @@ -455,6 +561,10 @@ EngineGraphQLGitLab <- R6::R6Class( "files" = files ) return(result) + }, + + response_prepared_by_iteration = function(files_response) { + !all(purrr::map_lgl(files_response, ~ all(c("name", "id", "webUrl", "repository") %in% names(.)))) } ) ) diff --git a/R/EngineRestGitLab.R b/R/EngineRestGitLab.R index 70683fb2..6d023a0f 100644 --- a/R/EngineRestGitLab.R +++ b/R/EngineRestGitLab.R @@ -34,6 +34,29 @@ EngineRestGitLab <- R6::R6Class( return(files_list) }, + # Prepare files table from REST API. + prepare_files_table = function(files_list) { + files_table <- NULL + if (!is.null(files_list)) { + files_table <- purrr::map(files_list, function(file_data) { + org_repo <- stringr::str_split_1(file_data$repo_fullname, "/") + org <- paste0(org_repo[1:(length(org_repo) - 1)], collapse = "/") + data.frame( + "repo_name" = file_data$repo_name, + "repo_id" = as.character(file_data$repo_id), + "organization" = org, + "file_path" = file_data$file_path, + "file_content" = file_data$content, + "file_size" = file_data$size, + "repo_url" = file_data$repo_url + ) + }) %>% + purrr::list_rbind() %>% + unique() + } + return(files_table) + }, + # Wrapper for iteration over GitLab search API response # @details For the time being there is no possibility to search GitLab with # filtering by language. For more information look here: @@ -87,6 +110,45 @@ EngineRestGitLab <- R6::R6Class( return(repos_list) }, + # Get only important info on commits. + tailor_commits_info = function(repos_list_with_commits, + org) { + repos_list_with_commits_cut <- purrr::map(repos_list_with_commits, function(repo) { + purrr::map(repo, function(commit) { + list( + "id" = commit$id, + "committed_date" = gts_to_posixt(commit$committed_date), + "author" = commit$author_name, + "additions" = commit$stats$additions, + "deletions" = commit$stats$deletions, + "repository" = gsub( + pattern = paste0("/-/commit/", commit$id), + replacement = "", + x = gsub(paste0("(.*)", org, "/"), "", commit$web_url) + ), + "organization" = org + ) + }) + }) + return(repos_list_with_commits_cut) + }, + + # A helper to turn list of data.frames into one data.frame + prepare_commits_table = function(commits_list) { + commits_dt <- purrr::map(commits_list, function(commit) { + purrr::map(commit, ~ data.frame(.)) %>% + purrr::list_rbind() + }) %>% + purrr::list_rbind() + if (length(commits_dt) > 0) { + commits_dt <- dplyr::mutate( + commits_dt, + api_url = self$rest_api_url + ) + } + return(commits_dt) + }, + # Pull all repositories URLs from organization get_repos_urls = function(type, org) { repos_urls <- self$response( diff --git a/R/GitHost.R b/R/GitHost.R index f568b8bf..53d84766 100644 --- a/R/GitHost.R +++ b/R/GitHost.R @@ -144,7 +144,7 @@ GitHost <- R6::R6Class( graphql_engine <- private$engines$graphql users_table <- purrr::map(users, function(user) { graphql_engine$get_user(user) %>% - private$prepare_user_table() + graphql_engine$prepare_user_table() }) %>% purrr::list_rbind() return(users_table) @@ -218,13 +218,13 @@ GitHost <- R6::R6Class( repos_names <- private$set_repositories( org = org ) - gql_engine <- private$engines$graphql + graphql_engine <- private$engines$graphql if (length(repos_names) > 0) { - release_logs_table_org <- gql_engine$get_release_logs_from_org( + release_logs_table_org <- graphql_engine$get_release_logs_from_org( org = org, repos_names = repos_names ) %>% - private$prepare_releases_table(org, since, until) + graphql_engine$prepare_releases_table(org, since, until) } else { releases_logs_table_org <- NULL } @@ -887,7 +887,7 @@ GitHost <- R6::R6Class( verbose = verbose, progress = progress ) %>% - private$prepare_files_table( + graphql_engine$prepare_files_table( org = org, file_path = file_path ) diff --git a/R/GitHostGitHub.R b/R/GitHostGitHub.R index 7f0a6c3c..21b4c8e8 100644 --- a/R/GitHostGitHub.R +++ b/R/GitHostGitHub.R @@ -185,7 +185,7 @@ GitHostGitHub <- R6::R6Class( until = until, progress = progress ) %>% - private$prepare_commits_table(org) + graphql_engine$prepare_commits_table(org) return(commits_table_org) }, .progress = if (private$scan_all && progress) { "[GitHost:GitHub] Pulling commits..." @@ -209,92 +209,6 @@ GitHostGitHub <- R6::R6Class( return(repos_names) }, - # Parses repositories' list with commits into table of commits. - prepare_commits_table = function(repos_list_with_commits, - org) { - commits_table <- purrr::imap(repos_list_with_commits, function(repo, repo_name) { - commits_row <- purrr::map_dfr(repo, function(commit) { - commit_author <- commit$node$author - commit$node$author <- commit_author$name - commit$node$author_login <- if (!is.null(commit_author$user$login)) { - commit_author$user$login - } else { - NA - } - commit$node$author_name <- if (!is.null(commit_author$user$name)) { - commit_author$user$name - } else { - NA - } - commit$node$committed_date <- gts_to_posixt(commit$node$committed_date) - commit$node - }) - commits_row$repository <- repo_name - commits_row - }) %>% - purrr::discard(~ length(.) == 1) %>% - purrr::list_rbind() - if (nrow(commits_table) > 0) { - commits_table <- commits_table %>% - dplyr::mutate( - organization = org, - api_url = private$api_url - ) %>% - dplyr::relocate( - any_of(c("author_login", "author_name")), - .after = author - ) - } - return(commits_table) - }, - - # Prepare user table. - prepare_user_table = function(user_response) { - if (!is.null(user_response$data$user)) { - user_data <- user_response$data$user - user_data[["name"]] <- user_data$name %||% "" - user_data[["starred_repos"]] <- user_data$starred_repos$totalCount - user_data[["commits"]] <- user_data$contributions$totalCommitContributions - user_data[["issues"]] <- user_data$contributions$totalIssueContributions - user_data[["pull_requests"]] <- user_data$contributions$totalPullRequestContributions - user_data[["reviews"]] <- user_data$contributions$totalPullRequestReviewContributions - user_data[["contributions"]] <- NULL - user_data[["email"]] <- user_data$email %||% "" - user_data[["location"]] <- user_data$location %||% "" - user_data[["web_url"]] <- user_data$web_url %||% "" - user_table <- tibble::as_tibble(user_data) %>% - dplyr::relocate(c(commits, issues, pull_requests, reviews), - .after = starred_repos) - } else { - user_table <- NULL - } - return(user_table) - }, - - # Prepare files table. - prepare_files_table = function(files_response, org, file_path) { - if (!is.null(files_response)) { - files_table <- purrr::map(files_response, function(repository) { - purrr::imap(repository, function(file_data, file_name) { - data.frame( - "repo_name" = file_data$repo_name, - "repo_id" = file_data$repo_id, - "organization" = org, - "file_path" = file_name, - "file_content" = file_data$file$text %||% NA, - "file_size" = file_data$file$byteSize, - "repo_url" = file_data$repo_url - ) - }) %>% - purrr::list_rbind() - }) %>% - purrr::list_rbind() - } else { - files_table <- NULL - } - return(files_table) - }, - # Prepare files table from REST API. prepare_files_table_from_rest = function(files_list) { files_table <- NULL @@ -327,47 +241,6 @@ GitHostGitHub <- R6::R6Class( # Get repository url set_repo_url = function(repo_fullname) { paste0(private$endpoints$repositories, "/", repo_fullname) - }, - - # Prepare releases table. - prepare_releases_table = function(releases_response, org, date_from, date_until) { - if (!is.null(releases_response)) { - releases_table <- - purrr::map(releases_response, function(release) { - release_table <- purrr::map(release$data$repository$releases$nodes, function(node) { - data.frame( - release_name = node$name, - release_tag = node$tagName, - published_at = gts_to_posixt(node$publishedAt), - release_url = node$url, - release_log = node$description - ) - }) %>% - purrr::list_rbind() %>% - dplyr::mutate( - repo_name = release$data$repository$name, - repo_url = release$data$repository$url - ) %>% - dplyr::relocate( - repo_name, repo_url, - .before = release_name - ) - return(release_table) - }) %>% - purrr::list_rbind() %>% - dplyr::filter( - published_at <= as.POSIXct(date_until) - ) - if (!is.null(date_from)) { - releases_table <- releases_table %>% - dplyr::filter( - published_at >= as.POSIXct(date_from) - ) - } - } else { - releases_table <- NULL - } - return(releases_table) } ) ) diff --git a/R/GitHostGitLab.R b/R/GitHostGitLab.R index 281fe017..428b6e0f 100644 --- a/R/GitHostGitLab.R +++ b/R/GitHostGitLab.R @@ -266,8 +266,8 @@ GitHostGitLab <- R6::R6Class("GitHostGitLab", until = until, progress = progress ) %>% - private$tailor_commits_info(org = org) %>% - private$prepare_commits_table() %>% + rest_engine$tailor_commits_info(org = org) %>% + rest_engine$prepare_commits_table() %>% rest_engine$get_commits_authors_handles_and_names( verbose = verbose, progress = progress @@ -298,46 +298,6 @@ GitHostGitLab <- R6::R6Class("GitHostGitLab", return(repos_names) }, - # Get only important info on commits. - tailor_commits_info = function(repos_list_with_commits, - org) { - repos_list_with_commits_cut <- purrr::map(repos_list_with_commits, function(repo) { - purrr::map(repo, function(commit) { - list( - "id" = commit$id, - "committed_date" = gts_to_posixt(commit$committed_date), - "author" = commit$author_name, - "additions" = commit$stats$additions, - "deletions" = commit$stats$deletions, - "repository" = gsub( - pattern = paste0("/-/commit/", commit$id), - replacement = "", - x = gsub(paste0("(.*)", org, "/"), "", commit$web_url) - ), - "organization" = org - ) - }) - }) - return(repos_list_with_commits_cut) - }, - - # A helper to turn list of data.frames into one data.frame - prepare_commits_table = function(commits_list) { - commits_dt <- purrr::map(commits_list, function(commit) { - purrr::map(commit, ~ data.frame(.)) %>% - purrr::list_rbind() - }) %>% - purrr::list_rbind() - - if (length(commits_dt) > 0) { - commits_dt <- dplyr::mutate( - commits_dt, - api_url = private$api_url - ) - } - return(commits_dt) - }, - are_non_text_files = function(file_path, host_files_structure) { if (!is.null(file_path)) { any(grepl(non_text_files_pattern, file_path)) @@ -395,143 +355,11 @@ GitHostGitLab <- R6::R6Class("GitHostGitLab", verbose = FALSE, progress = progress ) %>% - private$prepare_files_table_from_rest() + rest_engine$prepare_files_table() }, .progress = progress) %>% purrr::list_rbind() %>% private$add_repo_api_url() return(files_table) - }, - - # Prepare user table. - prepare_user_table = function(user_response) { - if (!is.null(user_response$data$user)) { - user_data <- user_response$data$user - user_data$name <- user_data$name %||% "" - user_data$starred_repos <- user_data$starred_repos$count - user_data$pull_requests <- user_data$pull_requests$count - user_data$reviews <- user_data$reviews$count - user_data$email <- user_data$email %||% "" - user_data$location <- user_data$location %||% "" - user_data$web_url <- user_data$web_url %||% "" - user_table <- tibble::as_tibble(user_data) %>% - dplyr::mutate(commits = NA, - issues = NA) %>% - dplyr::relocate(c(commits, issues), - .after = starred_repos) - } else { - user_table <- NULL - } - return(user_table) - }, - - # Prepare files table. - prepare_files_table = function(files_response, org, file_path) { - if (!is.null(files_response)) { - if (private$response_prepared_by_iteration(files_response)) { - files_table <- purrr::map(files_response, function(response_data) { - purrr::map(response_data$data$project$repository$blobs$nodes, function(file) { - data.frame( - "repo_name" = response_data$data$project$name, - "repo_id" = response_data$data$project$id, - "organization" = org, - "file_path" = file$name, - "file_content" = file$rawBlob, - "file_size" = as.integer(file$size), - "repo_url" = response_data$data$project$webUrl - ) - }) %>% - purrr::list_rbind() - }) %>% - purrr::list_rbind() - } else { - files_table <- purrr::map(files_response, function(project) { - purrr::map(project$repository$blobs$nodes, function(file) { - data.frame( - "repo_name" = project$name, - "repo_id" = project$id, - "organization" = org, - "file_path" = file$name, - "file_content" = file$rawBlob, - "file_size" = as.integer(file$size), - "repo_url" = project$webUrl - ) - }) %>% - purrr::list_rbind() - }) %>% - purrr::list_rbind() - } - } else { - files_table <- NULL - } - return(files_table) - }, - - response_prepared_by_iteration = function(files_response) { - !all(purrr::map_lgl(files_response, ~ all(c("name", "id", "webUrl", "repository") %in% names(.)))) - }, - - # Prepare files table from REST API. - prepare_files_table_from_rest = function(files_list) { - files_table <- NULL - if (!is.null(files_list)) { - files_table <- purrr::map(files_list, function(file_data) { - org_repo <- stringr::str_split_1(file_data$repo_fullname, "/") - org <- paste0(org_repo[1:(length(org_repo) - 1)], collapse = "/") - data.frame( - "repo_name" = file_data$repo_name, - "repo_id" = as.character(file_data$repo_id), - "organization" = org, - "file_path" = file_data$file_path, - "file_content" = file_data$content, - "file_size" = file_data$size, - "repo_url" = file_data$repo_url - ) - }) %>% - purrr::list_rbind() %>% - unique() - } - return(files_table) - }, - - # Prepare releases table. - prepare_releases_table = function(releases_response, org, date_from, date_until) { - if (length(releases_response) > 0) { - releases_table <- - purrr::map(releases_response, function(release) { - release_table <- purrr::map(release$data$project$releases$nodes, function(node) { - data.frame( - release_name = node$name, - release_tag = node$tagName, - published_at = gts_to_posixt(node$releasedAt), - release_url = node$links$selfUrl, - release_log = node$description - ) - }) %>% - purrr::list_rbind() %>% - dplyr::mutate( - repo_name = release$data$project$name, - repo_url = release$data$project$webUrl - ) %>% - dplyr::relocate( - repo_name, repo_url, - .before = release_name - ) - return(release_table) - }) %>% - purrr::list_rbind() %>% - dplyr::filter( - published_at <= as.POSIXct(date_until) - ) - if (!is.null(date_from)) { - releases_table <- releases_table %>% - dplyr::filter( - published_at >= as.POSIXct(date_from) - ) - } - } else { - releases_table <- NULL - } - return(releases_table) } ) ) diff --git a/R/GitStats.R b/R/GitStats.R index 3e75eb60..27ff5759 100644 --- a/R/GitStats.R +++ b/R/GitStats.R @@ -833,7 +833,8 @@ GitStats <- R6::R6Class( progress = progress ) }) %>% - purrr::list_rbind() + purrr::list_rbind() %>% + dplyr::as_tibble() return(commits_table) }, @@ -843,7 +844,8 @@ GitStats <- R6::R6Class( host$get_users(logins) }) %>% unique() %>% - purrr::list_rbind() + purrr::list_rbind() %>% + dplyr::as_tibble() }, # Pull content of a text file in a table form @@ -879,7 +881,8 @@ GitStats <- R6::R6Class( ) } }) %>% - purrr::list_rbind() + purrr::list_rbind() %>% + dplyr::as_tibble() }, get_host_files_structure = function(host, verbose) { @@ -943,7 +946,8 @@ GitStats <- R6::R6Class( progress = progress ) }) %>% - purrr::list_rbind() + purrr::list_rbind() %>% + dplyr::as_tibble() }, # Pull information on package usage in a table form diff --git a/tests/testthat/test-get_commits-GitHub.R b/tests/testthat/test-get_commits-GitHub.R index 88f7851f..c8b4e6e3 100644 --- a/tests/testthat/test-get_commits-GitHub.R +++ b/tests/testthat/test-get_commits-GitHub.R @@ -68,7 +68,7 @@ test_that("`get_commits_from_repos()` pulls commits from repos", { }) test_that("`prepare_commits_table()` prepares commits table", { - gh_commits_table <- github_testhost_priv$prepare_commits_table( + gh_commits_table <- test_graphql_github$prepare_commits_table( repos_list_with_commits = test_mocker$use("commits_from_repos"), org = "r-world-devs" ) @@ -81,7 +81,7 @@ test_that("`prepare_commits_table()` prepares commits table", { test_that("get_commits_from_orgs for GitHub works", { mockery::stub( github_testhost_repos_priv$get_commits_from_orgs, - "private$prepare_commits_table", + "graphql_engine$prepare_commits_table", test_mocker$use("gh_commits_table") ) suppressMessages( diff --git a/tests/testthat/test-get_commits-GitLab.R b/tests/testthat/test-get_commits-GitLab.R index b0113ab7..d75360e0 100644 --- a/tests/testthat/test-get_commits-GitLab.R +++ b/tests/testthat/test-get_commits-GitLab.R @@ -18,7 +18,7 @@ test_that("`get_commits_from_repos()` pulls commits from repo", { test_that("`tailor_commits_info()` retrieves only necessary info", { gl_commits_list <- test_mocker$use("gl_commits_org") - gl_commits_list_cut <- gitlab_testhost_priv$tailor_commits_info( + gl_commits_list_cut <- test_rest_gitlab$tailor_commits_info( gl_commits_list, org = "mbtests" ) @@ -29,7 +29,7 @@ test_that("`tailor_commits_info()` retrieves only necessary info", { }) test_that("`prepare_commits_table()` prepares table of commits properly", { - gl_commits_table <- gitlab_testhost_priv$prepare_commits_table( + gl_commits_table <- test_rest_gitlab$prepare_commits_table( commits_list = test_mocker$use("gl_commits_list_cut") ) expect_commits_table( diff --git a/tests/testthat/test-get_files_content-GitHub.R b/tests/testthat/test-get_files_content-GitHub.R index 4d3a9423..ec9183c8 100644 --- a/tests/testthat/test-get_files_content-GitHub.R +++ b/tests/testthat/test-get_files_content-GitHub.R @@ -108,7 +108,7 @@ test_that("GitHub GraphQL Engine pulls files from organization", { }) test_that("GitHubHost prepares table from files response", { - gh_files_table <- github_testhost_priv$prepare_files_table( + gh_files_table <- test_graphql_github$prepare_files_table( files_response = test_mocker$use("github_files_response"), org = "r-world-devs", file_path = "LICENSE" @@ -123,7 +123,7 @@ test_that("GitHubHost prepares table from files with no content", { test_repo$test_files$file$text <- NULL return(test_repo) }) - gh_empty_files_table <- github_testhost_priv$prepare_files_table( + gh_empty_files_table <- test_graphql_github$prepare_files_table( files_response = empty_files_response, org = "test_org", file_path = "test_files" @@ -136,7 +136,7 @@ test_that("GitHubHost prepares table from files with no content", { test_that("get_files_content_from_orgs for GitHub works", { mockery::stub( github_testhost_priv$get_files_content_from_orgs, - "private$prepare_files_table", + "graphql_engine$prepare_files_table", test_mocker$use("gh_files_table") ) gh_files_table <- github_testhost_priv$get_files_content_from_orgs( diff --git a/tests/testthat/test-get_files_content-GitLab.R b/tests/testthat/test-get_files_content-GitLab.R index c034666b..45e40f38 100644 --- a/tests/testthat/test-get_files_content-GitLab.R +++ b/tests/testthat/test-get_files_content-GitLab.R @@ -132,19 +132,19 @@ test_that("Gitlab GraphQL switches to pulling files per repositories when query test_that("checker properly identifies gitlab files responses", { expect_false( - gitlab_testhost_priv$response_prepared_by_iteration( + test_graphql_gitlab_priv$response_prepared_by_iteration( files_response = test_mocker$use("gitlab_files_response") ) ) expect_true( - gitlab_testhost_priv$response_prepared_by_iteration( + test_graphql_gitlab_priv$response_prepared_by_iteration( files_response = test_mocker$use("gitlab_files_response_by_repos") ) ) }) test_that("GitLab prepares table from files response", { - gl_files_table <- gitlab_testhost_priv$prepare_files_table( + gl_files_table <- test_graphql_gitlab$prepare_files_table( files_response = test_mocker$use("gitlab_files_response"), org = "mbtests", file_path = "meta_data.yaml" @@ -154,7 +154,7 @@ test_that("GitLab prepares table from files response", { }) test_that("GitLab prepares table from files response prepared in alternative way", { - gl_files_table <- gitlab_testhost_priv$prepare_files_table( + gl_files_table <- test_graphql_gitlab$prepare_files_table( files_response = test_mocker$use("gitlab_files_response_by_repos"), org = "mbtests", file_path = "meta_data.yaml" @@ -165,7 +165,7 @@ test_that("GitLab prepares table from files response prepared in alternative way test_that("get_files_content_from_orgs for GitLab works", { mockery::stub( gitlab_testhost_priv$get_files_content_from_orgs, - "private$prepare_files_table", + "graphql_engine$prepare_files_table", test_mocker$use("gl_files_table") ) suppressMessages( diff --git a/tests/testthat/test-get_release-GitHub.R b/tests/testthat/test-get_release-GitHub.R index 1b2bd73d..3c93c179 100644 --- a/tests/testthat/test-get_release-GitHub.R +++ b/tests/testthat/test-get_release-GitHub.R @@ -21,7 +21,7 @@ test_that("`get_releases_from_org()` pulls releases from the repositories", { }) test_that("`prepare_releases_table()` prepares releases table", { - releases_table <- github_testhost_priv$prepare_releases_table( + releases_table <- test_graphql_github$prepare_releases_table( releases_response = test_mocker$use("releases_from_repos"), org = "r-world-devs", date_from = "2023-05-01", @@ -48,7 +48,7 @@ test_that("`set_repositories` works", { test_that("`get_release_logs()` pulls release logs in the table format", { mockery::stub( github_testhost$get_release_logs, - "private$prepare_releases_table", + "graphql_engine$prepare_releases_table", test_mocker$use("releases_table") ) mockery::stub( diff --git a/tests/testthat/test-get_release-GitLab.R b/tests/testthat/test-get_release-GitLab.R index 15b18ca1..fe79a434 100644 --- a/tests/testthat/test-get_release-GitLab.R +++ b/tests/testthat/test-get_release-GitLab.R @@ -22,9 +22,9 @@ test_that("`get_releases_from_org()` pulls releases from the repositories", { test_that("`prepare_releases_table()` prepares releases table", { - releases_table <- gitlab_testhost_priv$prepare_releases_table( + releases_table <- test_graphql_gitlab$prepare_releases_table( releases_response = test_mocker$use("releases_from_repos"), - org = "r-world-devs", + org = "test_org", date_from = "2023-08-01", date_until = "2024-06-30" ) @@ -37,7 +37,7 @@ test_that("`prepare_releases_table()` prepares releases table", { test_that("`get_release_logs()` pulls release logs in the table format", { mockery::stub( gitlab_testhost$get_release_logs, - "private$prepare_releases_table", + "graphql_engine$prepare_releases_table", test_mocker$use("releases_table") ) releases_table <- gitlab_testhost$get_release_logs( diff --git a/tests/testthat/test-get_user-GitHub.R b/tests/testthat/test-get_user-GitHub.R index 250d6c3c..bba98a84 100644 --- a/tests/testthat/test-get_user-GitHub.R +++ b/tests/testthat/test-get_user-GitHub.R @@ -21,7 +21,7 @@ test_that("get_user pulls GitHub user response", { }) test_that("GitHub prepares user table", { - gh_user_table <- github_testhost_priv$prepare_user_table( + gh_user_table <- test_graphql_github$prepare_user_table( user_response = test_mocker$use("gh_user_response") ) expect_users_table( @@ -34,7 +34,7 @@ test_that("GitHub prepares user table", { test_that("GitHost gets users tables", { mockery::stub( github_testhost$get_users, - "private$prepare_user_table", + "graphql_engine$prepare_user_table", test_mocker$use("gh_user_table") ) github_users <- github_testhost$get_users( diff --git a/tests/testthat/test-get_user-GitLab.R b/tests/testthat/test-get_user-GitLab.R index 4b7bed2f..9ecea4f4 100644 --- a/tests/testthat/test-get_user-GitLab.R +++ b/tests/testthat/test-get_user-GitLab.R @@ -21,7 +21,7 @@ test_that("get_user pulls GitLab user response", { }) test_that("GitLab prepares user table", { - gl_user_table <- gitlab_testhost_priv$prepare_user_table( + gl_user_table <- test_graphql_gitlab$prepare_user_table( user_response = test_mocker$use("gl_user_response") ) expect_users_table( @@ -34,7 +34,7 @@ test_that("GitLab prepares user table", { test_that("get_users build users table for GitLab", { mockery::stub( gitlab_testhost$get_users, - "private$prepare_user_table", + "graphql_engine$prepare_user_table", test_mocker$use("gl_user_table") ) gitlab_users <- gitlab_testhost$get_users(