Skip to content

Commit

Permalink
Merge pull request #574 from r-world-devs/567-prettify
Browse files Browse the repository at this point in the history
Prettify
  • Loading branch information
maciekbanas authored Jan 10, 2025
2 parents a7ae9ed + 85d9fdd commit 4b177c3
Show file tree
Hide file tree
Showing 28 changed files with 429 additions and 173 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GitStats
Title: Standardized Git Repository Data
Version: 2.1.2.9008
Version: 2.2.0
Authors@R: c(
person(given = "Maciej", family = "Banas", email = "banasmaciek@gmail.com", role = c("aut", "cre")),
person(given = "Kamil", family = "Koziej", email = "koziej.k@gmail.com", role = "aut"),
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# GitStats (development version)
# GitStats 2.2.0

This release brings some substantial improvements with making it possible to scan whole organizations and particular repositories for one host at the same time, boosting function to prepare commits statistics and simplifying workflow for getting files.

## Features:

Expand All @@ -9,7 +11,7 @@
- adding `yearly` aggregation to `time_aggregation` parameter,
- changing basic input from `GitStats` to `commits_data` object which allows to build workflow in one pipeline (`create_gitstats() |> set_*_host() |> get_commits() |> get_commits_stats()`).
- Merged two functions `get_files_content()` and `get_files_structure()` into one `get_files()` ([#564](https://github.com/r-world-devs/GitStats/issues/564)).
- Add `.show_error` parameter to the `set_*_host()` functions to control if error should pop up when wrong input is passed ([#547](https://github.com/r-world-devs/GitStats/issues/547)).
- Add `.error` parameter to the `set_*_host()` functions to control if error should pop up when wrong input is passed ([#547](https://github.com/r-world-devs/GitStats/issues/547)).

## Fixes:

Expand Down
78 changes: 42 additions & 36 deletions R/EngineGraphQLGitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ EngineGraphQLGitHub <- R6::R6Class(
initialize = function(gql_api_url,
token,
scan_all = FALSE) {
super$initialize(gql_api_url = gql_api_url,
token = token,
scan_all = scan_all)
super$initialize(
gql_api_url = gql_api_url,
token = token,
scan_all = scan_all
)
self$gql_query <- GQLQueryGitHub$new()
},

Expand Down Expand Up @@ -53,7 +55,7 @@ EngineGraphQLGitHub <- R6::R6Class(
response$errors[[1]]$message
)
}
orgs_list <- purrr::map(response$data$search$edges, ~stringr::str_match(.$node$url, "[^\\/]*$"))
orgs_list <- purrr::map(response$data$search$edges, ~ stringr::str_match(.$node$url, "[^\\/]*$"))

Check warning on line 58 in R/EngineGraphQLGitHub.R

View check run for this annotation

Codecov / codecov/patch

R/EngineGraphQLGitHub.R#L58

Added line #L58 was not covered by tests
full_orgs_list <- append(full_orgs_list, orgs_list)
has_next_page <- response$data$search$pageInfo$hasNextPage
end_cursor <- response$data$search$pageInfo$endCursor
Expand Down Expand Up @@ -98,7 +100,7 @@ EngineGraphQLGitHub <- R6::R6Class(
prepare_repos_table = function(repos_list, org) {
if (length(repos_list) > 0) {
repos_table <- purrr::map(repos_list, function(repo) {
repo$default_branch <- if (!is.null(repo$default_branch)) {
repo[["default_branch"]] <- if (!is.null(repo$default_branch)) {
repo$default_branch$name
} else {
""
Expand All @@ -107,13 +109,13 @@ EngineGraphQLGitHub <- R6::R6Class(
if (length(last_activity_at) == 0) {
last_activity_at <- gts_to_posixt(repo$created_at)
}
repo$languages <- purrr::map_chr(repo$languages$nodes, ~ .$name) %>%
repo[["languages"]] <- purrr::map_chr(repo$languages$nodes, ~ .$name) |>
paste0(collapse = ", ")
repo$created_at <- gts_to_posixt(repo$created_at)
repo$issues_open <- repo$issues_open$totalCount
repo$issues_closed <- repo$issues_closed$totalCount
repo$last_activity_at <- last_activity_at
repo$organization <- repo$organization$login
repo[["created_at"]] <- gts_to_posixt(repo$created_at)
repo[["issues_open"]] <- repo$issues_open$totalCount
repo[["issues_closed"]] <- repo$issues_closed$totalCount
repo[["last_activity_at"]] <- last_activity_at
repo[["organization"]] <- repo$organization$login
repo <- data.frame(repo) %>%
dplyr::relocate(
default_branch,
Expand Down Expand Up @@ -200,7 +202,7 @@ EngineGraphQLGitHub <- R6::R6Class(
repos,
file_paths = NULL,
host_files_structure = NULL,
verbose = TRUE,
verbose = TRUE,
progress = TRUE) {
repo_data <- private$get_repos_data(
org = org,
Expand Down Expand Up @@ -265,11 +267,11 @@ EngineGraphQLGitHub <- R6::R6Class(
def_branches <- repo_data[["def_branches"]]
files_structure <- purrr::map2(repositories, def_branches, function(repo, def_branch) {
private$get_files_structure_from_repo(
org = org,
repo = repo,
org = org,
repo = repo,
def_branch = def_branch,
pattern = pattern,
depth = depth
pattern = pattern,
depth = depth
)
}, .progress = progress)
names(files_structure) <- repositories
Expand All @@ -293,7 +295,8 @@ EngineGraphQLGitHub <- R6::R6Class(
user_data[["web_url"]] <- user_data$web_url %||% ""
user_table <- tibble::as_tibble(user_data) %>%
dplyr::relocate(c(commits, issues, pull_requests, reviews),
.after = starred_repos)
.after = starred_repos
)
} else {
user_table <- NULL
}
Expand Down Expand Up @@ -431,27 +434,30 @@ EngineGraphQLGitHub <- R6::R6Class(
commits_by_org_query <- self$gql_query$commits_from_repo(
commits_cursor = commits_cursor
)
response <- tryCatch({
self$gql_response(
gql_query = commits_by_org_query,
vars = list(
"org" = org,
"repo" = repo,
"since" = date_to_gts(since),
"until" = date_to_gts(until)
response <- tryCatch(
{
self$gql_response(
gql_query = commits_by_org_query,
vars = list(
"org" = org,
"repo" = repo,
"since" = date_to_gts(since),
"until" = date_to_gts(until)
)
)
)
}, error = function(e) {
self$gql_response(
gql_query = commits_by_org_query,
vars = list(
"org" = org,
"repo" = repo,
"since" = date_to_gts(since),
"until" = date_to_gts(until)
},
error = function(e) {
self$gql_response(
gql_query = commits_by_org_query,
vars = list(
"org" = org,
"repo" = repo,
"since" = date_to_gts(since),
"until" = date_to_gts(until)

Check warning on line 456 in R/EngineGraphQLGitHub.R

View check run for this annotation

Codecov / codecov/patch

R/EngineGraphQLGitHub.R#L450-L456

Added lines #L450 - L456 were not covered by tests
)
)
)
})
}
)
return(response)
},

Expand Down
32 changes: 17 additions & 15 deletions R/EngineGraphQLGitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ EngineGraphQLGitLab <- R6::R6Class(
response <- self$gql_response(
gql_query = user_or_org_query,
vars = list(
"username" = owner,
"username" = owner,
"grouppath" = owner
)
)
Expand Down Expand Up @@ -352,10 +352,10 @@ EngineGraphQLGitLab <- R6::R6Class(
repositories <- repo_data[["repositories"]]
files_structure <- purrr::map(repositories, function(repo) {
private$get_files_structure_from_repo(
org = org,
repo = repo,
org = org,
repo = repo,
pattern = pattern,
depth = depth
depth = depth
)
}, .progress = progress)
names(files_structure) <- repositories
Expand All @@ -367,18 +367,20 @@ EngineGraphQLGitLab <- R6::R6Class(
prepare_user_table = function(user_response) {
if (!is.null(user_response$data$user)) {
user_data <- user_response$data$user
user_data$name <- user_data$name %||% ""
user_data$starred_repos <- user_data$starred_repos$count
user_data$pull_requests <- user_data$pull_requests$count
user_data$reviews <- user_data$reviews$count
user_data$email <- user_data$email %||% ""
user_data$location <- user_data$location %||% ""
user_data$web_url <- user_data$web_url %||% ""
user_table <- tibble::as_tibble(user_data) %>%
user_data[["name"]] <- user_data$name %||% ""
user_data[["starred_repos"]] <- user_data$starred_repos$count
user_data[["pull_requests"]] <- user_data$pull_requests$count
user_data[["reviews"]] <- user_data$reviews$count
user_data[["email"]] <- user_data$email %||% ""
user_data[["location"]] <- user_data$location %||% ""
user_data[["web_url"]] <- user_data$web_url %||% ""
user_table <- tibble::as_tibble(user_data) |>
dplyr::mutate(commits = NA,
issues = NA) %>%
dplyr::relocate(c(commits, issues),
.after = starred_repos)
issues = NA) |>
dplyr::relocate(
c(commits, issues),
.after = starred_repos
)
} else {
user_table <- NULL
}
Expand Down
6 changes: 1 addition & 5 deletions R/EngineRestGitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ EngineRestGitHub <- R6::R6Class(
error = function(e) {
NA
})
}, .progress = if (progress) {
"[GitHost:GitHub] Pulling contributors..."
} else {
FALSE
})
}, .progress = progress)
}
return(repos_table)
}
Expand Down
6 changes: 1 addition & 5 deletions R/EngineRestGitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,7 @@ EngineRestGitLab <- R6::R6Class(
NA
})
return(contributors_vec)
}, .progress = if (progress) {
"[GitHost:GitLab] Pulling contributors..."
} else {
FALSE
})
}, .progress = progress)
}
return(repos_table)
},
Expand Down
12 changes: 6 additions & 6 deletions R/GitHost.R
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ GitHost <- R6::R6Class(
}
}
return(org)
}) |>
}, .progress = verbose) |>
purrr::keep(~ length(.) > 0)
if (length(orgs) == 0) {
return(NULL)
Expand Down Expand Up @@ -693,7 +693,7 @@ GitHost <- R6::R6Class(
show_message(
host = private$host_name,
engine = "graphql",
scope = org,
scope = set_repo_scope(org, private),
information = "Pulling repositories"
)
}
Expand Down Expand Up @@ -813,7 +813,7 @@ GitHost <- R6::R6Class(
show_message(
host = private$host_name,
engine = "rest",
scope = org,
scope = paste0(org, "/", private$orgs_repos[[org]], collapse = ", "),
information = "Pulling repositories (URLs)"
)
}
Expand Down Expand Up @@ -1150,7 +1150,7 @@ GitHost <- R6::R6Class(
show_message(
host = private$host_name,
engine = "graphql",
scope = org,
scope = paste0(org, "/", private$orgs_repos[[org]], collapse = ", "),
information = glue::glue("Pulling files content: [{paste0(file_path, collapse = ', ')}]")

Check warning on line 1154 in R/GitHost.R

View check run for this annotation

Codecov / codecov/patch

R/GitHost.R#L1150-L1154

Added lines #L1150 - L1154 were not covered by tests
)
}
Expand Down Expand Up @@ -1280,7 +1280,7 @@ GitHost <- R6::R6Class(
show_message(
host = private$host_name,
engine = "graphql",
scope = org,
scope = paste0(org, "/", private$orgs_repos[[org]], collapse = ", "),
information = user_info

Check warning on line 1284 in R/GitHost.R

View check run for this annotation

Codecov / codecov/patch

R/GitHost.R#L1280-L1284

Added lines #L1280 - L1284 were not covered by tests
)
}
Expand Down Expand Up @@ -1383,7 +1383,7 @@ GitHost <- R6::R6Class(
show_message(
host = private$host_name,
engine = "graphql",
scope = paste0(org, "/", private$orgs_repos[[org]]),
scope = paste0(org, "/", private$orgs_repos[[org]], collapse = ", "),
information = "Pulling release logs"
)
}
Expand Down
Loading

0 comments on commit 4b177c3

Please sign in to comment.