From 59a1ed1da560e334f6993b9dc3676fa39e46f514 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Thu, 14 Sep 2023 12:17:11 +0000 Subject: [PATCH] Update Readme, remove example workflow. Example not needed anymore - Readme covers the examples. --- README.Rmd | 100 +++++++++++++++---- README.md | 209 +++++++++++++++++++++++++++++++-------- devel/example_workflow.R | 151 ---------------------------- 3 files changed, 247 insertions(+), 213 deletions(-) delete mode 100644 devel/example_workflow.R diff --git a/README.Rmd b/README.Rmd index 4816f6f1..fde90109 100644 --- a/README.Rmd +++ b/README.Rmd @@ -43,15 +43,40 @@ library(GitStats) git_stats <- create_gitstats() %>% set_host( api_url = "https://api.github.com", - orgs = c("r-world-devs", "openpharma") + orgs = c("r-world-devs", "openpharma"), + token = Sys.getenv("GITHUB_PAT") ) %>% set_host( api_url = "https://gitlab.com/api/v4", - orgs = c("mbtests") + orgs = c("mbtests"), + token = Sys.getenv("GITLAB_PAT_PUBLIC") ) ``` -## Setup +By default your search preferences are set to `organizations` (`org`). + +```{r} +git_stats + +pull_repos( + git_stats +) + +pull_commits( + git_stats, + date_from = "2023-01-01", + date_until = "2023-03-31" +) +``` + +Finally you can retrieve your repos to separate object. + +```{r} +repos_dt <- get_repos(git_stats) +commits_dt <- get_commits(git_stats) +``` + +## Set You can setup your search preferences, either to `org`, `team` or `phrase`. @@ -60,39 +85,75 @@ You can setup your search preferences, either to `org`, `team` or `phrase`. If you with to setup your search parameter to team, add your team members first: ```{r} + git_stats %>% 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" -) - -# now pull repos and commits by default by team -get_repos(git_stats) - -pull_commits(git_stats, + set_team_member("Maciej Banaś", "maciekbanas") %>% + set_params( + search_param = "team", + team_name = "RWD" + ) %>% + pull_repos() + +pull_commits( + gitstats_obj = git_stats, date_from = "2023-01-01", date_until = "2023-03-31" ) ``` -### Keyword +### Phrase With `GitStats` you can look for the repos with a certain phrase in code blobs. ```{r} -setup(git_stats, +set_params( + gitstats_obj = git_stats, search_param = "phrase", phrase = "shiny" +) %>% + pull_repos() +``` + +### Language + +You can define a programming language in your settings. + +```{r} +set_params( + gitstats_obj = git_stats, + search_param = "org", + language = "JavaScript" +) %>% + pull_repos() +``` + +You can always get back to All languages. + +```{r} +reset_language(git_stats) +``` + +## Users + +You can retrieve data about users with GitStats. + +```{r} +pull_users( + gitstats_obj = git_stats, + users = c("maciekbanas", "kalimu", "Cotau", "marcinkowskak", "@krystian8207") ) +``` + +## Reset your settings -# now pull repos by default by phrase -get_repos(git_stats) +If you wish to get back to default settings, run: + +```{r} +reset(git_stats) ``` ### Acknowledgement @@ -101,6 +162,7 @@ Special thanks to: - Kamil Koziej @Cotau - for reviewing permanently my pull requests and suggesting more efficient solutions, - Karolina Marcinkowska @marcinkowskak - for substantial improvements on plots, +- Krystian Igraś @krystian8207 - for the major review of GitStats and, - 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. +- Kamil Wais @kalimu, Adam Foryś @galachad - for your guidelines at the very beginning of the project. diff --git a/README.md b/README.md index c0ffa8ec..f623e50e 100644 --- a/README.md +++ b/README.md @@ -39,15 +39,73 @@ library(GitStats) git_stats <- create_gitstats() %>% set_host( api_url = "https://api.github.com", - orgs = c("r-world-devs", "openpharma") + orgs = c("r-world-devs", "openpharma"), + token = Sys.getenv("GITHUB_PAT") ) %>% set_host( api_url = "https://gitlab.com/api/v4", - orgs = c("mbtests") + orgs = c("mbtests"), + token = Sys.getenv("GITLAB_PAT_PUBLIC") ) ``` -## Setup +By default your search preferences are set to `organizations` (`org`). + +``` r +git_stats +#> A object for 2 hosts: +#> Hosts: https://api.github.com, https://gitlab.com/api/v4 +#> Organisations: [3] r-world-devs, openpharma, mbtests +#> Search preference: org +#> Team: +#> Phrase: +#> Language: All +#> Repositories output: +#> Commits output: + +pull_repos( + git_stats +) +#> Rows: 65 +#> Columns: 12 +#> $ id "R_kgDOHNMr2w", "R_kgDOHYNOFQ", "R_kgDOHYNrJw", "R_kg… +#> $ name "shinyGizmo", "cohortBuilder", "shinyCohortBuilder", … +#> $ stars 16, 3, 5, 0, 1, 2, 0, 2, 7, 176, 4, 10, 1, 19, 0, 1, … +#> $ forks 0, 2, 0, 0, 0, 0, 0, 0, 4, 31, 1, 1, 0, 4, 1, 1, 0, 0… +#> $ created_at 2022-04-20 10:04:32, 2022-05-22 18:31:55, 2022-05-22… +#> $ last_activity_at 129.51 days, 132.51 days, 17.51 days, 412.51 days, 0… +#> $ languages "R, CSS, JavaScript", "R", "R, CSS, JavaScript, SCSS"… +#> $ issues_open 6, 22, 32, 3, 79, 0, 0, 3, 6, 16, 0, 0, 0, 4, 0, 0, 0… +#> $ issues_closed 12, 1, 4, 0, 115, 0, 0, 0, 1, 167, 0, 0, 0, 16, 0, 0,… +#> $ organization "r-world-devs", "r-world-devs", "r-world-devs", "r-wo… +#> $ repo_url "https://github.com/r-world-devs/shinyGizmo", "https:… +#> $ api_url "https://api.github.com/repositories/r-world-devs/shi… + +pull_commits( + git_stats, + date_from = "2023-01-01", + date_until = "2023-03-31" +) +#> Rows: 798 +#> Columns: 8 +#> $ id "C_kwDOHNMr29oAKGI3ZmRlYTNkNjY0NmM2MmRmMzA0N2Y0NDhkODQy… +#> $ committed_date 2023-03-01 15:05:10, 2023-03-01 14:58:22, 2023-02-28 1… +#> $ author "Krystian Igras", "Krystian Igras", "Krystian Igras", "… +#> $ additions 296, 18, 10, 29, 8, 17, 1, 11, 267, 876, 1, 6, 3, 20, 1… +#> $ deletions 153, 11, 7, 14, 4, 8, 1, 5, 146, 146, 1, 4, 3, 9, 107, … +#> $ repository "shinyGizmo", "shinyGizmo", "shinyGizmo", "shinyGizmo",… +#> $ organization "r-world-devs", "r-world-devs", "r-world-devs", "r-worl… +#> $ api_url "https://api.github.com", "https://api.github.com", "ht… +``` + +Finally you can retrieve your repos to separate object. + +``` r +repos_dt <- get_repos(git_stats) +commits_dt <- get_commits(git_stats) +``` + +## Set You can setup your search preferences, either to `org`, `team` or `phrase`. @@ -58,29 +116,18 @@ If you with to setup your search parameter to team, add your team members first: ``` r + git_stats %>% 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 object for 2 hosts: -#> Hosts: https://api.github.com, https://gitlab.com/api/v4 -#> Organisations: [3] r-world-devs, openpharma, mbtests -#> Search preference: team -#> Team: RWD (5 members) -#> Phrase: -#> Language: All -#> Repositories output: -#> Commits output: - -# now pull repos and commits by default by team -get_repos(git_stats) + set_team_member("Maciej Banaś", "maciekbanas") %>% + set_params( + search_param = "team", + team_name = "RWD" + ) %>% + pull_repos() #> Rows: 18 #> Columns: 13 #> $ id "R_kgDOIvtxsg", "R_kgDOJAtHJA", "R_kgDOHNMr2w", "R_kg… @@ -88,16 +135,17 @@ get_repos(git_stats) #> $ stars 1, 2, 16, 3, 5, 2, 10, 22, 2, 0, 0, 0, 0, 0, 0, 0, 0,… #> $ forks 0, 0, 0, 2, 0, 0, 1, 5, 1, NA, NA, NA, NA, NA, NA, NA… #> $ created_at 2023-01-09 14:02:20, 2023-02-21 16:41:59, 2022-04-20… -#> $ last_activity_at 0.52 days, 124.52 days, 121.52 days, 124.52 days, 9.… +#> $ last_activity_at 0.51 days, 132.51 days, 129.51 days, 132.51 days, 17… #> $ languages "R", "R, CSS", "R, CSS, JavaScript", "R", "R, CSS, Ja… -#> $ issues_open 78, 0, 5, 22, 32, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1,… -#> $ issues_closed 113, 0, 12, 1, 4, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,… +#> $ issues_open 79, 0, 6, 22, 32, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1,… +#> $ issues_closed 115, 0, 12, 1, 4, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,… #> $ organization "r-world-devs", "r-world-devs", "r-world-devs", "r-wo… #> $ repo_url "https://github.com/r-world-devs/GitStats", "https://… #> $ api_url "https://api.github.com/repositories/r-world-devs/Git… #> $ contributors "maciekbanas, Cotau", "krystian8207", "krystian8207, … -pull_commits(git_stats, +pull_commits( + gitstats_obj = git_stats, date_from = "2023-01-01", date_until = "2023-03-31" ) @@ -113,28 +161,18 @@ pull_commits(git_stats, #> $ api_url "https://api.github.com", "https://api.github.com", "ht… ``` -### Keyword +### Phrase With `GitStats` you can look for the repos with a certain phrase in code blobs. ``` r -setup(git_stats, +set_params( + gitstats_obj = git_stats, search_param = "phrase", phrase = "shiny" -) -#> A object for 2 hosts: -#> Hosts: https://api.github.com, https://gitlab.com/api/v4 -#> Organisations: [3] r-world-devs, openpharma, mbtests -#> Search preference: phrase -#> Team: RWD (5 members) -#> Phrase: shiny -#> Language: All -#> Repositories output: Rows number: 18 -#> Commits output: Since: 2023-01-09 14:54:35; Until: 2023-03-30 14:35:34; Rows number: 398 - -# now pull repos by default by phrase -get_repos(git_stats) +) %>% + pull_repos() #> Rows: 4 #> Columns: 12 #> $ id "495151911", "586903986", "431378047", "512764983" @@ -142,7 +180,7 @@ get_repos(git_stats) #> $ stars 5, 1, 2, 0 #> $ forks 0, 0, 0, 0 #> $ created_at 2022-05-22 19:04:12, 2023-01-09 14:02:20, 2021-11-24 … -#> $ last_activity_at 9.18 days, 0.01 days, 571.97 days, 116.97 days +#> $ last_activity_at 17.17 days, 0.00 days, 579.96 days, 124.95 days #> $ languages "R", "R", "R", "Python" #> $ issues_open 30, 30, 0, 0 #> $ issues_closed 0, 0, 0, 0 @@ -151,6 +189,90 @@ get_repos(git_stats) #> $ api_url "https://api.github.com/repos/r-world-devs/shinyCoho… ``` +### Language + +You can define a programming language in your settings. + +``` r +set_params( + gitstats_obj = git_stats, + search_param = "org", + language = "JavaScript" +) %>% + pull_repos() +#> Rows: 6 +#> Columns: 12 +#> $ id "R_kgDOHNMr2w", "R_kgDOHYNrJw", "R_kgDOJWYrCA", "MDEw… +#> $ name "shinyGizmo", "shinyCohortBuilder", "hypothesis", "fa… +#> $ stars 16, 5, 2, 4, 0, 3 +#> $ forks 0, 0, 0, 0, 0, 0 +#> $ created_at 2022-04-20 10:04:32, 2022-05-22 19:04:12, 2023-04-13 … +#> $ last_activity_at 129.51 days, 17.51 days, 57.51 days, 1018.51 days, 44… +#> $ languages "R, CSS, JavaScript", "R, CSS, JavaScript, SCSS", "R… +#> $ issues_open 6, 32, 3, 1, 0, 2 +#> $ issues_closed 12, 4, 0, 0, 0, 2 +#> $ organization "r-world-devs", "r-world-devs", "r-world-devs", "ope… +#> $ repo_url "https://github.com/r-world-devs/shinyGizmo", "https:… +#> $ api_url "https://api.github.com/repositories/r-world-devs/shi… +``` + +You can always get back to All languages. + +``` r +reset_language(git_stats) +#> A object for 2 hosts: +#> Hosts: https://api.github.com, https://gitlab.com/api/v4 +#> Organisations: [3] r-world-devs, openpharma, mbtests +#> Search preference: org +#> Team: RWD (5 members) +#> Phrase: shiny +#> Language: All +#> Repositories output: Rows number: 6 +#> Commits output: Since: 2023-01-09 14:54:35; Until: 2023-03-30 14:35:34; Rows number: 398 +``` + +## Users + +You can retrieve data about users with GitStats. + +``` r +pull_users( + gitstats_obj = git_stats, + users = c("maciekbanas", "kalimu", "Cotau", "marcinkowskak", "@krystian8207") +) +#> Rows: 7 +#> Columns: 12 +#> $ id "MDQ6VXNlcjc0MjEyOTMz", "MDQ6VXNlcjI1MjIyMzY=", "MDQ6VXN… +#> $ name "Maciej Banaś", "Kamil Wais", "", "Karolina Marcinkowska… +#> $ login "maciekbanas", "kalimu", "Cotau", "marcinkowskak", "maci… +#> $ email "", "kamil.wais@gmail.com", "", "", "", "", "" +#> $ location "", "Rzeszów", "", "Warsaw, Poland", "", "", "" +#> $ starred_repos 15, 80, 1, 0, 0, 0, 0 +#> $ commits 435, 0, 1, 0, NA, NA, NA +#> $ issues 201, 0, 2, 1, NA, NA, NA +#> $ pull_requests 98, 1, 6, 2, 1, 0, 0 +#> $ reviews 4, 0, 27, 12, 0, 0, 0 +#> $ avatar_url "https://avatars.githubusercontent.com/u/74212933?u=f85d… +#> $ web_url "", "kalimu.github.io", "", "", "https://gitlab.com/maci… +``` + +## Reset your settings + +If you wish to get back to default settings, run: + +``` r +reset(git_stats) +#> A object for 2 hosts: +#> Hosts: https://api.github.com, https://gitlab.com/api/v4 +#> Organisations: [3] r-world-devs, openpharma, mbtests +#> Search preference: org +#> Team: +#> Phrase: +#> Language: All +#> Repositories output: Rows number: 6 +#> Commits output: Since: 2023-01-09 14:54:35; Until: 2023-03-30 14:35:34; Rows number: 398 +``` + ### Acknowledgement Special thanks to: @@ -159,7 +281,8 @@ Special thanks to: suggesting more efficient solutions, - Karolina Marcinkowska @marcinkowskak - for substantial improvements on plots, +- Krystian Igraś @krystian8207 - for the major review of GitStats and, - 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. +- Kamil Wais @kalimu, Adam Foryś @galachad - for your guidelines at the + very beginning of the project. diff --git a/devel/example_workflow.R b/devel/example_workflow.R deleted file mode 100644 index d2c44e42..00000000 --- a/devel/example_workflow.R +++ /dev/null @@ -1,151 +0,0 @@ -#file with example workflow for basic package functionality - will be helpful later tu build vignettes -pkgload::load_all() - -# Start by creating your GitStats object and setting connections. -git_stats <- create_gitstats() %>% - set_host( - api_url = "https://api.github.com", - orgs = c("r-world-devs", "openpharma") - ) %>% - set_host( - api_url = "https://gitlab.com/api/v4", - orgs = c("mbtests", "gitlab-org") - ) - -git_stats - -# examples for getting repos (default search parameter is 'org') -pull_repos(git_stats) -pull_repos_contributors(git_stats) -dplyr::glimpse(get_repos(git_stats)) - -pull_repos(git_stats, add_contributors = TRUE) - -pull_commits(git_stats, date_from = "2022-01-01") - -# setup your language you are interested in -set_params( - git_stats, - language = "Python" -) -pull_repos(git_stats) - -# set your team members -git_stats %>% - set_team_member("Adam Foryś", "galachad") %>% - 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") - -# You can set your search preferences -set_params( - git_stats, - search_param = "team", - team_name = "RWD", - language = "R" -) - -# now pull repos by default by team -pull_repos(git_stats) -get_repos(git_stats) -pull_commits(git_stats, date_from = "2020-01-01") - -reset_language(git_stats) - -# Change your settings to searches by phrase: -set_params( - git_stats, - search_param = "phrase", - phrase = "shiny" -) - -# Search by phrase -pull_repos(git_stats) - -# you can plot repos sorted by last activity -plot_repos(git_stats) - -# error should pop out when search param set to 'phrase': -pull_commits(git_stats, date_from = "2020-01-01") - -reset(git_stats) - -# now it should work -pull_commits(git_stats, date_from = "2020-01-01") - -# examples for plotting commits -plot_commits(git_stats) - -# get information on users -git_stats %>% - pull_users(c("maciekbanas", "kalimu", "marcinkowskak", "Cotau", "krystian8207")) -git_stats$get_users() - -# SHOWCASES - -# throws sometimes 502 Bad Gateway error (GraphQL one) -# should switch to REST if that is the case - -create_gitstats() %>% - set_host( - api_url = "https://api.github.com", - token = Sys.getenv("GITHUB_PAT"), - orgs = c("insightsengineering") - ) %>% get_repos() - -# one token does not exist - -git_stats <- create_gitstats() %>% - set_host( - api_url = "https://api.github.com", - token = Sys.getenv("DOES_NOT_EXIST"), - orgs = c("r-world-devs", "openpharma") - ) %>% - set_host( - api_url = "https://gitlab.com/api/v4", - token = Sys.getenv("GITLAB_PAT_PUBLIC"), - orgs = c("mbtests", "erasmusmc-public-health") - ) -git_stats - -# a token exists but does not grant access - -git_stats <- create_gitstats() %>% - set_host( - api_url = "https://api.github.com", - token = Sys.getenv("GITHUB_PAT"), - orgs = c("r-world-devs", "openpharma") - ) %>% - set_host( - api_url = "https://gitlab.com/api/v4", - token = Sys.getenv("GITLAB_PAT"), - orgs = c("mbtests", "erasmusmc-public-health") - ) -git_stats - -# wrong orgs - -git_stats <- create_gitstats() %>% - set_host( - api_url = "https://api.github.com", - token = Sys.getenv("GITHUB_PAT"), - orgs = c("rworlddevs", "openpharma") - ) %>% - set_host( - api_url = "https://gitlab.com/api/v4", - token = Sys.getenv("GITLAB_PAT_PUBLIC"), - orgs = c("mbtests", "public health") - ) -git_stats - -## add gitlab subgroups - -git_stats <- create_gitstats() %>% - set_host( - api_url = "https://gitlab.com/api/v4", - token = Sys.getenv("GITLAB_PAT_PUBLIC"), - orgs = "mbtests/subgroup" - ) -git_stats