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

506 fix gitstats storage #511

Merged
merged 17 commits into from
Oct 18, 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
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
branches: [devel, test, master]

name: R-CMD-check
name: 👮 R-CMD-check

jobs:
R-CMD-check:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 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

name: lint
on:
push:
branches: [master]
pull_request:
branches: [devel, test, master]

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
branches: [devel, test, master]

name: test-coverage
name: 🧪 Test coverage

jobs:
test-coverage:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ⬆️ Check Version Bump

on:
pull_request:
paths:
- DESCRIPTION

jobs:
check-version:
runs-on: ubuntu-latest

steps:
- name: Checkout source branch
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
path: source

- name: Checkout target branch
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: target

- name: Compare versions
id: compare_versions
run: |
SOURCE_VERSION=$(awk '/^Version:/ { print $2 }' source/DESCRIPTION)
TARGET_VERSION=$(awk '/^Version:/ { print $2 }' target/DESCRIPTION)
echo "Source package version: $SOURCE_VERSION"
echo "Target package version: $TARGET_VERSION"

if [ "$SOURCE_VERSION" == "$TARGET_VERSION" ]; then
echo "Versions are identical"
echo "::set-output name=versions_identical::true"
else
echo "Versions differ"
echo "::set-output name=versions_identical::false"
fi

- name: Fail if versions are identical
if: steps.compare_versions.outputs.versions_identical == 'true'
run: |
echo "The package versions are identical between the source and target branches."
exit 1
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.1.0.9005
Version: 2.1.0.9006
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(get_files_structure)
export(get_release_logs)
export(get_repos)
export(get_repos_urls)
export(get_storage)
export(get_users)
export(set_github_host)
export(set_gitlab_host)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- on the other hand, output of the function has been limited to contain only most necessary data (removing all repository stats), making thus process of obtaining package usage faster ([#474](https://github.com/r-world-devs/GitStats/issues/474)).
- new `split_output` parameter has been added - when set to `TRUE` a `list` with `tibbles` (every element of the `list` for every package) instead of one `tibble` is returned.
- Added possibility to get repositories for individual users with `get_repos()` ([#492](https://github.com/r-world-devs/GitStats/issues/492)). Earlier this was only possible for GitHub organizations and GitLab groups.
- Added new `get_storage()` function to retrieve data from `GitStats` object - whole or particular datasets (e.g. `commits`, `repositories` or `R_package_usage`) ([#509](https://github.com/r-world-devs/GitStats/issues/509)).

## Fixes:

Expand Down
3 changes: 0 additions & 3 deletions R/GitHost.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ GitHost <- R6::R6Class(
cli::cli_alert_info("[{private$host_name}][Engine:{cli::col_yellow('GraphQL')}] Pulling all organizations...")
private$orgs <- private$engines$graphql$get_orgs()
}
if (is.null(until)) {
until <- Sys.time()
}
commits_table <- private$get_commits_from_orgs(
since = since,
until = until,
Expand Down
36 changes: 22 additions & 14 deletions R/GitStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ GitStats <- R6::R6Class(
verbose = TRUE,
progress = TRUE) {
private$check_for_host()
args_list <- list("since" = since,
"until" = until)
args_list <- list("date_range" = c(since, as.character(until)))
trigger <- private$trigger_pulling(
cache = cache,
storage = "commits",
Expand All @@ -226,7 +225,9 @@ GitStats <- R6::R6Class(
class = "commits_data",
attr_list = args_list
)
private$save_to_storage(commits)
private$save_to_storage(
table = commits
)
} else {
commits <- private$get_from_storage(
table = "commits",
Expand Down Expand Up @@ -412,15 +413,12 @@ GitStats <- R6::R6Class(
#' @param progress A logical, by default set to `verbose` value. If `FALSE`
#' no `cli` progress bar will be displayed.
get_release_logs = function(since,
until,
until = Sys.Date(),
cache = TRUE,
verbose = TRUE,
progress = TRUE) {
private$check_for_host()
args_list <- list(
"since" = since,
"until" = until
)
args_list <- list("date_range" = c(since, as.character(until)))
trigger <- private$trigger_pulling(
storage = "release_logs",
cache = cache,
Expand Down Expand Up @@ -527,6 +525,14 @@ GitStats <- R6::R6Class(
private$settings$verbose
},

get_storage = function(storage) {
if (is.null(storage)) {
private$storage
} else {
private$storage[[storage]]
}
},

#' @description A print method for a GitStats object.
print = function() {
cat(paste0("A ", cli::col_blue('GitStats'), " object for ", length(private$hosts), " hosts: \n"))
Expand Down Expand Up @@ -1242,24 +1248,26 @@ GitStats <- R6::R6Class(
},

# print storage attribute
print_storage_attribute = function(storage_table, storage_name) {
print_storage_attribute = function(storage_data, storage_name) {
if (storage_name != "repositories") {
storage_attr <- switch(storage_name,
"repos_urls" = "type",
"files" = "file_path",
"files_structure" = "pattern",
"commits" = "dates_range",
"release_logs" = "dates_range",
"commits" = "date_range",
"release_logs" = "date_range",
"users" = "logins",
"R_package_usage" = "packages")
attr_data <- attr(storage_table, storage_attr)
attr_data <- attr(storage_data, storage_attr)
attr_name <- switch(storage_attr,
"type" = "type",
"file_path" = "files",
"pattern" = "files matching pattern",
"dates_range" = "date range",
"date_range" = "date range",
"packages" = "packages",
"logins" = "logins")
if (length(attr_data) > 1) {
separator <- if (storage_attr == "dates_range") {
separator <- if (storage_attr == "date_range") {
" - "
} else {
", "
Expand Down
37 changes: 35 additions & 2 deletions R/gitstats_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ get_repos_urls <- function(gitstats_object,
#' @export
get_commits <- function(gitstats_object,
since = NULL,
until = NULL,
until = Sys.Date() + lubridate::days(1),
cache = TRUE,
verbose = is_verbose(gitstats_object),
progress = verbose) {
Expand Down Expand Up @@ -501,7 +501,7 @@ get_R_package_usage <- function(gitstats_object,
#' @export
get_release_logs <- function(gitstats_object,
since = NULL,
until = NULL,
until = Sys.Date() + lubridate::days(1),
cache = TRUE,
verbose = is_verbose(gitstats_object),
progress = verbose) {
Expand Down Expand Up @@ -557,3 +557,36 @@ verbose_off <- function(gitstats_object) {
is_verbose <- function(gitstats_object) {
gitstats_object$is_verbose()
}

#' @title Get data from `GitStats` storage
maciekbanas marked this conversation as resolved.
Show resolved Hide resolved
#' @name get_storage
#' @description Retrieves whole or particular data (see `storage` parameter)
#' pulled earlier with `GitStats`.
#' @param gitstats_object A GitStats object.
#' @param storage A character, type of the data you want to get from storage:
#' `commits`, `repositories`, `release_logs`, `users`, `files`,
#' `files_structure`, `R_package_usage` or `release_logs`.
#' @return A list of tibbles (if `storage` set to `NULL`) or a tibble (if
#' `storage` defined).
#' @examples
#' \dontrun{
#' my_gitstats <- create_gitstats() %>%
#' set_github_host(
#' token = Sys.getenv("GITHUB_PAT"),
#' orgs = c("r-world-devs", "openpharma")
#' )
#' get_release_logs(my_gistats, since = "2024-01-01")
#' get_repos(my_gitstats)
#'
#' release_logs <- get_storage(
#' gitstats_object = my_gitstats,
#' storage = "release_logs"
#' )
#' }
#' @export
get_storage <- function(gitstats_object,
storage = NULL) {
gitstats_object$get_storage(
storage = storage
)
}
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ articles:
navbar: ~
contents:
- set_hosts
- get_data
- get_and_store_data
- get_repos_with_code
- get_files

2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ plotly
repo
repos
regex
tibble
tibbles
30 changes: 30 additions & 0 deletions inst/get_commits_workflow.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
devtools::load_all(".")

git_stats <- create_gitstats() %>%
set_github_host(
orgs = c("r-world-devs", "openpharma"),
token = Sys.getenv("GITHUB_PAT")
) %>%
set_gitlab_host(
orgs = c("mbtests"),
token = Sys.getenv("GITLAB_PAT_PUBLIC")
)

release_logs <- get_release_logs(
gitstats_object = git_stats,
since = "2024-01-01",
verbose = FALSE
)

release_logs

# Check printing in storage
test_gitstats

get_commits(
git_stats,
since = "2024-01-01"
)

# Check printing in storage
test_gitstats
8 changes: 8 additions & 0 deletions inst/get_repos_urls_workflow.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
devtools::load_all(".")

test_gitstats <- create_gitstats() |>
set_github_host(
orgs = c("r-world-devs", "openpharma")
)

get_repos_urls(test_gitstats, with_code = "shiny")
32 changes: 32 additions & 0 deletions inst/get_storage_workflow.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
devtools::load_all(".")

git_stats <- create_gitstats() %>%
set_github_host(
orgs = c("r-world-devs", "openpharma"),
token = Sys.getenv("GITHUB_PAT")
)

release_logs <- get_release_logs(
gitstats_object = git_stats,
since = "2024-01-01"
)

repos_urls <- get_repos_urls(
gitstats_object = git_stats,
with_code = "shiny"
)

files_structure <- get_files_structure(
gitstats_object = git_stats,
pattern = "\\.md",
depth = 1L
)

git_stats

get_storage(git_stats)

get_storage(git_stats, "commits")
get_storage(git_stats, "repos_urls")
get_storage(git_stats, "release_logs")
get_storage(git_stats, "files_structure")
2 changes: 1 addition & 1 deletion man/get_commits.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_release_logs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading