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

319 tweak gitstats for cran release #515

Merged
merged 12 commits into from
Oct 21, 2024
Merged
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
^pkgdown$
^project_metadata.yaml
^.lintr
^CRAN-SUBMISSION$
^cran-comments\.md$
^vignettes/get_and_store_data\.Rmd$
^vignettes/get_files\.Rmd$
3 changes: 1 addition & 2 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: ⬆️ Check Version Bump

on:
pull_request:
paths:
- DESCRIPTION
branches: [devel, test, master]

jobs:
check-version:
Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: GitStats
Title: Get Statistics from GitHub and GitLab
Version: 2.1.1
Version: 2.1.1.9000
Authors@R: c(
person(given = "Maciej", family = "Banas", email = "[email protected]", role = c("aut", "cre")),
person(given = "Kamil", family = "Koziej", email = "[email protected]", role = "aut"),
person(given = "Karolina", family = "Marcinkowska", email = "[email protected]", role = "aut"),
person(given = "Matt", family = "Secrest", email = "[email protected]", role = "aut")
)
Description: Obtain statistics in a standardized way from multiple Git services: GitHub and GitLab for the time-being.
Its main purpose is to help teams, whose activities are spread across multiple git platforms, get their repository
metadata in a standardized way from all these platforms.
Description: Obtain statistics in a standardized way from multiple Git services. Its main purpose is to help teams,
whose activities are spread across multiple git platforms, get their repository metadata in a standardized way
from all these platforms.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ This is a major release with general changes in workflow (simplifying it), chang

## Simplifying workflow:

- GitStats workflow is now simplified. To pull data on `repositories`, `commits`, `R_package_usage` or other you should use directly corresponding `get_*()` functions instead of `pull_*()` which are deprecated. These `get_*()` functions pull data from API, parse it into table, add some goodies (additional columns) if needed and return table instead of `GitStats` object, which in our opinion is more intuitive and user-friendly ([#345]((https://github.com/r-world-devs/GitStats/issues/345))). That means you do not need to run in pipe two or three additional function calls as before, e.g. `pull_repos(gitstats_object) %>% get_repos() %>% get_repos_stats()`, but you just run
- GitStats workflow is now simplified. To pull data on `repositories`, `commits`, `R_package_usage` or other you should use directly corresponding `get_*()` functions instead of `pull_*()` which are deprecated. These `get_*()` functions pull data from API, parse it into table, add some goodies (additional columns) if needed and return table instead of `GitStats` object, which in our opinion is more intuitive and user-friendly ([#345](https://github.com/r-world-devs/GitStats/issues/345)). That means you do not need to run in pipe two or three additional function calls as before, e.g. `pull_repos(gitstats_object) %>% get_repos() %>% get_repos_stats()`, but you just run
`get_repos(gitstats_object)` to get data you need.
- Moreover, if you run for the second time `get_*()` function `GitStats` will pull the data from its storage and not from API as for the first time, unless you change parameters for the function (e.g. starting date with `since` in `get_commits()`) or change directly the `cache` parameter in the function. ([#333](https://github.com/r-world-devs/GitStats/issues/333))
- `pull_repos_contributors()` as a separate function is deprecated. The parameter `add_contributors` is now set by default to `TRUE` in `get_repos()` which seems more reasonable as user gets all the data.
Expand Down
6 changes: 6 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ With GitStats you can pull git data in a uniform way (table format) from GitHub
## Installation

```r
From CRAN:

install.packages("GitStats")

Or development version:

devtools::install_github("r-world-devs/GitStats")
```

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ GitHub and GitLab. For the time-being you can get data on:
## Installation

``` r
From CRAN:

install.packages("GitStats")

Or development version:

devtools::install_github("r-world-devs/GitStats")
```

Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
29 changes: 2 additions & 27 deletions tests/testthat/_snaps/01-get_repos-GitHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,10 @@
Output
[1] "\n query GetReposByOrg($login: String! $repoCursor: String!) {\n repositoryOwner(login: $login) {\n ... on Organization {\n \n repositories(first: 100 after: $repoCursor) {\n totalCount\n pageInfo {\n endCursor\n hasNextPage\n }\n nodes {\n repo_id: id\n repo_name: name\n default_branch: defaultBranchRef {\n name\n }\n stars: stargazerCount\n forks: forkCount\n created_at: createdAt\n last_activity_at: pushedAt\n languages (first: 5) { nodes {name} }\n issues_open: issues (first: 100 states: [OPEN]) {\n totalCount\n }\n issues_closed: issues (first: 100 states: [CLOSED]) {\n totalCount\n }\n organization: owner {\n login\n }\n repo_url: url\n }\n }\n \n }\n }\n }"

# `prepare_repos_table()` prepares repos table
# `get_all_repos()` prints proper message

Code
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...

# `prepare_repos_table()` prepares minimum version of repos table

Code
gh_repos_by_code_table_min <- test_rest_github$prepare_repos_table(repos_list = test_mocker$
use("gh_repos_by_code_tailored_min"), output = "table_min")
Message
i Preparing repositories table...

# `get_all_repos()` works as expected

Code
gh_repos_table <- github_testhost_priv$get_all_repos()
gh_repos_table <- github_testhost_priv$get_all_repos(verbose = TRUE)
Message
i [Host:GitHub][Engine:GraphQl][Scope:test-org] Pulling repositories...

# `get_repos_contributors()` works on GitHost level

Code
gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"), verbose = TRUE,
progress = FALSE)
Message
i [Host:GitHub][Engine:REST] Pulling contributors...

8 changes: 0 additions & 8 deletions tests/testthat/_snaps/01-get_repos-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@
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 }"

# REST client prepares table from GitLab repositories response

Code
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...

8 changes: 0 additions & 8 deletions tests/testthat/_snaps/01-get_repos-GitStats.md

This file was deleted.

8 changes: 0 additions & 8 deletions tests/testthat/_snaps/get_commits-GitLab.md

This file was deleted.

9 changes: 9 additions & 0 deletions tests/testthat/_snaps/get_commits-GitStats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# get_commits() returns error when since is not defined

You need to pass date to `since` parameter.

# get_commits_stats returns error when no commits

x No commits found in GitStats storage.
i Run first `get_commits()`.

10 changes: 0 additions & 10 deletions tests/testthat/_snaps/get_files_content-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,3 @@
Output
[1] "\n query GetFilesByRepo($fullPath: ID!, $file_paths: [String!]!) {\n project(fullPath: $fullPath) {\n name\n id\n webUrl\n repository {\n blobs(paths: $file_paths) {\n nodes {\n name\n rawBlob\n size\n }\n }\n }\n }\n }\n "

# Gitlab GraphQL switches to pulling files per repositories when query is too complex

Code
gitlab_files_response_by_repos <- test_graphql_gitlab$get_files_from_org(org = "mbtests",
type = "organization", repos = NULL, file_paths = c("DESCRIPTION",
"project_metadata.yaml", "README.md"), host_files_structure = NULL,
only_text_files = TRUE, verbose = TRUE, progress = FALSE)
Message
i I will switch to pulling files per repository.

9 changes: 0 additions & 9 deletions tests/testthat/_snaps/get_files_structure-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
Output
[1] "\n query GetFilesTree ($fullPath: ID!, $file_path: String!) {\n project(fullPath: $fullPath) {\n repository {\n tree(path: $file_path) {\n trees (first: 100) {\n pageInfo{\n endCursor\n hasNextPage\n }\n nodes {\n name\n }\n }\n blobs (first: 100) {\n pageInfo{\n endCursor\n hasNextPage\n }\n nodes {\n name\n }\n }\n }\n }\n }\n }\n "

# get_files_structure_from_orgs pulls files structure for repositories in orgs

Code
gl_files_structure_from_orgs <- gitlab_testhost_priv$
get_files_structure_from_orgs(pattern = "\\.md", depth = 1L, verbose = TRUE,
progress = FALSE)
Message
i [Host:GitLab][Engine:GraphQl][Scope:mbtests] Pulling files structure...[files matching pattern: '\.md']...

# get_files_content makes use of files_structure

Code
Expand Down
6 changes: 0 additions & 6 deletions tests/testthat/_snaps/get_files_structure-GitStats.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@
! No files structure found for matching pattern \.png in 1 level of dirs.
! Files structure will not be saved in GitStats.

# get_files_structure works as expected

Code
files_structure <- test_gitstats$get_files_structure(pattern = "\\.md", depth = 2L,
verbose = TRUE)

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/get_release-GitHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
Output
[1] "query GetReleasesFromRepo ($org: String!, $repo: String!) {\n repository(owner:$org, name:$repo){\n name\n url\n releases (last: 100) {\n nodes {\n name\n tagName\n publishedAt\n url\n description\n }\n }\n }\n }"

# `get_release_logs()` prints proper message when running

Code
releases_table <- github_testhost$get_release_logs(since = "2023-05-01", until = "2023-09-30",
verbose = TRUE, progress = FALSE)
Message
i [Host:GitHub][Engine:GraphQl][Scope:test-org] Pulling release logs...

50 changes: 0 additions & 50 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
if (nchar(Sys.getenv("GITHUB_PAT")) == 0) {
cli::cli_abort(c(
"x" = "You did not set up your GITHUB_PAT environment variable.",
"i" = "If you wish to run tests for GitHub - set up your GITHUB_PAT
enviroment variable (as a GitHub access token on github.com)."
))
}
if (nchar(Sys.getenv("GITHUB_PAT")) > 0) {
tryCatch({
httr2::request("https://api.github.com") %>%
httr2::req_headers("Authorization" = paste0("Bearer ", Sys.getenv("GITHUB_PAT"))) %>%
httr2::req_perform()
},
error = function(e) {
if (grepl("401", e$message)) {
cli::cli_abort(c(
"x" = "Your GITHUB_PAT enviroment variable does not grant access. Please
setup your GITHUB_PAT before running tests.",
"i" = "If you wish to run tests for GitHub - set up your GITHUB_PAT
enviroment variable (as a GitHub access token on github.com)."
))
}
})
}
if (nchar(Sys.getenv("GITLAB_PAT_PUBLIC")) == 0) {
cli::cli_abort(c(
"x" = "You did not set up your GITLAB_PAT_PUBLIC environment variable.",
"i" = "If you wish to run tests for GitLab - set up your GITLAB_PAT_PUBLIC
enviroment variable (as a GitLab access token on gitlab.com)."
))
}
if (nchar(Sys.getenv("GITLAB_PAT_PUBLIC")) > 0) {
tryCatch({
httr2::request("https://gitlab.com/api/v4/projects") %>%
httr2::req_headers("Authorization" = paste0("Bearer ",
Sys.getenv("GITLAB_PAT_PUBLIC"))) %>%
httr2::req_perform()
},
error = function(e) {
if (grepl("401", e$message)) {
cli::cli_abort(c(
"x" = "Your GITLAB_PAT_PUBLIC enviroment variable does not grant access.
Please setup your GITLAB_PAT_PUBLIC before running tests.",
"i" = "If you wish to run tests for GitLab - set up your GITLAB_PAT_PUBLIC
enviroment variable (as a GitLab access token on gitlab.com)."
))
}
})
}

test_mocker <- Mocker$new()

test_gitstats <- create_test_gitstats(hosts = 2)
Expand Down
43 changes: 26 additions & 17 deletions tests/testthat/test-01-get_repos-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ test_that("GitHub tailors `repos_list` to minimal version of table", {
})

test_that("`prepare_repos_table()` prepares repos table", {
expect_snapshot(
gh_repos_by_code_table <- test_rest_github$prepare_repos_table(
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"),
verbose = FALSE
)
expect_repos_table(
gh_repos_by_code_table
Expand All @@ -238,11 +237,10 @@ test_that("`prepare_repos_table()` prepares repos table", {
})

test_that("`prepare_repos_table()` prepares minimum version of repos table", {
expect_snapshot(
gh_repos_by_code_table_min <- test_rest_github$prepare_repos_table(
repos_list = test_mocker$use("gh_repos_by_code_tailored_min"),
output = "table_min"
)
gh_repos_by_code_table_min <- test_rest_github$prepare_repos_table(
repos_list = test_mocker$use("gh_repos_by_code_tailored_min"),
output = "table_min",
verbose = FALSE
)
expect_repos_table(
gh_repos_by_code_table_min,
Expand Down Expand Up @@ -399,15 +397,28 @@ test_that("`get_all_repos()` works as expected", {
"graphql_engine$prepare_repos_table",
test_mocker$use("gh_repos_table")
)
expect_snapshot(
gh_repos_table <- github_testhost_priv$get_all_repos()
gh_repos_table <- github_testhost_priv$get_all_repos(
verbose = FALSE
)
expect_repos_table(
gh_repos_table
)
test_mocker$cache(gh_repos_table)
})

test_that("`get_all_repos()` prints proper message", {
mockery::stub(
github_testhost_priv$get_all_repos,
"graphql_engine$prepare_repos_table",
test_mocker$use("gh_repos_table")
)
expect_snapshot(
gh_repos_table <- github_testhost_priv$get_all_repos(
verbose = TRUE
)
)
})

test_that("GitHost adds `repo_api_url` column to GitHub repos table", {
repos_table <- test_mocker$use("gh_repos_table")
gh_repos_table_with_api_url <- github_testhost_priv$add_repo_api_url(repos_table)
Expand Down Expand Up @@ -469,12 +480,10 @@ test_that("`get_repos_contributors()` works on GitHost level", {
"rest_engine$get_repos_contributors",
test_mocker$use("gh_repos_with_contributors")
)
expect_snapshot(
gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"),
verbose = TRUE,
progress = FALSE
)
gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"),
verbose = FALSE,
progress = FALSE
)
expect_repos_table(
gh_repos_with_contributors,
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-01-get_repos-GitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ test_that("`tailor_repos_response()` tailors precisely `repos_list`", {
})

test_that("REST client prepares table from GitLab repositories response", {
expect_snapshot(
gl_repos_by_code_table <- test_rest_gitlab$prepare_repos_table(
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"),
verbose = FALSE
)
expect_repos_table(
gl_repos_by_code_table
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-01-get_repos-GitStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ test_that("get_repos works properly and for the second time uses cache", {
repos_object = repos_table,
with_cols = c("contributors", "contributors_n")
)
expect_snapshot(
repos_table <- test_gitstats$get_repos()
repos_table <- test_gitstats$get_repos(
verbose = FALSE
)
expect_repos_table_object(
repos_object = repos_table,
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-get_commits-GitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ test_that("`get_commits_authors_handles_and_names()` adds author logis and names
"private$get_authors_dict",
test_mocker$use("authors_dict")
)
expect_snapshot(
gl_commits_table <- test_rest_gitlab$get_commits_authors_handles_and_names(
commits_table = test_mocker$use("gl_commits_table"),
verbose = TRUE
)
gl_commits_table <- test_rest_gitlab$get_commits_authors_handles_and_names(
commits_table = test_mocker$use("gl_commits_table"),
verbose = FALSE
)
expect_commits_table(
gl_commits_table,
Expand Down
Loading
Loading