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

Last changes to release. #308

Merged
merged 17 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
.Ruserdata
example_workflow_Roche.R
example_branch.R
docs
inst/doc
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GitStats
Title: Get Statistics from Git Hosting Services
Version: 0.1.0.9011
Title: Get Statistics from GitHub and GitLab
Version: 1.0.0
Authors@R: c(
person(given = "Maciej", family = "Banaś", email = "[email protected]", role = c("aut", "cre")),
person(given = "Kamil", family = "Koziej", email = "[email protected]", role = "aut"),
Expand Down
53 changes: 35 additions & 18 deletions NEWS.md
marcinkowskak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
GitStats (development version)

- added `get_*_stats` functions to prepare summary stats from pulled data: repositories and commits (I: #276),
- rename and refactor plot functions to one generic `gitstats_plot` which takes as an input `repos_stats` or `commits_stats` (I: #276),
- changed names of `get_*` to `pull_*` functions; `get_*` functions are now to retrieve already pulled data from GitStats object (I: #294),
- changed name of `setup` to `set_params` function (I: #294),
- set new name for `set_connection` function: `set_host` as it is more informative (and shorter) (I: #271),
- changed name of a function: `add_team_member` to `set_team_member` (I: #271),
- added setting tokens by default - if a user does have all the PATs set up in environment variables (as e.g. `GITHUB_PAT` or `GITLAB_PAT`), there is no need to pass them as an argument to `set_connection` (I: #120 PR: #268),
- added `pull_users()` function to pull information on users (I: #199 PR: #238),
# GitStats 1.0.0

## Breaking changes:

### New functions:

- added `get_*_stats()` functions to prepare summary stats from pulled data: repositories and commits (I: #276),
- rename and refactor plot functions to one generic `gitstats_plot()` which takes as an input `repos_stats` or `commits_stats` class objects (I: #276),

### New names for core functions:

- changed names from `get_*` to `pull_*`; `get_*` functions are now to retrieve already pulled data from GitStats object (I: #294),
- changed name from `setup()` to `set_params()` (I: #294),
- changed name from `set_connection()` to `set_host()` (I: #271),
- changed name from `add_team_member()` to `set_team_member()` (I: #271).

## Major changes:

### New features:

- added setting tokens by default - if the user does have all the PATs set up in environment variables (as e.g. `GITHUB_PAT` or `GITLAB_PAT`), there is no need to pass them as an argument to `set_host()` (I: #120),
- added `pull_users()` function to pull information on users (I: #199),
- added possibility of scanning whole internal git platforms if no `orgs` are passed (I: #258),
- added switching to REST engine in case GraphQL fails with 502 error (I: #225 PRs: #227 (for repos) #261 (for commits))
- added `get_orgs()` function to print all organizations (I: #283),
- added GraphQL engine for getting GitLab repos by organization (I: #218 PR: #233)
- removed `contributors` as basic stat when pulling `repos` by `org` and by `phrase` to improve speed of pulling repositories data. Added `pull_repos_contributors()` user function and `add_contributors` parameter to `pull_repos()` function to add conditionally information on contributors to repositories table (I: #235 PRs: #243 #264)
- added resetting all settings to default with `reset()` function (I: #270)
- added resetting language in your search preferences with `reset_language()` or setting `language` parameter to `All` in `setup()` function (I: #231 PR: #265)
- OOP optimization: moved method on adding issues do repository table via REST to privates (I: #235 PR: #243)
- handled errors when tokens do not grant access (I: #242 PR: #247)
- in repositories output set `api_url` column as an address to the repo, not the host (I: #201 PR: #249)
- added resetting language in your search preferences with `reset_language()` or setting `language` parameter to `All` in `setup()` function (I: #231)

### Improving performance with REST and GraphQL APIs:

- added switching to REST engine in case GraphQL fails with 502 error (I: #225)
- added GraphQL engine for getting GitLab repositories by organization (I: #218)
- removed `contributors` as basic stat when pulling `repos` by `org` and by `phrase` to improve speed of pulling repositories data. Added `pull_repos_contributors()` user function and `add_contributors` parameter to `pull_repos()` function to add conditionally information on contributors to repositories table (I: #235)

## Minor changes:

- handled errors with proper messages when tokens do not grant access (I: #242 #301),
- in repositories output set `api_url` column as an address to the repository, not the host (I: #201),
- fixed adding GitLab subgroups (I: #176),
- exported pipe operator (`%>%`) (I: #289).

GitStats 0.1.0
# GitStats 0.1.0

This is the first release of GitStats with given features:

Expand Down
6 changes: 6 additions & 0 deletions R/EngineGraphQL.R
marcinkowskak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @importFrom dplyr distinct mutate relocate filter
#'
#' @title A EngineGraphQL class
Expand Down Expand Up @@ -62,6 +63,11 @@ EngineGraphQL <- R6::R6Class("EngineGraphQL",
gql_query = self$gql_query$user(),
vars = list("user" = username)
)
if (length(response$errors) > 0) {
cli::cli_abort(
response$errors[[1]]$message
)
}
return(response)
}
)
Expand Down
6 changes: 6 additions & 0 deletions R/EngineGraphQLGitHub.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @importFrom dplyr distinct mutate filter
#'
#' @title A EngineGraphQLGitHub class
Expand Down Expand Up @@ -30,6 +31,11 @@ EngineGraphQLGitHub <- R6::R6Class("EngineGraphQLGitHub",
end_cursor = end_cursor
)
)
if (length(response$errors) > 0) {
cli::cli_abort(
response$errors[[1]]$message
)
}
orgs_list <- purrr::map(response$data$search$edges, ~stringr::str_match(.$node$url, "[^\\/]*$"))
full_orgs_list <- append(full_orgs_list, orgs_list)
has_next_page <- response$data$search$pageInfo$hasNextPage
Expand Down
13 changes: 13 additions & 0 deletions R/EngineGraphQLGitLab.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @importFrom dplyr relocate
#'
#' @title A EngineGraphQLGitLab class
Expand Down Expand Up @@ -29,6 +30,15 @@ EngineGraphQLGitLab <- R6::R6Class("EngineGraphQLGitLab",
gql_query = self$gql_query$groups(),
vars = list("groupCursor" = group_cursor)
)
if (length(response$data$groups$edges) == 0) {
cli::cli_abort(
c(
"x" = "Empty response.",
"!" = "Your token probably does not cover scope to pull organizations.",
"i" = "Set `read_api` scope when creating GitLab token."
)
)
}
orgs_list <- purrr::map(response$data$groups$edges, ~.$node$fullPath)
full_orgs_list <- append(full_orgs_list, orgs_list)
has_next_page <- response$data$groups$pageInfo$hasNextPage
Expand Down Expand Up @@ -107,6 +117,9 @@ EngineGraphQLGitLab <- R6::R6Class("EngineGraphQLGitLab",
users = users,
repo_cursor = repo_cursor
)
if (length(repos_response$data$group) == 0) {
cli::cli_abort("Empty")
}
if (from == "org") {
core_response <- repos_response$data$group$projects
repos_list <- core_response$edges
Expand Down
1 change: 1 addition & 0 deletions R/EngineRest.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @importFrom httr2 request req_headers req_perform resp_body_json
#' @importFrom cli cli_abort col_green
#' @importFrom rlang %||%
Expand Down
1 change: 1 addition & 0 deletions R/EngineRestGitHub.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @title A EngineRestGitHub class
#' @description A class for methods wrapping GitHub's REST API responses.
EngineRestGitHub <- R6::R6Class("EngineRestGitHub",
Expand Down
1 change: 1 addition & 0 deletions R/EngineRestGitLab.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @title A EngineRestGitLab class
#' @description A class for methods wrapping GitLab's REST API responses.
EngineRestGitLab <- R6::R6Class("EngineRestGitLab",
Expand Down
1 change: 1 addition & 0 deletions R/GQLQueryGitHub.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @title A GQLQueryGitHub class
#' @description A class with methods to build GraphQL Queries for GitHub.

Expand Down
1 change: 1 addition & 0 deletions R/GQLQueryGitLab.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @title A GQLQueryGitLab class
#' @description A class with methods to build GraphQL Queries for GitLab.

Expand Down
36 changes: 24 additions & 12 deletions R/GitHost.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @importFrom R6 R6Class
#' @importFrom rlang expr
#' @importFrom cli cli_alert_danger cli_alert_success
Expand Down Expand Up @@ -99,8 +100,8 @@ GitHost <- R6::R6Class("GitHost",
#' @param settings A list of `GitStats` settings.
#' @return A data.frame of commits
pull_commits = function(date_from,
date_until = Sys.Date(),
settings) {
date_until = Sys.Date(),
settings) {
if (settings$search_param == "phrase") {
cli::cli_abort(c(
"x" = "Pulling commits by phrase in code blobs is not supported.",
Expand Down Expand Up @@ -315,18 +316,29 @@ GitHost <- R6::R6Class("GitHost",
},
error = function(e) {
if (!private$scan_all) {
if (grepl("502", e)) {
cli::cli_alert_warning(cli::col_yellow("HTTP 502 Bad Gateway Error. Switch to another Engine."))
} else {
cli::cli_alert_warning(cli::col_yellow("Error. Switch to another Engine."))
if (grepl("502|400", e)) {
if (grepl("502", e)) {
cli::cli_alert_warning(cli::col_yellow("HTTP 502 Bad Gateway Error."))
} else if (grepl("400", e)) {
cli::cli_alert_warning(cli::col_yellow("HTTP 400 Bad Request."))
}
cli::cli_alert_info("Switching to REST engine.")
repos_list <<- purrr::map(private$engines, function (engine) {
engine$pull_repos_supportive(
org = org,
settings = settings
)
})
} else if (grepl("Empty", e)) {
cli::cli_abort(
c(
"x" = "Empty response.",
"!" = "Your token probably does not cover scope to pull repositories.",
"i" = "Set `read_api` scope when creating GitLab token."
)
)
}
}
repos_list <<- purrr::map(private$engines, function (engine) {
engine$pull_repos_supportive(
org = org,
settings = settings
)
})
})
repos_table_org <- purrr::list_rbind(repos_list)
return(repos_table_org)
Expand Down
1 change: 1 addition & 0 deletions R/GitStats.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @noRd
#' @importFrom R6 R6Class
#' @importFrom cli cli_alert_info cli_alert_success cli_alert_warning col_yellow
#' @importFrom data.table rbindlist :=
Expand Down
4 changes: 2 additions & 2 deletions R/get_stats.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Get Statistics On Repositories
#' @title Get statistics on repositories
#' @name get_repos_stats
#' @description Prepare statistics from the pulled repositories data.
#' @param gitstats_obj A GitStats class object.
Expand Down Expand Up @@ -41,7 +41,7 @@ get_repos_stats <- function(gitstats_obj){
return(repos_stats)
}

#' @title Get Statistics On Commits
#' @title Get statistics on commits
#' @name get_commits_stats
#' @description Prepare statistics from the pulled commits data.
#' @param gitstats_obj A GitStats class object.
Expand Down
21 changes: 11 additions & 10 deletions R/gitstats_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ create_gitstats <- function() {
GitStats$new()
}

#' @title Add Git host
#' @title Set Git host
#' @name set_host
#' @param gitstats_obj A GitStats object.
#' @param api_url A character, url address of API.
Expand Down Expand Up @@ -48,7 +48,7 @@ set_host <- function(gitstats_obj,
return(invisible(gitstats_obj))
}

#' @title Set up your search settings.
#' @title Set up your search settings
#' @name set_params
#' @param gitstats_obj A GitStats object.
#' @param search_param One of three: team, orgs or phrase.
Expand Down Expand Up @@ -84,7 +84,7 @@ set_params <- function(gitstats_obj,
return(gitstats_obj)
}

#' @title Add your team member
#' @title Set your team member
#' @name set_team_member
#' @description Passes information on team member to your `team` field.
#' @param gitstats_obj `GitStats` object.
Expand All @@ -109,7 +109,7 @@ set_team_member <- function(gitstats_obj,
return(invisible(gitstats_obj))
}

#' @title Get information on repositories.
#' @title Pull information on repositories
#' @name pull_repos
#' @description List all repositories for an organization, a team or by a
#' keyword.
Expand Down Expand Up @@ -150,20 +150,21 @@ pull_repos <- function(gitstats_obj, add_contributors = FALSE) {
return(invisible(gitstats_obj))
}

#' @title Add information on contributors to your repositories.
#' @title Pull information on contributors
#' @name pull_repos_contributors
#' @param gitstats_obj A GitStats object.
#' @description A method to add information on repository contributors.
#' @description A method to add information on contributors to already pulled
#' repositories table.
#' @return A table of repositories with added information on contributors.
#' @export
pull_repos_contributors <- function(gitstats_obj) {
gitstats_obj$pull_repos_contributors()
return(invisible(gitstats_obj))
}

#' @title Get information on commits.
#' @title Pull information on commits
#' @name pull_commits
#' @description List all repositories for an organization, a team.
#' @description List all commits from all repositories for an organization or a team.
#' @param gitstats_obj A GitStats object.
#' @param date_from A starting date to look commits for
#' @param date_until An end date to look commits for
Expand Down Expand Up @@ -200,9 +201,9 @@ pull_commits <- function(gitstats_obj,
return(invisible(gitstats_obj))
}

#' @title Get users statistics.
#' @title Pull users data
#' @name pull_users
#' @description Get information on users.
#' @description Pull users data from Git Host.
#' @param gitstats_obj A GitStats object.
#' @param users A character vector of users.
#' @examples
Expand Down
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ Please remember to have your access tokens stored as environment variables: `GIT

### Scope of tokens

In the spirit of good practice of setting minimal scope of access to tokens for `GitStats` to work you need:
For `GitStats` to work you need:

- [GitHub] `public_repo` and `read:user` scopes,
- [GitHub] `public_repo`, `read:org` and `read:user` scopes,
- [GitLab] `read_api` scope.

## GitStats workflow

On how to use GitStats, refer to the [documentation](placeholder for a link to docs).
On how to use GitStats, refer to the [documentation](https://r-world-devs.github.io/GitStats/index.html).

## Acknowledgement

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ GitLab API.

### Scope of tokens

In the spirit of good practice of setting minimal scope of access to
tokens for `GitStats` to work you need:
For `GitStats` to work you need:

- \[GitHub\] `public_repo` and `read:user` scopes,
- \[GitHub\] `public_repo`, `read:org` and `read:user` scopes,
- \[GitLab\] `read_api` scope.

## GitStats workflow

On how to use GitStats, refer to the
[documentation](placeholder%20for%20a%20link%20to%20docs).
[documentation](https://r-world-devs.github.io/GitStats/index.html).

## Acknowledgement

Expand Down
11 changes: 11 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
url: ~
template:
bootstrap: 5
reference:
- contents:
- matches("create_gitstats")
- starts_with("set_")
- starts_with("pull_")
- starts_with("get_")
- starts_with("reset")
- matches("gitstats_plot")
Loading
Loading