if (!require("pak")) install.packages("pak")
pak::pkg_install(pkg = c(
"CedricMondy/Rapi4GH", "CedricMondy/AspeDashboard", "CedricMondy/templatesOFB",
"dplyr", "purrr", "lubridate", "aweek", "stringr", "ggplot2", "treemapify"
), ask = FALSE)Bilan
Installation et paramétrage
Les fonctions pour interroger l’API ont été regroupées dans un package R: {Rapi4GH} que l’on installe depuis GitHub.
Le dépôt de référence du PRR Onde est celui que nous allons interroger de manière répétée, on stocke donc son propriétaire et le nom du dépôt dans des variables pour éviter de le retaper.
owner <- "richaben"
repo <- "PRR_ONDE"L’API de GitHub présente une limitation du nombre de requêtes qui peuvent être faites. Cette limitation est moins forte lorsque l’on s’identifie. Le nom d’utilisateur et un jeton d’accès personnel sont stockés comme des variables d’environnement dans le fichier .Renviron à la racine du répertoire personnel. Les valeurs des ces variables peuvent être récupérés en utilisant la fonction Sys.getenv avec comme argument le nom de la variable souhaitée. Dans cet exemple, le nom d’utilisateur GitHub et un token personnel sont stockés dans les variables GH_USER et GH_TOKEN
Sys.getenv("GH_user")
Sys.getenv("GH_TOKEN")Déploiements régionaux
Un petit peu d’harmonisation des noms de compte GitHub des DR est utile:
directions_regionales <- c(
`ofb-bzh` = "DR BZH",
`OFB-HdF` = "DR HdF",
`OFB-IdF` = "DR IdF",
`ofb-pdl` = "DR PdL",
`SRC-PacaCorse` = "DR PACA-C",
`OFB-NA` = "DR NA",
`Josefine57` = "DR GE",
`OFB-BFC` = "DR BFC",
`OFB-OCC` = "DR OCC",
`ofb-CVL` = "DR CVL",
`ofb-aura` = "DR AURA",
`OFB-Nor` = "DR NOR"
)On récupère les informations sur les copies du dépôt et leurs dates de création.
forks <- Rapi4GH::get_gh_info(
owner = owner, repo = repo, endpoint = "forks",
auth_user = Sys.getenv("GH_USER"), auth_pswd = Sys.getenv("GH_TOKEN")
) %>%
Rapi4GH::format_forks() %>%
dplyr::mutate(
dr = directions_regionales[owner]
) On complète en récupérant la date du dernier commit réalisé sur la branche principale de chacune des copies du dépôt.
forks_last_commit <- purrr::map(
.x = forks$owner,
.f = function(x) {
Rapi4GH::get_gh_info(
owner = x,
repo = repo,
endpoint = "commits",
query = "sha=master&per_page=1&page=1",
auth_user = Sys.getenv("GH_USER"), auth_pswd = Sys.getenv("GH_TOKEN")
) %>%
Rapi4GH::format_commits() %>%
dplyr::mutate(
owner = x,
date = lubridate::as_date(date)
)
}
) %>%
purrr::list_rbind()On visualise les dates de création et de dernière mise à jour des copies régionales du dépôt de référence.
data_forks <- forks %>%
dplyr::left_join(
forks_last_commit %>%
dplyr::select(owner, last_update = date),
by = "owner"
) %>%
dplyr::filter(!is.na(dr))
ggplot2::ggplot() +
ggplot2::geom_segment(
data = data_forks,
mapping = ggplot2::aes(
x = created_at,
xend = last_update,
y = dr,
yend = dr
)
) +
ggplot2::geom_point(
data = data_forks %>%
tidyr::pivot_longer(
cols = c(created_at, last_update),
names_to = "event",
values_to = "date"
),
mapping = ggplot2::aes(
x = date, y = dr, shape = event, fill = event
),
size = 2
)+
templatesOFB::theme_ofb() +
ggplot2::labs(
x = "", y = "Direction Régionale\n",
caption = stringr::str_wrap("Certains dépôts ont été 'recréés' en raison de problèmes lors de la mise à jour, les versions antérieures n'apparraissent donc pas dans ce graphique.", width = 80)
) +
ggplot2::theme(
axis.text.y = ggplot2::element_text(hjust = 0),
plot.caption = ggplot2::element_text(hjust = 0)
) +
ggplot2::scale_shape_manual(
name = "Evénement du dépôt",
labels = c("Création", "Dernière MaJ"),
values = c(22, 21)
) +
ggplot2::scale_fill_manual(
name = "Evénement du dépôt",
labels = c("Création", "Dernière MaJ"),
values = c("black", "white")
) Contributions au dépôt de référence
Tickets et demandes de contribution
On récupère les informations sur les tickets (issues) ouverts sur le dépôt de référence ainsi que les demandes de contribution (Pull requests) qui ont été réalisées.
all_issues <- Rapi4GH::get_gh_info(
owner = owner, repo = repo, endpoint = "issues",
query = "state=all",
auth_user = Sys.getenv("GH_USER"), auth_pswd = Sys.getenv("GH_TOKEN")
) %>%
Rapi4GH::format_issues() %>%
dplyr::mutate(
dr = dplyr::case_when(
author %in% c("CedricMondy", "OFB-IdF") ~ "DR IdF",
author %in% c("PascalIrz") ~ "DR BZH",
author %in% c("OFB-NA") ~ "DR NA",
author %in% c("antonio-andrade", "ofb-dsued") ~ "DSUED",
author %in% c("Josefine57") ~ "DR GE",
author %in% c("OFB-BFC") ~ "DR BFC",
author %in% c("richaben", "OFB-Nor") ~ "DR NOR",
author %in% c("broussel59") ~ "DR HdF"
)
)Tickets
Evolution du nombre et du type de ticket ouverts,.
all_issues %>%
dplyr::filter(!is_pr, !is.na(type), type != "duplicate") %>%
dplyr::count(type)# A tibble: 2 × 2
type n
<chr> <int>
1 bug 11
2 enhancement 15
all_issues %>%
dplyr::filter(!is_pr, !is.na(type), type != "duplicate") %>%
dplyr::mutate(
date_opened = opened,
date_closed = closed
) %>%
dplyr::select(dr, url, type, date_opened, date_closed) %>%
dplyr::mutate(
year = lubridate::year(date_opened),
week = lubridate::isoweek(date_opened)
) %>%
dplyr::mutate(
week_date = paste0(
year, "-W", week
) %>%
aweek::week2date()
) %>%
dplyr::count(
week_date, type
) %>%
ggplot2::ggplot() +
ggplot2::geom_col(
mapping = ggplot2::aes(x = week_date, y = n, fill = type)
) +
templatesOFB::theme_ofb() +
ggplot2::labs(x = "", y = "Nombre de tickets ouverts", fill = "Type de demande") +
ggplot2::scale_y_continuous(breaks = AspeDashboard:::int_breaks) +
ggplot2::scale_fill_hue(labels = c("Correction", "Evolution"))Contributions des différentes DR
all_issues %>%
dplyr::filter(!is_pr, !is.na(type), type != "duplicate") %>%
dplyr::count(dr, type) %>%
ggplot2::ggplot(
mapping = ggplot2::aes(
area = n, fill = type, subgroup = dr
)
) +
treemapify::geom_treemap() +
treemapify::geom_treemap_subgroup_border() +
treemapify::geom_treemap_subgroup_text(
mapping = ggplot2::aes(label = dr),
place = "center", grow = FALSE
) +
treemapify::geom_treemap_text(
mapping = ggplot2::aes(label = n)
) +
ggplot2::scale_fill_hue(
name = "Type de demande",
labels = c("Correction", "Evolution")
)Estimation du temps pris pour répondre aux différents tickets.
all_issues %>%
dplyr::filter(!is_pr, !is.na(type), type != "duplicate") %>%
dplyr::mutate(
date_opened = lubridate::as_date(opened),
date_closed = lubridate::as_date(closed)
) %>%
dplyr::mutate(
year = lubridate::year(date_opened),
week = lubridate::isoweek(date_opened)
) %>%
dplyr::mutate(
week_date = paste0(
year, "-W", week
) %>%
aweek::week2date()
) %>%
# dplyr::select(dr, type, date_opened, date_closed, url) %>%
dplyr::filter(!is.na(date_closed)) %>%
dplyr::mutate(
closing_delay = as.numeric(date_closed - date_opened)
) %>%
ggplot2::ggplot(
mapping = ggplot2::aes(
x = closing_delay, fill = type
)
) +
ggplot2::geom_histogram(binwidth = 10, colour = "black") +
# ggplot2::scale_y_log10() +
templatesOFB::theme_ofb() +
ggplot2::scale_fill_hue(
name = "Type de demande",
labels = c("Correction", "Evolution")
) +
ggplot2::scale_y_continuous(breaks = AspeDashboard:::int_breaks) +
ggplot2::labs(
x = "Durée en jours pour clore la demande",
y = "Nombre de demandes"
)Pull requests
Evolution du nombre de demandes de contribution au dépôt de référence
all_issues %>%
dplyr::filter(
is_pr,
url != "https://github.com/richaben/PRR_ONDE/pull/4"
) %>%
dplyr::mutate(
date = opened,
utilisateur = dplyr::case_when(
author %in% c("CedricMondy", "OFB-IdF") ~ "Cédric",
author %in% c("richaben", "OFB-Nor") ~ "Benoît",
author %in% c("antonio-andrade") ~ "Antonio"
)
) %>%
dplyr::mutate(
year = lubridate::year(date),
week = lubridate::isoweek(date)
) %>%
dplyr::mutate(
week_date = paste0(
year, "-W", week
) %>%
aweek::week2date()
) %>%
# dplyr::filter(year == 2023) %>%
ggplot2::ggplot() +
ggplot2::geom_bar(
mapping = ggplot2::aes(
x = week_date, fill = utilisateur
)
) +
templatesOFB::theme_ofb() +
ggplot2::labs(x = "", y = "Nombre de PR", fill = "Auteur")Commits
On récupère l’historique du dépôt, on retire les commits de merge et on nettoie un peu les noms des contributeurs.
historique_git <- Rapi4GH::get_gh_info(
owner = owner, repo = repo, endpoint = "commits",
query = "sha=master", auth_user = Sys.getenv("GH_USER"), auth_pswd = Sys.getenv("GH_TOKEN")
) %>%
Rapi4GH::format_commits() %>%
dplyr::filter(!stringr::str_detect(message, "Merge")) %>%
dplyr::mutate(
auteur = dplyr::case_when(
author %in% c("Benoit R", "Benoit Richard", "Office français de la biodiversité - Normandie", "richaben", "OFB-Nor") ~ "Benoît",
author %in% c("CedricMondy", "Cédric Mondy", "cedric.mondy", "OFB-IdF") ~ "Cédric",
author %in% c("antonio-andrade") ~ "Antonio"
)
) historique_git %>%
dplyr::mutate(date = date %>%
lubridate::as_date()) %>%
dplyr::mutate(
year = lubridate::year(date),
week = lubridate::isoweek(date)
) %>%
dplyr::mutate(
week_date = paste0(
year, "-W", week
) %>%
aweek::week2date()
) %>%
# dplyr::filter(year == 2023) %>%
ggplot2::ggplot() +
ggplot2::geom_bar(
mapping = ggplot2::aes(
x = week_date, fill = auteur
)
) +
templatesOFB::theme_ofb() +
ggplot2::labs(x = "", y = "Nombre de commits\nqui ne sont pas des merge", fill = "Auteur")