From 4883457e9bd76cd44513747419c725e8ec47392f Mon Sep 17 00:00:00 2001 From: LE DURAND Matteo <matteo.le-durand@developpement-durable.gouv.fr> Date: Thu, 6 Mar 2025 16:30:01 +0100 Subject: [PATCH] ajout des groupes --- dev/github_extraire.R | 7 ++++++- dev/gitlab_classique.R | 10 ++++++---- dev/gitlab_forge.R | 22 +++++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/dev/github_extraire.R b/dev/github_extraire.R index e8763ce..167a81e 100644 --- a/dev/github_extraire.R +++ b/dev/github_extraire.R @@ -152,7 +152,12 @@ get_github_topics <- function(repo) { ) combined_data <- combined_data %>% left_join(topics_list, by = "project_name") %>% - mutate(origine = "Github") %>% + mutate(origine = "Github", + groupe = case_when( + str_detect(project_name, "parcours_r") ~ "r-formation", + str_detect(project_name, "spyrales") ~ "spyrales", + TRUE ~ "autre" + )) %>% unique() # Afficher les premières lignes du tableau combiné diff --git a/dev/gitlab_classique.R b/dev/gitlab_classique.R index 023964f..cd71b90 100644 --- a/dev/gitlab_classique.R +++ b/dev/gitlab_classique.R @@ -7,7 +7,7 @@ library(gitlabr) set_gitlab_connection( gitlab_url = "https://gitlab.com" , - private_token = Sys.getenv("GITLAB_PAT") + private_token = Sys.getenv("GITLAB_COM_TOKEN") ) project_ids <- c(41600697, 19859695, 49118792, 21138017, 44145525, 18441361, 17610613,18439010) @@ -27,12 +27,12 @@ get_project_name <- function(base_url, project_id, private_token) { # Boucle pour récupérer tous les noms de projets name_gitlab <- bind_rows(lapply(project_ids, get_project_name, base_url = "https://gitlab.com", - private_token = Sys.getenv("GITLAB_PAT"))) + private_token = Sys.getenv("GITLAB_COM_TOKEN"))) name_gitlab$id <- as.character(name_gitlab$id) # Variables pour l'API GitLab base_url <- "https://gitlab.com" -private_token <- Sys.getenv("GITLAB_PAT") # Récupération du token depuis Renviron +private_token <- Sys.getenv("GITLAB_COM_TOKEN") # Récupération du token depuis Renviron # Fonction pour gérer la pagination de l'API GitLab avec une limite stricte à 160 pages, en vérifiant la présence de pages suivantes @@ -242,7 +242,9 @@ all_data_gitlab <- all_data_gitlab %>% filter(!(is.na(all_data_gitlab$type) | is.na(all_data_gitlab$message)) | all_data_gitlab$type == "joined" | all_data_gitlab$type == "WikiPage::Meta") all_data_gitlab <- bind_rows(fg,all_data_gitlab) all_data_gitlab <- all_data_gitlab %>% - mutate(origine ="Gitlab") + mutate(origine ="Gitlab", + groupe = "RDES_DREAL") all_data_gitlab <- left_join(all_data_gitlab, projects_topics, by = c("project_name" = "id")) + # save.image("gitlab.RData") save(all_data_gitlab, file = "gitlab.RData") diff --git a/dev/gitlab_forge.R b/dev/gitlab_forge.R index 6955bc6..ff2f641 100644 --- a/dev/gitlab_forge.R +++ b/dev/gitlab_forge.R @@ -7,7 +7,7 @@ library(gitlabr) set_gitlab_connection( gitlab_url = "https://gitlab-forge.din.developpement-durable.gouv.fr" , - private_token = Sys.getenv("GITLAB_COM_TOKEN") + private_token = Sys.getenv("GITLAB_PAT") ) response <- data.frame() @@ -15,7 +15,7 @@ response <- data.frame() buildres <- function(i){ res_proj100 <- GET( "https://gitlab-forge.din.developpement-durable.gouv.fr/api/v4/groups/1013/projects", - add_headers(`PRIVATE-TOKEN` = Sys.getenv("GITLAB_COM_TOKEN")), + add_headers(`PRIVATE-TOKEN` = Sys.getenv("GITLAB_PAT")), query = list( include_subgroups = "true", per_page = 100, @@ -38,7 +38,7 @@ repeat { } # response <- GET( # "https://gitlab-forge.din.developpement-durable.gouv.fr/api/v4/groups/1013/projects", -# add_headers(`PRIVATE-TOKEN` = Sys.getenv("GITLAB_COM_TOKEN")), +# add_headers(`PRIVATE-TOKEN` = Sys.getenv("GITLAB_PAT")), # query = list( # include_subgroups = "true", # per_page = 1000 @@ -68,12 +68,12 @@ get_project_name <- function(base_url, project_id, private_token) { # Boucle pour récupérer tous les noms de projets name_gitlab <- bind_rows(lapply(project_ids, get_project_name, base_url = "https://gitlab-forge.din.developpement-durable.gouv.fr", - private_token = Sys.getenv("GITLAB_COM_TOKEN"))) + private_token = Sys.getenv("GITLAB_PAT"))) name_gitlab$id <- as.character(name_gitlab$id) # Variables pour l'API GitLab base_url <- "https://gitlab-forge.din.developpement-durable.gouv.fr" -private_token <- Sys.getenv("GITLAB_COM_TOKEN") # Récupération du token depuis Renviron +private_token <- Sys.getenv("GITLAB_PAT") # Récupération du token depuis Renviron # Fonction pour gérer la pagination de l'API GitLab avec une limite stricte à 160 pages, en vérifiant la présence de pages suivantes @@ -278,10 +278,22 @@ projects_topics <- bind_rows(lapply(project_ids, get_project_topics, base_url = # Récupérer les données pour tous les projets all_data_forge <- get_data_from_multiple_projects(base_url, project_ids, private_token) + all_data_forge <- all_data_forge %>% filter(!(is.na(all_data_forge$type) | is.na(all_data_forge$message)) | all_data_forge$type == "joined"|all_data_forge$type == "WikiPage::Meta") all_data_forge <- bind_rows(ff,all_data_forge) all_data_forge <- all_data_forge %>% mutate(origine ="Gitlab_Forge") all_data_forge <- left_join(all_data_forge, projects_topics, by = c("project_name" = "id")) + +#data.frame avec les groupes et le nom pour left join ----- +response_df <- data.frame( + name = response$name, + groupe = response$namespace$path +) +# Joindre les deux jeux de données +all_data_forge <- all_data_forge %>% + left_join(response_df, by = c("project_name" = "name")) + +# sauvegarde du jeu de donnée ----- save(all_data_forge, file = "gitlab_forge.RData") -- GitLab