Skip to content

Instantly share code, notes, and snippets.

@ColinFay
Created September 29, 2022 08:35
Show Gist options
  • Save ColinFay/c94d92c84a825630e07194442f0de098 to your computer and use it in GitHub Desktop.
Save ColinFay/c94d92c84a825630e07194442f0de098 to your computer and use it in GitHub Desktop.
com <- git2r::commits() |> purrr::map_chr("message") |> tolower()
n_feat <- com |>
grepl("^feat", .) |>
sum()
n_fix <- com |>
grepl("^fix", .) |>
sum()
n_chore <- com |>
grepl("^chore", .) |>
sum()
n_merge <- com |>
grepl("^merge", .) |>
sum()
n_style<- com |>
grepl("^style", .) |>
sum()
n_ci <- com |>
grepl("^ci", .) |>
sum()
n_refactor <- com |>
grepl("^refactor", .) |>
sum()
n_test <- com |>
grepl("^test", .) |>
sum()
n_docs <- com |>
grepl("^docs", .) |>
sum()
unknown <- length(com) - (sum(n_feat, n_fix,n_chore,n_merge, n_style, n_ci, n_refactor,n_test, n_docs))
library(ggplot2)
data.frame(
type = c("feat", "fix", "chore", "merge","style","ci", "refactor", "test","docs", "unknown"),
n = c(n_feat, n_fix,n_chore,n_merge, n_style, n_ci, n_refactor,n_test, n_docs, unknown)
) |> ggplot(aes(type, n, fill = type)) + geom_col() |> dput()
git2r::commits() |>
purrr::map_df
~ {
tibble::tibble(
date = as.character(.x$author$when),
message = .x$message
) |>
dplyr::mutate
type = dplyr::case_when(
grepl("^chore", message) ~ "chore",
grepl("^feat", message) ~ "feat",
grepl("^fix", message) ~ "fix",
grepl("^merge", message) ~ "merged",
grepl("^style", message) ~ "style",
grepl("^ci", message) ~ "ci",
grepl("^merge", message) ~ "merged",
grepl("^refactor", message) ~ "refactor",
grepl("^test", message) ~ "test",
grepl("^docs", message) ~ "docs",
TRUE ~ "unknown"
)
)
}
) |>
dplyr::mutate(
date = lubridate::ymd_hms(date) |> as.Date()
) |>
dplyr::filter(type != "unknown") |>
dplyr::group_by(date) |>
dplyr::count(type) |>
dplyr::group_by(type) |>
dplyr::mutate(ctype = cumsum(n)) |>
ggplot(aes(date, ctype, group = type, color = type)) + geom_line( size = 2)
# week
git2r::commits() |>
purrr::map_df(
~ {
tibble::tibble(
date = as.character(.x$author$when),
message = .x$message
) |>
dplyr::mutate(
type = dplyr::case_when(
grepl("^chore", message) ~ "chore",
grepl("^feat", message) ~ "feat",
grepl("^fix", message) ~ "fix",
grepl("^merge", message) ~ "merged",
grepl("^style", message) ~ "style",
grepl("^ci", message) ~ "ci",
grepl("^merge", message) ~ "merged",
grepl("^refactor", message) ~ "refactor",
grepl("^test", message) ~ "test",
grepl("^docs", message) ~ "docs",
TRUE ~ "unknown"
)
)
}
) |>
dplyr::mutate(
week = lubridate::ymd_hms(date) |> lubridate::week()
) |>
dplyr::filter(type != "unknown") |>
dplyr::group_by(week) |>
dplyr::count(type) |>
ggplot(aes(week, n, fill = type)) + geom_col( position = "fill")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment