Skip to content

Commit

Permalink
Updates after code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Sep 1, 2023
1 parent 364912a commit 667f553
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 96 deletions.
18 changes: 9 additions & 9 deletions R/EngineRestGitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EngineRestGitHub <- R6::R6Class("EngineRestGitHub",
) %>%
private$tailor_repos_info() %>%
private$prepare_repos_table() %>%
private$add_repos_issues()
private$get_repos_issues()
} else {
repos_table <- NULL
}
Expand All @@ -45,7 +45,7 @@ EngineRestGitHub <- R6::R6Class("EngineRestGitHub",
) %>%
private$tailor_repos_info() %>%
private$prepare_repos_table() %>%
private$add_repos_issues()
private$get_repos_issues()
}
return(repos_table)
},
Expand Down Expand Up @@ -102,7 +102,7 @@ EngineRestGitHub <- R6::R6Class("EngineRestGitHub",
commits_table <- repos_list_with_commits %>%
private$tailor_commits_info(org = org) %>%
private$prepare_commits_table() %>%
private$add_commits_stats()
private$get_commits_stats()

return(commits_table)
},
Expand Down Expand Up @@ -317,10 +317,10 @@ EngineRestGitHub <- R6::R6Class("EngineRestGitHub",
repos_list
},

# @description A method to add information on repository contributors.
# @description A method to add information on open and closed issues of a repository.
# @param repos_table A table of repositories.
# @return A table of repositories with added information on contributors.
add_repos_issues = function(repos_table) {
# @return A table of repositories with added information on issues.
get_repos_issues = function(repos_table) {
if (nrow(repos_table) > 0) {
repos_iterator <- paste0(repos_table$organization, "/", repos_table$name)
issues <- purrr::map_dfr(repos_iterator, function(repo_path) {
Expand Down Expand Up @@ -471,10 +471,10 @@ EngineRestGitHub <- R6::R6Class("EngineRestGitHub",
return(commits_table)
},

# @description A wrapper to pull stats for all commits
# @param commits_table A table with commits
# @description A wrapper to pull stats for all commits.
# @param commits_table A table with commits.
# @return A data.frame
add_commits_stats = function(commits_table) {
get_commits_stats = function(commits_table) {
cli::cli_alert_info("[GitHub][Engine:{cli::col_green('REST')}] Pulling commits stats...")
repo_fullnames <- paste0(commits_table$organization, "/", commits_table$repository)
commit_stats <- purrr::map2_dfr(commits_table$id, repo_fullnames,
Expand Down
12 changes: 6 additions & 6 deletions R/EngineRestGitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EngineRestGitLab <- R6::R6Class("EngineRestGitLab",
) %>%
private$tailor_repos_info() %>%
private$prepare_repos_table() %>%
private$add_repos_issues()
private$get_repos_issues()
} else if (settings$search_param == "team") {
if (!private$scan_all) {
cli::cli_alert_info("[GitLab][Engine:{cli::col_green('REST')}][org:{org}][team:{settings$team_name}] Pulling repositories...")
Expand All @@ -31,7 +31,7 @@ EngineRestGitLab <- R6::R6Class("EngineRestGitLab",
repos_table <- private$pull_repos_from_org(org) %>%
private$tailor_repos_info() %>%
private$prepare_repos_table() %>%
private$add_repos_issues()
private$get_repos_issues()
suppressMessages({
repos_table <- self$get_repos_contributors(
repos_table = repos_table
Expand Down Expand Up @@ -59,7 +59,7 @@ EngineRestGitLab <- R6::R6Class("EngineRestGitLab",
repos_table <- private$pull_repos_from_org(org) %>%
private$tailor_repos_info() %>%
private$prepare_repos_table() %>%
private$add_repos_issues()
private$get_repos_issues()
}
return(repos_table)
},
Expand Down Expand Up @@ -277,10 +277,10 @@ EngineRestGitLab <- R6::R6Class("EngineRestGitLab",
projects_list
},

# @description A method to add information on repository contributors.
# @description A method to add information on open and closed issues of a repository.
# @param repos_table A table of repositories.
# @return A table of repositories with added information on contributors.
add_repos_issues = function(repos_table) {
# @return A table of repositories with added information on issues.
get_repos_issues = function(repos_table) {
if (nrow(repos_table) > 0) {
issues <- purrr::map(repos_table$id, function(repos_id) {
id <- gsub("gid://gitlab/Project/", "", repos_id)
Expand Down
26 changes: 13 additions & 13 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ devtools::install_github("r-world-devs/GitStats")

## Getting started

Please remember to have your access tokens stored as environment variables: `GITHUB_PAT` for access to GitHub API and `GITLAB_PAT` for GitLab API.

You can start by creating your `GitStats` object, where you will hold information on your multiple connections.

```{r}
library(GitStats)
library(magrittr)
git_stats <- create_gitstats() %>%
set_connection(
set_host(
api_url = "https://api.github.com",
token = Sys.getenv("GITHUB_PAT"),
orgs = c("r-world-devs", "openpharma", "pharmaverse")
) %>%
set_connection(
set_host(
api_url = "https://gitlab.com/api/v4",
token = Sys.getenv("GITLAB_PAT_PUBLIC"),
orgs = c("mbtests")
)
```
Expand All @@ -62,12 +62,11 @@ If you with to setup your search parameter to team, add your team members first:

```{r}
git_stats %>%
add_team_member("Adam Foryś", "galachad") %>%
add_team_member("Kamil Wais", "kalimu") %>%
add_team_member("Krystian Igras", "krystian8207") %>%
add_team_member("Karolina Marcinkowska", "marcinkowskak") %>%
add_team_member("Kamil Koziej", "Cotau") %>%
add_team_member("Maciej Banaś", "maciekbanas")
set_team_member("Kamil Wais", "kalimu") %>%
set_team_member("Krystian Igras", "krystian8207") %>%
set_team_member("Karolina Marcinkowska", "marcinkowskak") %>%
set_team_member("Kamil Koziej", "Cotau") %>%
set_team_member("Maciej Banaś", "maciekbanas")
setup(git_stats,
search_param = "team",
Expand Down Expand Up @@ -101,7 +100,8 @@ get_repos(git_stats)

Special thanks to:

- @Cotau - for reviewing permanently my pull requests and suggesting more efficient solutions,
- @marcinkowskak - for substantial improvements on plots,
- @kalimu, @galachad, @krystian8207 - for your guidelines at the very beginning of the project.
- Kamil Koziej @Cotau - for reviewing permanently my pull requests and suggesting more efficient solutions,
- Karolina Marcinkowska @marcinkowskak - for substantial improvements on plots,
- Matt Secrest @mattsecrest - for making use of your scripts to apply search feature,
- Kamil Wais @kalimu, Krystian Igraś @krystian8207, Adam Foryś @galachad - for your guidelines at the very beginning of the project.

114 changes: 57 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ devtools::install_github("r-world-devs/GitStats")

## Getting started

Please remember to have your access tokens stored as environment variables: `GITHUB_PAT` for access to GitHub API and `GITLAB_PAT` for GitLab API.

You can start by creating your `GitStats` object, where you will hold
information on your multiple connections.

Expand All @@ -34,14 +36,12 @@ library(GitStats)
library(magrittr)

git_stats <- create_gitstats() %>%
set_connection(
set_host(
api_url = "https://api.github.com",
token = Sys.getenv("GITHUB_PAT"),
orgs = c("r-world-devs", "openpharma", "pharmaverse")
) %>%
set_connection(
set_host(
api_url = "https://gitlab.com/api/v4",
token = Sys.getenv("GITLAB_PAT_PUBLIC"),
orgs = c("mbtests")
)
```
Expand All @@ -58,56 +58,55 @@ members first:

``` r
git_stats %>%
add_team_member("Adam Foryś", "galachad") %>%
add_team_member("Kamil Wais", "kalimu") %>%
add_team_member("Krystian Igras", "krystian8207") %>%
add_team_member("Karolina Marcinkowska", "marcinkowskak") %>%
add_team_member("Kamil Koziej", "Cotau") %>%
add_team_member("Maciej Banaś", "maciekbanas")
set_team_member("Kamil Wais", "kalimu") %>%
set_team_member("Krystian Igras", "krystian8207") %>%
set_team_member("Karolina Marcinkowska", "marcinkowskak") %>%
set_team_member("Kamil Koziej", "Cotau") %>%
set_team_member("Maciej Banaś", "maciekbanas")

setup(git_stats,
search_param = "team",
team_name = "RWD"
)
#> A <GitStats> object for 2 hosts:
#> Hosts: https://api.github.com, https://gitlab.com/api/v4
#> Organisations: r-world-devs, openpharma, pharmaverse, mbtests
#> Organisations: [4] r-world-devs, openpharma, pharmaverse, mbtests
#> Search preference: team
#> Team: RWD (6 members)
#> Team: RWD (5 members)
#> Phrase: <not defined>
#> Language: <not defined>
#> Language: All
#> Repositories output: <not defined>
#> Commits output: <not defined>

# now pull repos and commits by default by team
get_repos(git_stats)
#> Rows: 23
#> Rows: 18
#> Columns: 13
#> $ id <chr> "R_kgDOJWYrCA", "R_kgDOIvtxsg", "R_kgDOJAtHJA", "R_kg…
#> $ name <chr> "hypothesis", "GitStats", "shinyTimelines", "shinyGiz…
#> $ stars <int> 2, 1, 2, 16, 2, 4, 4, 10, 22, 2, 144, 1, 3, 7, 7, 0, …
#> $ forks <int> 0, 0, 0, 0, 2, 0, 0, 1, 5, 1, 36, 0, 3, 6, 4, NA, NA,…
#> $ created_at <dttm> 2023-04-13 13:52:24, 2023-01-09 14:02:20, 2023-02-21…
#> $ last_activity_at <drtn> 14.38 days, 0.38 days, 7.38 days, 4.38 days, 7.38 da…
#> $ languages <chr> "R, JavaScript", "R", "R, CSS", "R, CSS, JavaScript",…
#> $ issues_open <dbl> 0, 65, 0, 5, 22, 27, 1, 0, 0, 2, 64, 6, 3, 39, 26, 0,…
#> $ issues_closed <dbl> 0, 79, 0, 12, 1, 4, 0, 0, 1, 0, 986, 55, 23, 121, 35,…
#> $ contributors <chr> "krystian8207", "maciekbanas", "krystian8207", "kryst…
#> $ id <chr> "R_kgDOIvtxsg", "R_kgDOJAtHJA", "R_kgDOHNMr2w", "R_kg…
#> $ name <chr> "GitStats", "shinyTimelines", "shinyGizmo", "cohortBu…
#> $ stars <int> 1, 2, 16, 3, 5, 2, 10, 22, 2, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ forks <int> 0, 0, 0, 2, 0, 0, 1, 5, 1, NA, NA, NA, NA, NA, NA, NA…
#> $ created_at <dttm> 2023-01-09 14:02:20, 2023-02-21 16:41:59, 2022-04-20…
#> $ last_activity_at <drtn> 0.64 days, 119.64 days, 116.64 days, 119.64 days, 4.…
#> $ languages <chr> "R", "R, CSS", "R, CSS, JavaScript", "R", "R, CSS, Ja…
#> $ issues_open <dbl> 80, 0, 5, 22, 32, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1,…
#> $ issues_closed <dbl> 107, 0, 12, 1, 4, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ organization <chr> "r-world-devs", "r-world-devs", "r-world-devs", "r-wo…
#> $ repo_url <chr> "https://github.com/r-world-devs/hypothesis", "https:…
#> $ api_url <chr> "https://api.github.com", "https://api.github.com", "…
#> $ repo_url <chr> "https://github.com/r-world-devs/GitStats", "https://…
#> $ api_url <chr> "https://api.github.com/repositories/r-world-devs/Git…
#> $ contributors <chr> "maciekbanas, Cotau", "krystian8207", "krystian8207, …

get_commits(git_stats,
date_from = "2022-01-01",
date_until = "2023-03-31"
)
#> Rows: 304
#> Rows: 553
#> Columns: 8
#> $ id <chr> "C_kwDOHNMr29oAKGFjZWNlMDA5ZDNiMWQ2MWY1OWJhZGVlNmNmMzg2
#> $ committed_date <dttm> 2022-05-23 15:00:08, 2022-05-18 07:32:23, 2023-03-01 1…
#> $ author <chr> "Adam Forys", "Adam Forys", "Krystian Igras", "Krystian
#> $ additions <int> 1, 33, 296, 18, 10, 29, 8, 17, 1, 11, 267, 876, 1, 6, 3…
#> $ deletions <int> 1, 6, 153, 11, 7, 14, 4, 8, 1, 5, 146, 146, 1, 4, 3, 9,…
#> $ id <chr> "C_kwDOHNMr29oAKGI3ZmRlYTNkNjY0NmM2MmRmMzA0N2Y0NDhkODQy
#> $ committed_date <dttm> 2023-03-01 15:05:10, 2023-03-01 14:58:22, 2023-02-28 1…
#> $ author <chr> "Krystian Igras", "Krystian Igras", "Krystian Igras", "…
#> $ additions <int> 296, 18, 10, 29, 8, 17, 1, 11, 267, 876, 1, 6, 3, 20, 1
#> $ deletions <int> 153, 11, 7, 14, 4, 8, 1, 5, 146, 146, 1, 4, 3, 9, 107,
#> $ repository <chr> "shinyGizmo", "shinyGizmo", "shinyGizmo", "shinyGizmo",…
#> $ organization <chr> "r-world-devs", "r-world-devs", "r-world-devs", "r-worl…
#> $ api_url <chr> "https://api.github.com", "https://api.github.com", "ht…
Expand All @@ -125,39 +124,40 @@ setup(git_stats,
)
#> A <GitStats> object for 2 hosts:
#> Hosts: https://api.github.com, https://gitlab.com/api/v4
#> Organisations: r-world-devs, openpharma, pharmaverse, mbtests
#> Organisations: [4] r-world-devs, openpharma, pharmaverse, mbtests
#> Search preference: phrase
#> Team: RWD (6 members)
#> Team: RWD (5 members)
#> Phrase: shiny
#> Language: <not defined>
#> Repositories output: Rows number: 23
#> Commits output: Since: 2022-01-20 14:57:56; Until: 2023-03-30 14:15:33; Rows number: 304
#> Language: All
#> Repositories output: Rows number: 18
#> Commits output: Since: 2022-01-20 14:57:56; Until: 2023-03-30 14:35:34; Rows number: 553

# now pull repos by default by phrase
get_repos(git_stats)
#> Rows: 3
#> Columns: 13
#> $ id <chr> "495151911", "512764983", "431378047"
#> $ name <chr> "shinyCohortBuilder", "openpharma_ml", "elaborator"
#> $ stars <int> 4, 0, 2
#> $ forks <int> 0, 0, 0
#> $ created_at <dttm> 2022-05-22, 2022-07-11, 2021-11-24
#> $ last_activity_at <drtn> 7.38 days, 1.38 days, 455.38 days
#> $ languages <chr> "R", "Python", "R"
#> $ issues_open <int> 27, 0, 0
#> $ issues_closed <int> 0, 0, 0
#> $ contributors <chr> "krystian8207, galachad", "MathieuCayssol, epijim", "…
#> $ organization <chr> "r-world-devs", "openpharma", "openpharma"
#> $ repo_url <chr> "https://api.github.com/repos/r-world-devs/shinyCohor…
#> $ api_url <chr> "https://api.github.com", "https://api.github.com", "…
#> Rows: 4
#> Columns: 12
#> $ id <chr> "495151911", "586903986", "431378047", "512764983"
#> $ name <chr> "shinyCohortBuilder", "GitStats", "elaborator", "open…
#> $ stars <int> 5, 1, 2, 0
#> $ forks <int> 0, 0, 0, 0
#> $ created_at <dttm> 2022-05-22 19:04:12, 2023-01-09 14:02:20, 2021-11-24 …
#> $ last_activity_at <drtn> 4.30 days, 0.10 days, 567.09 days, 112.08 days
#> $ languages <chr> "R", "R", "R", "Python"
#> $ issues_open <int> 30, 30, 0, 0
#> $ issues_closed <int> 0, 0, 0, 0
#> $ organization <chr> "r-world-devs", "r-world-devs", "openpharma", "openph…
#> $ repo_url <chr> "https://github.com/r-world-devs/shinyCohortBuilder",…
#> $ api_url <chr> "https://api.github.com/repos/r-world-devs/shinyCoho…
```

### Acknowledgement

Special thanks to:

- @Cotau - for reviewing permanently my pull requests and suggesting
more efficient solutions,
- @marcinkowskak - for substantial improvements on plots,
- @kalimu, @galachad, @krystian8207 - for your guidelines at the very
beginning of the project.
- Kamil Koziej @Cotau - for reviewing permanently my pull requests and
suggesting more efficient solutions,
- Karolina Marcinkowska @marcinkowskak - for substantial improvements on
plots,
- Matt Secrest @mattsecrest - for making use of your scripts to apply search feature,
- Kamil Wais @kalimu, Krystian Igraś @krystian8207, Adam Foryś
@galachad - for your guidelines at the very beginning of the project.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/03-EngineRestGitHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

x HTTP 401 Unauthorized.

# `add_commits_stats()` works as expected
# `get_commits_stats()` works as expected

Code
gh_rest_commits_table_with_stats <- test_rest_priv$add_commits_stats(
gh_rest_commits_table_with_stats <- test_rest_priv$get_commits_stats(
commits_table = test_mocker$use("gh_rest_commits_table")[1:5, ])
Message <cliMessage>
i [GitHub][Engine:REST] Pulling commits stats...
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/GitStats.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

Add first your hosts with `set_connection()`.

# GitStats throws error when add_contributors is run with empty repos field
# GitStats throws error when get_repos_contributors is run with empty repos field

You need to pull repos first with `get_repos()`.

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-03-EngineRestGitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ test_that("`prepare_repos_table()` prepares repos table", {
test_mocker$cache(gh_repos_by_phrase_table)
})

test_that("`add_repos_issues()` adds issues to repos table", {
test_that("`get_repos_issues()` adds issues to repos table", {
gh_repos_by_phrase_table <- test_mocker$use("gh_repos_by_phrase_table")

gh_repos_by_phrase_table <- test_rest_priv$add_repos_issues(
gh_repos_by_phrase_table <- test_rest_priv$get_repos_issues(
gh_repos_by_phrase_table
)
expect_gt(
Expand Down Expand Up @@ -195,9 +195,9 @@ test_that("`prepare_commits_table()` prepares commits table (for orgs and for te
test_mocker$cache(gh_rest_commits_table_team)
})

test_that("`add_commits_stats()` works as expected", {
test_that("`get_commits_stats()` works as expected", {
expect_snapshot(
gh_rest_commits_table_with_stats <- test_rest_priv$add_commits_stats(
gh_rest_commits_table_with_stats <- test_rest_priv$get_commits_stats(
commits_table = test_mocker$use("gh_rest_commits_table")[1:5,]
)
)
Expand Down Expand Up @@ -258,7 +258,7 @@ test_that("supportive method for getting commits works", {
)
mockery::stub(
test_rest$get_commits_supportive,
"private$add_commits_stats",
"private$get_commits_stats",
test_mocker$use("gh_rest_commits_table_with_stats")
)
test_settings <- list(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-03-EngineRestGitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ test_that("`prepare_commits_table()` prepares table of commits properly", {
)
})

test_that("`add_repos_issues()` adds issues to repos table", {
test_that("`get_repos_issues()` adds issues to repos table", {
gl_repos_by_phrase_table <- test_mocker$use("gl_repos_by_phrase_table")
gl_repos_by_phrase_table <- test_rest_priv$add_repos_issues(
gl_repos_by_phrase_table <- test_rest_priv$get_repos_issues(
gl_repos_by_phrase_table
)
expect_gt(
Expand Down
Loading

0 comments on commit 667f553

Please sign in to comment.