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

485 fix pkgdown job #486

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GITLAB_PAT_PUBLIC: ${{ secrets.GITLAB_PAT}}
permissions:
contents: write
steps:
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Changed message when searching scope is set to scan whole git host (no `orgs` nor `repos` specified) from warning to info ([#456](https://github.com/r-world-devs/GitStats/issues/456)).
- Added new CI/CD jobs: deploy to `gh-pages`, lint and check for bumping version.
- Mocked extensively API responses to improve tests and checks progress ([#481](https://github.com/r-world-devs/GitStats/issues/481)].

# GitStats 2.0.2

Expand Down
5 changes: 5 additions & 0 deletions R/EngineGraphQLGitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ EngineGraphQLGitLab <- R6::R6Class(
repo_name <- url_split[length(url_split)]
return(repo_name)
},

get_repos_data = function(org, repos = NULL) {
repos_list <- self$get_repos_from_org(
org = org
Expand All @@ -288,6 +289,7 @@ EngineGraphQLGitLab <- R6::R6Class(
)
return(result)
},

get_file_blobs_response = function(org, repo, file_paths) {
file_blobs_response <- self$gql_response(
gql_query = self$gql_query$file_blob_from_repo(),
Expand All @@ -298,6 +300,7 @@ EngineGraphQLGitLab <- R6::R6Class(
)
return(file_blobs_response)
},

get_files_tree_response = function(org, repo, file_path) {
files_tree_response <- self$gql_response(
gql_query = self$gql_query$files_tree_from_repo(),
Expand All @@ -308,6 +311,7 @@ EngineGraphQLGitLab <- R6::R6Class(
)
return(files_tree_response)
},

get_files_structure_from_repo = function(org, repo, pattern = NULL, depth = Inf) {
files_tree_response <- private$get_files_tree_response(
org = org,
Expand Down Expand Up @@ -364,6 +368,7 @@ EngineGraphQLGitLab <- R6::R6Class(
}
return(files_structure)
},

get_files_and_dirs = function(files_tree_response) {
tree_nodes <- files_tree_response$data$project$repository$tree$trees$nodes
blob_nodes <- files_tree_response$data$project$repository$tree$blobs$nodes
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/get_files_structure-GitHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@
Output
named list()

# get_files_content makes use of files_structure

Code
files_content <- github_testhost_priv$get_files_content_from_orgs(file_path = NULL,
host_files_structure = test_mocker$use("gh_files_structure_from_orgs"))
Message
i I will make use of files structure stored in GitStats.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/get_files_structure-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@
Message
i [Host:GitLab][Engine:GraphQl][Scope:mbtests] Pulling files structure...[files matching pattern: '\.md|\.R']...

# get_files_content makes use of files_structure

Code
files_content <- gitlab_testhost_priv$get_files_content_from_orgs(file_path = NULL,
host_files_structure = test_mocker$use("gl_files_structure_from_orgs"))
Message
i I will make use of files structure stored in GitStats.

27 changes: 0 additions & 27 deletions tests/testthat/_snaps/get_files_structure-GitStats.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,3 @@
files_structure <- test_gitstats$get_files_structure(pattern = "\\.md", depth = 2L,
verbose = TRUE)

# get_files_content makes use of files_structure

Code
files_content <- test_gitstats$get_files_content(file_path = NULL,
use_files_structure = TRUE, verbose = TRUE)
Message
i I will make use of files structure stored in GitStats.
i [Host:GitHub][Engine:GraphQl][Scope:r-world-devs] Pulling files from files structure...
i [Host:GitHub][Engine:GraphQl][Scope:openpharma] Pulling files from files structure...
i I will make use of files structure stored in GitStats.
i [Host:GitLab][Engine:GraphQl][Scope:mbtests] Pulling files from files structure...
i [Host:GitLab][Engine:GraphQl][Scope:mbtestapps] Pulling files from files structure...

---

Code
test_gitstats
Output
A GitStats object for 2 hosts:
Hosts: https://api.github.com, https://gitlab.com/api/v4
Scanning scope:
Organizations: [2] r-world-devs, mbtests
Repositories: [0]
Storage:
character(0)
Files_structure: 2 [files matching pattern: \.md]

34 changes: 34 additions & 0 deletions tests/testthat/helper-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,40 @@ test_fixtures$github_search_response <- list(
)
)

test_fixtures$gitlab_files_tree_response <- list(
"data" = list(
"project" = list(
"repository" = list(
"tree" = list(
"trees" = list(
"nodes" = list(
list(
"name" = "R"
),
list(
"name" = "tests"
)
)
),
"blobs" = list(
"nodes" = list(
list(
"name" = "DESCRIPTION"
),
list(
"name" = "README.md"
),
list(
"name" = "project_metadata.yaml"
)
)
)
)
)
)
)
)

test_fixtures$github_files_tree_response <- list(
"data" = list(
"repository" = list(
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-get_files_structure-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,21 @@ test_that("get_files_structure pulls files structure for repositories in orgs",
})
test_mocker$cache(gh_files_structure_from_orgs)
})

test_that("get_files_content makes use of files_structure", {
mockery::stub(
github_testhost_priv$get_files_content_from_orgs,
"private$add_repo_api_url",
test_mocker$use("gh_files_table")
)
expect_snapshot(
files_content <- github_testhost_priv$get_files_content_from_orgs(
file_path = NULL,
host_files_structure = test_mocker$use("gh_files_structure_from_orgs")
)
)
expect_files_table(
files_content,
with_cols = "api_url"
)
})
23 changes: 23 additions & 0 deletions tests/testthat/test-get_files_structure-GitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ test_that("files tree query for GitLab are built properly", {
})

test_that("get_files_tree_response() works", {
mockery::stub(
test_graphql_gitlab_priv$get_files_tree_response,
"self$gql_response",
test_fixtures$gitlab_files_tree_response
)
gl_files_tree_response <- test_graphql_gitlab_priv$get_files_tree_response(
org = "mbtests",
repo = "graphql_tests",
Expand Down Expand Up @@ -220,3 +225,21 @@ test_that("get_files_structure pulls files structure for repositories in orgs",
})
test_mocker$cache(gl_files_structure_from_orgs)
})

test_that("get_files_content makes use of files_structure", {
mockery::stub(
gitlab_testhost_priv$get_files_content_from_orgs,
"private$add_repo_api_url",
test_mocker$use("gl_files_table")
)
expect_snapshot(
files_content <- gitlab_testhost_priv$get_files_content_from_orgs(
file_path = NULL,
host_files_structure = test_mocker$use("gl_files_structure_from_orgs")
)
)
expect_files_table(
files_content,
with_cols = "api_url"
)
})
21 changes: 0 additions & 21 deletions tests/testthat/test-get_files_structure-GitStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,3 @@ test_that("get_files_structure works as expected", {
expect_s3_class(files_structure, "files_structure")
test_mocker$cache(files_structure)
})

test_that("get_files_content makes use of files_structure", {
test_gitstats <- create_test_gitstats(
hosts = 2,
inject_files_structure = "files_structure"
)
expect_snapshot(
files_content <- test_gitstats$get_files_content(
file_path = NULL,
use_files_structure = TRUE,
verbose = TRUE
)
)
expect_files_table(
files_content,
with_cols = "api_url"
)
expect_snapshot(
test_gitstats
)
})
Loading