From 405ee3c1601c8482df6e6721ffbce3aa0d115d1d Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 15 Oct 2024 11:49:27 +0000 Subject: [PATCH 1/3] Move parsing methods for repositories to lower-level API clients. --- R/EngineGraphQLGitHub.R | 34 ++++++++++++ R/EngineGraphQLGitLab.R | 38 +++++++++++++ R/EngineRest.R | 26 +++++++++ R/EngineRestGitHub.R | 25 +++++++++ R/EngineRestGitLab.R | 21 +++++++ R/GitHost.R | 36 ++---------- R/GitHostGitHub.R | 58 -------------------- R/GitHostGitLab.R | 58 -------------------- R/GitStats.R | 4 +- tests/testthat/_snaps/01-get_repos-GitHub.md | 4 +- tests/testthat/_snaps/01-get_repos-GitLab.md | 6 +- tests/testthat/test-01-get_repos-GitHub.R | 8 +-- tests/testthat/test-01-get_repos-GitLab.R | 8 +-- 13 files changed, 164 insertions(+), 162 deletions(-) diff --git a/R/EngineGraphQLGitHub.R b/R/EngineGraphQLGitHub.R index ed03264f..966a567c 100644 --- a/R/EngineGraphQLGitHub.R +++ b/R/EngineGraphQLGitHub.R @@ -71,6 +71,40 @@ EngineGraphQLGitHub <- R6::R6Class( return(full_repos_list) }, + # Parses repositories list into table. + prepare_repos_table = function(repos_list) { + if (length(repos_list) > 0) { + repos_table <- purrr::map(repos_list, function(repo) { + repo$default_branch <- if (!is.null(repo$default_branch)) { + repo$default_branch$name + } else { + "" + } + last_activity_at <- as.POSIXct(repo$last_activity_at) + if (length(last_activity_at) == 0) { + last_activity_at <- gts_to_posixt(repo$created_at) + } + repo$languages <- purrr::map_chr(repo$languages$nodes, ~ .$name) %>% + paste0(collapse = ", ") + repo$created_at <- gts_to_posixt(repo$created_at) + repo$issues_open <- repo$issues_open$totalCount + repo$issues_closed <- repo$issues_closed$totalCount + repo$last_activity_at <- last_activity_at + repo$organization <- repo$organization$login + repo <- data.frame(repo) %>% + dplyr::relocate( + default_branch, + .after = repo_name + ) + return(repo) + }) %>% + purrr::list_rbind() + } else { + repos_table <- NULL + } + return(repos_table) + }, + # Iterator over pulling commits from all repositories. get_commits_from_repos = function(org, repos_names, diff --git a/R/EngineGraphQLGitLab.R b/R/EngineGraphQLGitLab.R index ccf47280..9b826d3a 100644 --- a/R/EngineGraphQLGitLab.R +++ b/R/EngineGraphQLGitLab.R @@ -77,6 +77,44 @@ EngineGraphQLGitLab <- R6::R6Class( return(full_repos_list) }, + # Parses repositories list into table. + prepare_repos_table = function(repos_list) { + if (length(repos_list) > 0) { + repos_table <- purrr::map(repos_list, function(repo) { + repo <- repo$node + repo$default_branch <- repo$repository$rootRef %||% "" + repo$repository <- NULL + repo$languages <- if (length(repo$languages) > 0) { + purrr::map_chr(repo$languages, ~ .$name) %>% + paste0(collapse = ", ") + } else { + "" + } + repo$created_at <- gts_to_posixt(repo$created_at) + repo$issues_open <- repo$issues$opened + repo$issues_closed <- repo$issues$closed + repo$issues <- NULL + repo$last_activity_at <- as.POSIXct(repo$last_activity_at) + repo$organization <- repo$namespace$path + repo$namespace <- NULL + repo$repo_path <- NULL # temporary to close issue 338 + data.frame(repo) + }) %>% + purrr::list_rbind() %>% + dplyr::relocate( + repo_url, + .after = organization + ) %>% + dplyr::relocate( + default_branch, + .after = repo_name + ) + } else { + repos_table <- NULL + } + return(repos_table) + }, + # Pull all given files from all repositories of a group. # This is a one query way to get all the necessary info. # However it may fail if query is too complex (too many files in file_paths). diff --git a/R/EngineRest.R b/R/EngineRest.R index d20ab0a5..6b8ad1fc 100644 --- a/R/EngineRest.R +++ b/R/EngineRest.R @@ -36,6 +36,32 @@ EngineRest <- R6::R6Class("EngineRest", result <- list() } return(result) + }, + + # Prepare table for repositories content + prepare_repos_table = function(repos_list, verbose = TRUE) { + repos_dt <- purrr::map(repos_list, function(repo) { + repo <- purrr::map(repo, function(attr) { + attr <- attr %||% "" + }) + data.frame(repo) + }) %>% + purrr::list_rbind() + if (verbose) { + cli::cli_alert_info("Preparing repositories table...") + } + if (length(repos_dt) > 0) { + repos_dt <- dplyr::mutate( + repos_dt, + repo_id = as.character(repo_id), + created_at = as.POSIXct(created_at), + last_activity_at = as.POSIXct(last_activity_at), + forks = as.integer(forks), + issues_open = as.integer(issues_open), + issues_closed = as.integer(issues_closed) + ) + } + return(repos_dt) } ), diff --git a/R/EngineRestGitHub.R b/R/EngineRestGitHub.R index 694a688b..7ddd1784 100644 --- a/R/EngineRestGitHub.R +++ b/R/EngineRestGitHub.R @@ -67,6 +67,31 @@ EngineRestGitHub <- R6::R6Class( return(search_output) }, + # Retrieve only important info from repositories response + tailor_repos_response = function(repos_response) { + repos_list <- purrr::map(repos_response, function(repo) { + list( + "repo_id" = repo$id, + "repo_name" = repo$name, + "default_branch" = repo$default_branch, + "stars" = repo$stargazers_count, + "forks" = repo$forks_count, + "created_at" = gts_to_posixt(repo$created_at), + "last_activity_at" = if (!is.null(repo$pushed_at)) { + gts_to_posixt(repo$pushed_at) + } else { + gts_to_posixt(repo$created_at) + }, + "languages" = repo$language, + "issues_open" = repo$issues_open, + "issues_closed" = repo$issues_closed, + "organization" = repo$owner$login, + "repo_url" = repo$html_url + ) + }) + return(repos_list) + }, + #' Pull all repositories URLS from organization get_repos_urls = function(type, org) { repos_urls <- self$response( diff --git a/R/EngineRestGitLab.R b/R/EngineRestGitLab.R index 6820a147..70683fb2 100644 --- a/R/EngineRestGitLab.R +++ b/R/EngineRestGitLab.R @@ -66,6 +66,27 @@ EngineRestGitLab <- R6::R6Class( return(search_output) }, + # Retrieve only important info from repositories response + tailor_repos_response = function(repos_response) { + repos_list <- purrr::map(repos_response, function(project) { + list( + "repo_id" = project$id, + "repo_name" = project$name, + "default_branch" = project$default_branch, + "stars" = project$star_count, + "forks" = project$fork_count, + "created_at" = project$created_at, + "last_activity_at" = project$last_activity_at, + "languages" = paste0(project$languages, collapse = ", "), + "issues_open" = project$issues_open, + "issues_closed" = project$issues_closed, + "organization" = project$namespace$path, + "repo_url" = project$web_url + ) + }) + return(repos_list) + }, + # 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 2975c1a2..f568b8bf 100644 --- a/R/GitHost.R +++ b/R/GitHost.R @@ -626,7 +626,7 @@ GitHost <- R6::R6Class( org = org, type = type ) %>% - private$prepare_repos_table_from_graphql() + graphql_engine$prepare_repos_table() if (!is.null(repos)) { repos_table <- repos_table %>% dplyr::filter(repo_name %in% repos) @@ -725,8 +725,8 @@ GitHost <- R6::R6Class( if (!raw_output) { rest_engine <- private$engines$rest repos_table <- repos_response %>% - private$tailor_repos_response() %>% - private$prepare_repos_table_from_rest( + rest_engine$tailor_repos_response() %>% + rest_engine$prepare_repos_table( verbose = verbose ) %>% rest_engine$get_repos_issues( @@ -767,8 +767,8 @@ GitHost <- R6::R6Class( if (!raw_output) { rest_engine <- private$engines$rest repos_table <- repos_response %>% - private$tailor_repos_response() %>% - private$prepare_repos_table_from_rest( + rest_engine$tailor_repos_response() %>% + rest_engine$prepare_repos_table( verbose = verbose ) %>% rest_engine$get_repos_issues( @@ -842,32 +842,6 @@ GitHost <- R6::R6Class( } }, - # Prepare table for repositories content - prepare_repos_table_from_rest = function(repos_list, verbose = TRUE) { - repos_dt <- purrr::map(repos_list, function(repo) { - repo <- purrr::map(repo, function(attr) { - attr <- attr %||% "" - }) - data.frame(repo) - }) %>% - purrr::list_rbind() - if (verbose) { - cli::cli_alert_info("Preparing repositories table...") - } - if (length(repos_dt) > 0) { - repos_dt <- dplyr::mutate( - repos_dt, - repo_id = as.character(repo_id), - created_at = as.POSIXct(created_at), - last_activity_at = as.POSIXct(last_activity_at), - forks = as.integer(forks), - issues_open = as.integer(issues_open), - issues_closed = as.integer(issues_closed) - ) - } - return(repos_dt) - }, - # Pull files content from organizations get_files_content_from_orgs = function(file_path, host_files_structure = NULL, diff --git a/R/GitHostGitHub.R b/R/GitHostGitHub.R index b258e9c5..7f0a6c3c 100644 --- a/R/GitHostGitHub.R +++ b/R/GitHostGitHub.R @@ -140,64 +140,6 @@ GitHostGitHub <- R6::R6Class( all(c(org_scopes, repo_scopes, user_scopes)) }, - # Retrieve only important info from repositories response - tailor_repos_response = function(repos_response) { - repos_list <- purrr::map(repos_response, function(repo) { - list( - "repo_id" = repo$id, - "repo_name" = repo$name, - "default_branch" = repo$default_branch, - "stars" = repo$stargazers_count, - "forks" = repo$forks_count, - "created_at" = gts_to_posixt(repo$created_at), - "last_activity_at" = if (!is.null(repo$pushed_at)) { - gts_to_posixt(repo$pushed_at) - } else { - gts_to_posixt(repo$created_at) - }, - "languages" = repo$language, - "issues_open" = repo$issues_open, - "issues_closed" = repo$issues_closed, - "organization" = repo$owner$login, - "repo_url" = repo$html_url - ) - }) - return(repos_list) - }, - - # Parses repositories list into table. - prepare_repos_table_from_graphql = function(repos_list) { - if (length(repos_list) > 0) { - repos_table <- purrr::map_dfr(repos_list, function(repo) { - repo$default_branch <- if (!is.null(repo$default_branch)) { - repo$default_branch$name - } else { - "" - } - last_activity_at <- as.POSIXct(repo$last_activity_at) - if (length(last_activity_at) == 0) { - last_activity_at <- gts_to_posixt(repo$created_at) - } - repo$languages <- purrr::map_chr(repo$languages$nodes, ~ .$name) %>% - paste0(collapse = ", ") - repo$created_at <- gts_to_posixt(repo$created_at) - repo$issues_open <- repo$issues_open$totalCount - repo$issues_closed <- repo$issues_closed$totalCount - repo$last_activity_at <- last_activity_at - repo$organization <- repo$organization$login - repo <- data.frame(repo) %>% - dplyr::relocate( - default_branch, - .after = repo_name - ) - return(repo) - }) - } else { - repos_table <- NULL - } - return(repos_table) - }, - # Add `api_url` column to table. add_repo_api_url = function(repos_table) { if (!is.null(repos_table) && nrow(repos_table) > 0) { diff --git a/R/GitHostGitLab.R b/R/GitHostGitLab.R index 6c1d2b5d..281fe017 100644 --- a/R/GitHostGitLab.R +++ b/R/GitHostGitLab.R @@ -207,64 +207,6 @@ GitHostGitLab <- R6::R6Class("GitHostGitLab", any(private$access_scopes %in% private$token_scopes) }, - # Retrieve only important info from repositories response - tailor_repos_response = function(repos_response) { - repos_list <- purrr::map(repos_response, function(project) { - list( - "repo_id" = project$id, - "repo_name" = project$name, - "default_branch" = project$default_branch, - "stars" = project$star_count, - "forks" = project$fork_count, - "created_at" = project$created_at, - "last_activity_at" = project$last_activity_at, - "languages" = paste0(project$languages, collapse = ", "), - "issues_open" = project$issues_open, - "issues_closed" = project$issues_closed, - "organization" = project$namespace$path, - "repo_url" = project$web_url - ) - }) - return(repos_list) - }, - - # Parses repositories list into table. - prepare_repos_table_from_graphql = function(repos_list) { - if (length(repos_list) > 0) { - repos_table <- purrr::map_dfr(repos_list, function(repo) { - repo <- repo$node - repo$default_branch <- repo$repository$rootRef %||% "" - repo$repository <- NULL - repo$languages <- if (length(repo$languages) > 0) { - purrr::map_chr(repo$languages, ~ .$name) %>% - paste0(collapse = ", ") - } else { - "" - } - repo$created_at <- gts_to_posixt(repo$created_at) - repo$issues_open <- repo$issues$opened - repo$issues_closed <- repo$issues$closed - repo$issues <- NULL - repo$last_activity_at <- as.POSIXct(repo$last_activity_at) - repo$organization <- repo$namespace$path - repo$namespace <- NULL - repo$repo_path <- NULL # temporary to close issue 338 - data.frame(repo) - }) %>% - dplyr::relocate( - repo_url, - .after = organization - ) %>% - dplyr::relocate( - default_branch, - .after = repo_name - ) - } else { - repos_table <- NULL - } - return(repos_table) - }, - # Add `api_url` column to table. add_repo_api_url = function(repos_table) { if (!is.null(repos_table) && nrow(repos_table) > 0) { diff --git a/R/GitStats.R b/R/GitStats.R index 96071593..3e75eb60 100644 --- a/R/GitStats.R +++ b/R/GitStats.R @@ -709,7 +709,8 @@ GitStats <- R6::R6Class( } }) %>% purrr::list_rbind() %>% - private$add_stats_to_repos() + private$add_stats_to_repos() %>% + dplyr::as_tibble() return(repos_table) }, @@ -974,7 +975,6 @@ GitStats <- R6::R6Class( dplyr::mutate( package_usage = ifelse(api_url %in% duplicated_repos, "import, library", package_usage) ) - rownames(package_usage_table) <- seq_len(nrow(package_usage_table)) } return(package_usage_table) }, diff --git a/tests/testthat/_snaps/01-get_repos-GitHub.md b/tests/testthat/_snaps/01-get_repos-GitHub.md index 0c71258f..72bd89bc 100644 --- a/tests/testthat/_snaps/01-get_repos-GitHub.md +++ b/tests/testthat/_snaps/01-get_repos-GitHub.md @@ -8,8 +8,8 @@ # `prepare_repos_table()` prepares repos table Code - gh_repos_by_code_table <- github_testhost_priv$prepare_repos_table_from_rest( - repos_list = test_mocker$use("gh_repos_by_code_tailored")) + gh_repos_by_code_table <- test_rest_github$prepare_repos_table(repos_list = test_mocker$ + use("gh_repos_by_code_tailored")) Message i Preparing repositories table... diff --git a/tests/testthat/_snaps/01-get_repos-GitLab.md b/tests/testthat/_snaps/01-get_repos-GitLab.md index c6dab9da..b1db1759 100644 --- a/tests/testthat/_snaps/01-get_repos-GitLab.md +++ b/tests/testthat/_snaps/01-get_repos-GitLab.md @@ -5,11 +5,11 @@ Output [1] "\n query GetReposByOrg($org: ID! $repo_cursor: String!) {\n group(fullPath: $org) {\n projects(first: 100 after: $repo_cursor) {\n \n count\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n repo_id: id\n repo_name: name\n repo_path: path\n ... on Project {\n repository {\n rootRef\n }\n }\n stars: starCount\n forks: forksCount\n created_at: createdAt\n last_activity_at: lastActivityAt\n languages {\n name\n }\n issues: issueStatusCounts {\n all\n closed\n opened\n }\n namespace {\n path\n }\n repo_url: webUrl\n }\n }\n }\n }\n }" -# GitHost prepares table from GitLab repositories response +# REST client prepares table from GitLab repositories response Code - gl_repos_by_code_table <- gitlab_testhost_priv$prepare_repos_table_from_rest( - repos_list = test_mocker$use("gl_repos_by_code_tailored")) + gl_repos_by_code_table <- test_rest_gitlab$prepare_repos_table(repos_list = test_mocker$ + use("gl_repos_by_code_tailored")) Message i Preparing repositories table... diff --git a/tests/testthat/test-01-get_repos-GitHub.R b/tests/testthat/test-01-get_repos-GitHub.R index 3c09ab50..c4bc6da6 100644 --- a/tests/testthat/test-01-get_repos-GitHub.R +++ b/tests/testthat/test-01-get_repos-GitHub.R @@ -183,7 +183,7 @@ test_that("`get_repos_by_code()` for GitHub prepares a raw (raw_output = TRUE) s test_that("GitHub tailors precisely `repos_list`", { gh_repos_by_code <- test_mocker$use("gh_repos_by_code") gh_repos_by_code_tailored <- - github_testhost_priv$tailor_repos_response(gh_repos_by_code) + test_rest_github$tailor_repos_response(gh_repos_by_code) gh_repos_by_code_tailored %>% expect_type("list") %>% expect_length(length(gh_repos_by_code)) @@ -204,7 +204,7 @@ test_that("GitHub tailors precisely `repos_list`", { test_that("`prepare_repos_table()` prepares repos table", { expect_snapshot( - gh_repos_by_code_table <- github_testhost_priv$prepare_repos_table_from_rest( + gh_repos_by_code_table <- test_rest_github$prepare_repos_table( repos_list = test_mocker$use("gh_repos_by_code_tailored") ) ) @@ -258,7 +258,7 @@ test_that("`get_repos_with_code_from_orgs()` works", { }) test_that("GitHub prepares repos table from repositories response", { - gh_repos_table <- github_testhost_priv$prepare_repos_table_from_graphql( + gh_repos_table <- test_graphql_github$prepare_repos_table( repos_list = test_mocker$use("gh_repos_from_org") ) expect_repos_table( @@ -277,7 +277,7 @@ test_that("GitHost adds `repo_api_url` column to GitHub repos table", { test_that("`get_all_repos()` works as expected", { mockery::stub( github_testhost_priv$get_all_repos, - "private$prepare_repos_table_from_graphql", + "graphql_engine$prepare_repos_table", test_mocker$use("gh_repos_table_with_api_url") ) expect_snapshot( diff --git a/tests/testthat/test-01-get_repos-GitLab.R b/tests/testthat/test-01-get_repos-GitLab.R index 0fbe209f..751455f6 100644 --- a/tests/testthat/test-01-get_repos-GitLab.R +++ b/tests/testthat/test-01-get_repos-GitLab.R @@ -149,7 +149,7 @@ test_that("`get_repos_languages` works", { }) test_that("`prepare_repos_table()` prepares repos table", { - gl_repos_table <- gitlab_testhost_priv$prepare_repos_table_from_graphql( + gl_repos_table <- test_graphql_gitlab$prepare_repos_table( repos_list = test_mocker$use("gl_repos_from_org") ) expect_repos_table( @@ -168,7 +168,7 @@ test_that("GitHost adds `repo_api_url` column to GitLab repos table", { test_that("`tailor_repos_response()` tailors precisely `repos_list`", { gl_repos_by_code <- test_mocker$use("gl_search_repos_by_code") gl_repos_by_code_tailored <- - gitlab_testhost_priv$tailor_repos_response(gl_repos_by_code) + test_rest_gitlab$tailor_repos_response(gl_repos_by_code) gl_repos_by_code_tailored %>% expect_type("list") %>% expect_length(length(gl_repos_by_code)) @@ -188,9 +188,9 @@ test_that("`tailor_repos_response()` tailors precisely `repos_list`", { test_mocker$cache(gl_repos_by_code_tailored) }) -test_that("GitHost prepares table from GitLab repositories response", { +test_that("REST client prepares table from GitLab repositories response", { expect_snapshot( - gl_repos_by_code_table <- gitlab_testhost_priv$prepare_repos_table_from_rest( + gl_repos_by_code_table <- test_rest_gitlab$prepare_repos_table( repos_list = test_mocker$use("gl_repos_by_code_tailored") ) ) From 2c143d83181acbdf6085ec5959c1b8eedeff892a Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 15 Oct 2024 12:21:29 +0000 Subject: [PATCH 2/3] 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( From 9defa4c413e4fc5e32d4d18c04a2c70e1b5cda0c Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 15 Oct 2024 12:21:41 +0000 Subject: [PATCH 3/3] Bump version. --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 971b2a0f..7782078c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Get Statistics from GitHub and GitLab -Version: 2.1.0.9002 +Version: 2.1.0.9003 Authors@R: c( person(given = "Maciej", family = "Banas", email = "banasmaciek@gmail.com", role = c("aut", "cre")), person(given = "Kamil", family = "Koziej", email = "koziej.k@gmail.com", role = "aut"),