diff --git a/R/plot_commits_github.R b/R/plot_commits_github.R index 9bb422b..273e80f 100644 --- a/R/plot_commits_github.R +++ b/R/plot_commits_github.R @@ -16,14 +16,17 @@ #' pkgmeta::plot_commits_github(repos_commits) #' } #' -plot_commits_github <- function(repos_commits) { +plot_commits_github <- function(repos_commits) +{ n_commits <- repos_commits %>% dplyr::count(.data$author_login) %>% dplyr::rename(n_commits = .data$n) repos_commits %>% dplyr::left_join(n_commits, by = "author_login") %>% - dplyr::mutate(user = sprintf("%s (n = %d)", .data$author_login, .data$n_commits)) %>% + dplyr::mutate( + user = sprintf("%s (n = %d)", .data$author_login, .data$n_commits) + ) %>% ggplot2::ggplot(ggplot2::aes( x = as.Date(.data$datetime) , y = forcats::fct_reorder(.data$repo, .data$datetime), @@ -39,5 +42,4 @@ plot_commits_github <- function(repos_commits) { y = "Repo", x = "Date" ) - } diff --git a/R/plot_r_releases.R b/R/plot_r_releases.R index 81667b5..3bee9dd 100644 --- a/R/plot_r_releases.R +++ b/R/plot_r_releases.R @@ -9,33 +9,53 @@ #' @examples #' releases <- get_r_releases() #' head(releases) -get_r_releases <- function(releases = rversions::r_versions(dots = TRUE)) { +get_r_releases <- function(releases = rversions::r_versions(dots = TRUE)) +{ releases %>% - tidyr::separate(col = "version", - into = c("major", "minor", "patch"), - sep = "\\.", - remove = FALSE) %>% - dplyr::mutate(patch = dplyr::if_else(is.na(.data$patch), 0L, as.integer(.data$patch)), - major = as.integer(.data$major), - minor = as.integer(.data$minor), - diff.major = .data$major - dplyr::lag(.data$major, n = 1L), - diff.minor = .data$minor - dplyr::lag(.data$minor, n = 1L), - diff.patch = .data$patch - dplyr::lag(.data$patch, n = 1L), - release_type = dplyr::if_else(.data$diff.major > 0, - "Major", - dplyr::if_else(.data$diff.minor > 0, - "Minor", - dplyr::if_else(.data$diff.patch > 0, - "Patch", - "Initial")))) %>% - dplyr::mutate(release_type = dplyr::if_else(is.na(.data$release_type), - "Initial", - .data$release_type), - label = sprintf("v%s (%s): %s", - .data$version, - .data$date, - .data$release_type)) - + tidyr::separate( + col = "version", + into = c("major", "minor", "patch"), + sep = "\\.", + remove = FALSE + ) %>% + dplyr::mutate( + patch = dplyr::if_else( + is.na(.data$patch), + 0L, + as.integer(.data$patch) + ), + major = as.integer(.data$major), + minor = as.integer(.data$minor), + diff.major = .data$major - dplyr::lag(.data$major, n = 1L), + diff.minor = .data$minor - dplyr::lag(.data$minor, n = 1L), + diff.patch = .data$patch - dplyr::lag(.data$patch, n = 1L), + release_type = dplyr::if_else( + .data$diff.major > 0, + "Major", + dplyr::if_else( + .data$diff.minor > 0, + "Minor", + dplyr::if_else( + .data$diff.patch > 0, + "Patch", + "Initial" + ) + ) + ) + ) %>% + dplyr::mutate( + release_type = dplyr::if_else( + is.na(.data$release_type), + "Initial", + .data$release_type + ), + label = sprintf( + "v%s (%s): %s", + .data$version, + .data$date, + .data$release_type + ) + ) } #' Plot R Releases @@ -50,22 +70,28 @@ get_r_releases <- function(releases = rversions::r_versions(dots = TRUE)) { #' \dontrun{ #' plot_r_releases() #' } -plot_r_releases <- function(r_releases = get_r_releases(), - title = "R Releases") { - -g <- r_releases %>% -ggplot2::ggplot(ggplot2::aes_string(x = "date", - y = "major", - col = "release_type", - label = "label")) + -ggplot2::geom_point(ggplot2::aes(alpha = 0.5)) + -ggplot2::theme_bw() + -ggplot2::scale_y_discrete() + -ggplot2::labs(title = title, - x = "Date", - y = "Major Release Version", - color = "Type", - alpha = "") +plot_r_releases <- function( + r_releases = get_r_releases(), + title = "R Releases" +) +{ + g <- r_releases %>% + ggplot2::ggplot(ggplot2::aes_string( + x = "date", + y = "major", + col = "release_type", + label = "label" + )) + + ggplot2::geom_point(ggplot2::aes(alpha = 0.5)) + + ggplot2::theme_bw() + + ggplot2::scale_y_discrete() + + ggplot2::labs( + title = title, + x = "Date", + y = "Major Release Version", + color = "Type", + alpha = "" + ) -plotly::ggplotly(g, tooltip = "label") + plotly::ggplotly(g, tooltip = "label") } diff --git a/R/plot_rpackages.R b/R/plot_rpackages.R index 344550f..84422d0 100644 --- a/R/plot_rpackages.R +++ b/R/plot_rpackages.R @@ -16,14 +16,19 @@ #' pkgs <- get_github_packages() #' plot_github_pkgs_over_time(pkgs)} #' -plot_github_pkgs_over_time <- function(df_pkgs, - last_update = Sys.time()) { - fakin_date_start <- lubridate::as_datetime("2017-05-01") +plot_github_pkgs_over_time <- function( + df_pkgs, + last_update = Sys.time() +) +{ + as_date <- lubridate::as_datetime + + fakin_date_start <- as_date("2017-05-01") df_pkgs %>% dplyr::mutate( - created_at = lubridate::as_datetime(.data$created_at), - pushed_at = lubridate::as_datetime(.data$pushed_at) + created_at = as_date(.data$created_at), + pushed_at = as_date(.data$pushed_at) ) %>% ggplot2::ggplot(ggplot2::aes( x = .data$created_at, @@ -33,9 +38,11 @@ plot_github_pkgs_over_time <- function(df_pkgs, xintercept = fakin_date_start, size = 2, alpha = 0.5, col = "grey" ) + - ggplot2::geom_segment(ggplot2::aes(yend = .data$name, xend = .data$pushed_at), + ggplot2::geom_segment( + ggplot2::aes(yend = .data$name, xend = .data$pushed_at), size = 1.3, - arrow = ggplot2::arrow(length = ggplot2::unit(0.1, "inches")) + arrow = ggplot2::arrow(length = ggplot2::unit(0.1, "inches") + ) ) + ggplot2::theme_bw() + ggplot2::labs( @@ -43,9 +50,12 @@ plot_github_pkgs_over_time <- function(df_pkgs, subtitle = glue::glue("Last update: {last_update}"), y = "Repository Name", x = "Date", - caption = glue::glue("Start of the arrow is the first release on Github, while the end of the arrow -represents the lasted 'push' activity to the repository. The vertical grey line -stands for the start date ({fakin_date_start}) of the FAKIN project at KWB which -serves as a booster of this publishing process (last update: {last_update}") + caption = glue::glue(paste0( + "Start of the arrow is the first release on Github, while the end of ", + "the arrow represents the lasted 'push' activity to the repository. ", + "The vertical grey line stands for the start date ", + "({fakin_date_start}) of the FAKIN project at KWB which serves as a ", + "booster of this publishing process (last update: {last_update})" + )) ) } diff --git a/R/plot_rpackages_releases.R b/R/plot_rpackages_releases.R index ac291d1..65b0576 100644 --- a/R/plot_rpackages_releases.R +++ b/R/plot_rpackages_releases.R @@ -18,8 +18,11 @@ #' plot_github_pkgs_releases(pkgs_releases) #' } #' -plot_github_pkgs_releases <- function(pkgs_releases, - last_update = Sys.time()) { +plot_github_pkgs_releases <- function( + pkgs_releases, + last_update = Sys.time() +) +{ # fakin_date_start <- lubridate::as_date("2017-05-01") pkgs_releases %>% diff --git a/R/travis_pkg_install_script.R b/R/travis_pkg_install_script.R index 480bd66..b596ad2 100644 --- a/R/travis_pkg_install_script.R +++ b/R/travis_pkg_install_script.R @@ -1,18 +1,17 @@ #' Travis Package Install Script +#' #' @description Needs to be Run before rendering vignettes #' @param pkgs dataframe with R packages as retrieved by #' get_github_packages() #' @return installs kwb-r packages #' @export -travis_pkg_install_script <- function(pkgs = pkgmeta::get_github_packages()) { - sapply( - pkgs$full_name, - FUN = function(pkg) { - try(remotes::install_github( - repo = pkg, - dependencies = TRUE, - upgrade = "always" - )) - } - ) +travis_pkg_install_script <- function(pkgs = pkgmeta::get_github_packages()) +{ + sapply(pkgs$full_name, function(pkg) { + try(remotes::install_github( + repo = pkg, + dependencies = TRUE, + upgrade = "always" + )) + }) } diff --git a/R/write_github_repos_json.R b/R/write_github_repos_json.R index de3da8d..69eac0a 100644 --- a/R/write_github_repos_json.R +++ b/R/write_github_repos_json.R @@ -6,45 +6,46 @@ #' @importFrom tibble tibble #' @importFrom dplyr bind_rows #' -get_github_topics <- function(full_names = get_github_full_names()) { +get_github_topics <- function(full_names = get_github_full_names()) +{ + repos <- lapply(full_names, function(full_name) { - - repos <- lapply(full_names, FUN = function(full_name) { topics <- try(silent = TRUE, gh::gh( - endpoint = "GET /repos/:full_name/topics", - full_name = full_name, - .send_headers = c(Accept = "application/vnd.github.mercy-preview+json") - )) - - if (! inherits(topics, "try-error")) { + endpoint = "GET /repos/:full_name/topics", + full_name = full_name, + .send_headers = c(Accept = "application/vnd.github.mercy-preview+json") + )) + + na_entry <- tibble::tibble( + full_name = full_name, + topics = NA_character_ + ) + + if (inherits(topics, "try-error")) { + return(na_entry) + } topics_vector <- unlist(topics$names) - if(length(topics_vector) > 0) { - - tibble::tibble(full_name = full_name, - topics = topics_vector) - } else { - tibble::tibble(full_name = full_name, - topics = NA_character_) + if (length(topics_vector) == 0L) { + return(na_entry) } - } else { - - tibble::tibble(full_name = full_name, - topics = NA_character_) - } + tibble::tibble( + full_name = full_name, + topics = topics_vector + ) }) dplyr::bind_rows(repos) - } #' @keywords internal #' @noRd #' -get_github_full_names <- function(github_repos = get_github_repos()) { +get_github_full_names <- function(github_repos = get_github_repos()) +{ vapply(github_repos, "[[", "", "full_name") } @@ -57,23 +58,26 @@ get_github_full_names <- function(github_repos = get_github_repos()) { #' https://developer.github.com/v3/ (e.g. type = "public") #' @importFrom gh gh #' @export -get_github_repos <- function (group = "KWB-R", - github_token = Sys.getenv("GITHUB_PAT"), - dbg = TRUE, - ...) { - - msg <- sprintf(paste("\nFetching Github metadata for", - "repos of organisation '%s' at '%s'"), - group, - sprintf("https://github.com/%s/", group)) - - kwb.utils::catAndRun(msg, - expr = { - gh_repos <- gh::gh(endpoint = sprintf("GET /orgs/%s/repos?per_page=100", - group), .token = github_token, - ...)}, - dbg = dbg) - +get_github_repos <- function ( + group = "KWB-R", + github_token = Sys.getenv("GITHUB_PAT"), + dbg = TRUE, + ... +) +{ + kwb.utils::catAndRun( + messageText = sprintf( + "\nFetching Github metadata for repos of organisation '%s' at '%s'", + group, + sprintf("https://github.com/%s/", group) + ), + dbg = dbg, + expr = gh::gh( + endpoint = sprintf("GET /orgs/%s/repos?per_page=100", group), + .token = github_token, + ... + ) + ) } #' Write Github Metadata to JSON @@ -87,29 +91,27 @@ get_github_repos <- function (group = "KWB-R", #' @importFrom jsonlite toJSON write_json #' @importFrom kwb.utils catAndRun #' @export -write_github_repos_json <- function(github_repos = get_github_repos(), - file = file.path(getwd(), "github.json"), - dbg = TRUE) { - - - repo_html_url <- vapply(github_repos, "[[", "", "html_url") - repo_html_url <- repo_html_url[order(repo_html_url)] - repo_names <- vapply(github_repos, "[[", "", "name") - repo_names <- repo_names[order(repo_names)] - - n_repos <- length(repo_names) +write_github_repos_json <- function( + github_repos = get_github_repos(), + file = file.path(getwd(), "github.json"), + dbg = TRUE +) +{ + fetch_sorted <- function(what) { + sort(vapply(github_repos, "[[", "", what)) + } - kwb.utils::catAndRun(sprintf("Writting '%s' file for %d repos:\n%s", - file, - n_repos, - paste0("- ", - repo_names, - ": ", - repo_html_url, - collapse = "\n")), - expr = { - jsonlite::write_json(github_repos, file) - }, - dbg = dbg + repo_html_url <- fetch_sorted(what = "html_url") + repo_names <- fetch_sorted(what = "name") + + kwb.utils::catAndRun( + sprintf( + "Writting '%s' file for %d repos:\n%s", + file, + length(repo_names), + paste0("- ", repo_names, ": ", repo_html_url, collapse = "\n") + ), + expr = jsonlite::write_json(github_repos, file), + dbg = dbg ) } diff --git a/R/write_pkg_codemeta_json.R b/R/write_pkg_codemeta_json.R index 1e0f959..7d6986e 100644 --- a/R/write_pkg_codemeta_json.R +++ b/R/write_pkg_codemeta_json.R @@ -9,17 +9,20 @@ #' @importFrom jsonlite write_json #' @importFrom kwb.utils catAndRun #' @export -write_pkg_codemeta_json <- function(codemeta = create_pkg_codemeta(), - file = file.path(getwd(), "codemetar.json"), - dbg = TRUE) { - kwb.utils::catAndRun(sprintf("Writting codemeta to '%s'", file), - expr = { - jsonlite::write_json(codemeta, file, - useBytes = TRUE, - pretty = TRUE, - auto_unbox = TRUE - ) - }, - dbg = dbg +write_pkg_codemeta_json <- function( + codemeta = create_pkg_codemeta(), + file = file.path(getwd(), "codemetar.json"), + dbg = TRUE +) +{ + kwb.utils::catAndRun( + sprintf("Writting codemeta to '%s'", file), + dbg = dbg, + expr = jsonlite::write_json( + codemeta, file, + useBytes = TRUE, + pretty = TRUE, + auto_unbox = TRUE + ) ) }