Skip to content

Commit

Permalink
Merge pull request #484 from r-world-devs/devel
Browse files Browse the repository at this point in the history
2.1.0 release
  • Loading branch information
maciekbanas authored Oct 1, 2024
2 parents 9ecc7b1 + d2f6382 commit 08a7d85
Show file tree
Hide file tree
Showing 108 changed files with 5,713 additions and 3,335 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^docs$
^pkgdown$
^project_metadata.yaml
^.lintr
28 changes: 28 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on: [push, pull_request]

name: lint

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/[email protected]

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
51 changes: 51 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
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:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
11 changes: 11 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters: linters_with_defaults(
quotes_linter = NULL,
line_length_linter = NULL,
object_usage_linter = NULL,
object_length_linter = NULL,
object_name_linter = NULL,
cyclocomp_linter = NULL
)
exclusions: list(
"inst",
"tests")
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GitStats
Title: Get Statistics from GitHub and GitLab
Version: 2.0.2
Version: 2.1.0
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"),
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export(create_gitstats)
export(get_R_package_usage)
export(get_commits)
export(get_commits_stats)
export(get_files)
export(get_files_content)
export(get_files_structure)
export(get_release_logs)
export(get_repos)
export(get_repos_urls)
Expand Down
16 changes: 15 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# GitStats 2.1.0

## New features:

- Added new `get_files_structure()` function to pull files structure for a given repository with possibility to control level of directories (`depth` parameter) and to limit output to files matching regex argument passed to `pattern` parameter ([#338](https://github.com/r-world-devs/GitStats/issues/338)). Together with that, `get_files()` function was renamed to `get_files_content()` to better reflect its purpose.
- Adjusted `get_files_content()` so it can make use of `files_structure` pulled to `GitStats` storage with `get_files_structure()` function - if `file_path` is set to `NULL` and `use_files_structure()` parameter to `TRUE` (both are by default)([#467](https://github.com/r-world-devs/GitStats/issues/467)).
- Added `progress` parameter to user functions to control showing of `cli` progress bar separately from messages (which are controlled with `verbose`) ([#465](https://github.com/r-world-devs/GitStats/issues/465)).

## Other:

- 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

This is a patch release with substantial improvements to some functions (`get_repos()`, `get_files()` and `get_R_package_usage()`), adding `with_files` and `in_files` parameters, fixing `cache` feature and introducing new `get_repos_urls()` function, a minimalist version of `get_repos()`:
Expand All @@ -19,7 +33,7 @@ This is a patch release with some hot issues that needed to be addressed, notabl

## Features:

- Getting files feature has been speeded up when `GitStats` is set to scan whole hosts, with switching to `Search API` instead of pulling files via `GraphQL` (with iteration over organizations and repositories) ([#411](https://github.com/r-world-devs/GitStats/issues/411)).
- Getting files feature has been sped up when `GitStats` is set to scan whole hosts, with switching to `Search API` instead of pulling files via `GraphQL` (with iteration over organizations and repositories) ([#411](https://github.com/r-world-devs/GitStats/issues/411)).
- When setting hosts to be scanned in whole (without specifying `orgs` or `repos`) GitStats does not pull no more all organizations. Pulling all organizations from host is triggered only when user decides to pull repositories from organizations. If he decides, e.g. to pull repositories by code, there is no need to pull all organizations (which may be a time consuming process), as GitStats uses then `Search API` ([#393](https://github.com/r-world-devs/GitStats/issues/393)).
- It is now possible to mute messages also from `set_*_host()` functions with `verbose_off()` or `verbose` parameter ([#413](https://github.com/r-world-devs/GitStats/issues/413)).
- Setting `verbose` to `FALSE` does not lead to hiding output of the `get_*()` functions - i.e. a glimpse of table will always appear after pulling data, even if the `verbose` is switched off. `verbose` parameter serves now only the purpose to show and hide messages to user ([#423](https://github.com/r-world-devs/GitStats/issues/423)).
Expand Down
135 changes: 82 additions & 53 deletions R/EngineGraphQL.R
Original file line number Diff line number Diff line change
@@ -1,62 +1,91 @@
#' @noRd
#' @description A class for methods wrapping GitHub's GraphQL API responses.
EngineGraphQL <- R6::R6Class("EngineGraphQL",
inherit = Engine,
EngineGraphQL <- R6::R6Class(
"EngineGraphQL",
inherit = Engine,
public = list(

public = list(
#' @field gql_api_url A character, url of GraphQL API.
gql_api_url = NULL,

#' @field gql_api_url A character, url of GraphQL API.
gql_api_url = NULL,
#' @field gql_query An environment for GraphQL queries.
gql_query = NULL,

#' @field gql_query An environment for GraphQL queries.
gql_query = NULL,
#' Create `EngineGraphQL` object.
initialize = function(gql_api_url = NA,
token = NA,
scan_all = FALSE) {
private$engine <- "graphql"
self$gql_api_url <- gql_api_url
private$token <- token
private$scan_all <- scan_all
},

#' Create `EngineGraphQL` object.
initialize = function(gql_api_url = NA,
token = NA,
scan_all = FALSE) {
private$engine <- "graphql"
self$gql_api_url <- gql_api_url
private$token <- token
private$scan_all <- scan_all
},
#' Wrapper of GraphQL API request and response.
gql_response = function(gql_query, vars = "null") {
response <- private$perform_request(
gql_query = gql_query,
vars = vars
)
response_list <- httr2::resp_body_json(response)
return(response_list)
},

#' Wrapper of GraphQL API request and response.
gql_response = function(gql_query, vars = "null") {
response <- private$perform_request(
gql_query = gql_query,
vars = vars
)
response_list <- httr2::resp_body_json(response)
return(response_list)
},
# A method to pull information on user.
get_user = function(username) {
response <- tryCatch(
{
self$gql_response(
gql_query = self$gql_query$user(),
vars = list("user" = username)
)
},
error = function(e) {
NULL
}
)
return(response)
}
),
private = list(

# A method to pull information on user.
pull_user = function(username) {
response <- tryCatch({
self$gql_response(
gql_query = self$gql_query$user(),
vars = list("user" = username)
)
}, error = function(e) {
NULL
})
return(response)
}
),
private = list(

# GraphQL method for pulling response from API
perform_request = function(gql_query, vars) {
response <- httr2::request(paste0(self$gql_api_url, "?")) %>%
httr2::req_headers("Authorization" = paste0("Bearer ", private$token)) %>%
httr2::req_body_json(list(query = gql_query, variables = vars)) %>%
httr2::req_retry(
is_transient = ~ httr2::resp_status(.x) %in% c(400, 500, 502),
max_seconds = 60
) %>%
httr2::req_perform()
return(response)
}
)
# GraphQL method for pulling response from API
perform_request = function(gql_query, vars) {
response <- httr2::request(paste0(self$gql_api_url, "?")) %>%
httr2::req_headers("Authorization" = paste0("Bearer ", private$token)) %>%
httr2::req_body_json(list(query = gql_query, variables = vars)) %>%
httr2::req_retry(
is_transient = ~ httr2::resp_status(.x) %in% c(400, 502),
max_seconds = 30
) %>%
httr2::req_perform()
return(response)
},
is_query_error = function(response) {
check <- FALSE
if (length(response) > 0) {
check <- names(response) == "errors"
}
return(check)
},
filter_files_by_pattern = function(files_structure, pattern) {
files_structure[grepl(pattern, files_structure)]
},
get_path_from_files_structure = function(host_files_structure,
only_text_files,
org,
repo = NULL) {
if (is.null(repo)) {
file_path <- host_files_structure[[org]] %>%
unlist(use.names = FALSE) %>%
unique()
} else {
file_path <- host_files_structure[[org]][[repo]]
}
if (only_text_files) {
file_path <- file_path[!grepl(non_text_files_pattern, file_path)]
}
return(file_path)
}
)
)
Loading

0 comments on commit 08a7d85

Please sign in to comment.