Created
April 23, 2018 06:47
-
-
Save maelle/75261a0b6793d18cfdd02734d2e3f243 to your computer and use it in GitHub Desktop.
Programmatically update contributor list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("magrittr") | |
# get current author list | |
codemetar_current_desc <- ghrecipes::get_description("ropensci", | |
"codemetar", | |
branch = "dev") | |
# parse it to a data.frame | |
parse_author <- function(person){ | |
if(!is.null(person$family)){ | |
tibble::tibble(given = person$given, | |
family = person$family, | |
role = person$role) | |
}else{ | |
tibble::tibble(given = person$given, | |
role = person$role) | |
} | |
} | |
# parse authors | |
codemetar_current_authors <- purrr::map_df(codemetar_current_desc$authors, | |
parse_author) | |
# contributers to master that Carl wanted to add | |
# the output is a data.frame with login and name | |
ctb <- ghrecipes::get_master_committers("codemetar", "ropensci") | |
# hack because of https://github.com/ropensci/jqr/issues/71 | |
ctb$name[ctb$login == "maelle"] <- "Maëlle Salmon" | |
# parse names | |
master_contributers <- purrr::map_df(ctb$name, humaniformat::parse_names) | |
master_contributers <- master_contributers[, c("first_name", "last_name")] | |
# humaniformat uses first_name and last_name, rename them | |
master_contributers <- dplyr::rename(master_contributers, | |
given = first_name, | |
family = last_name) | |
master_contributers <- dplyr::mutate(master_contributers, | |
role = "ctb") | |
# read the current DESCRIPTION | |
# am working on the dev branch | |
desc <- desc::desc("DESCRIPTION") | |
# if the person is already an author, add the ctb role | |
# unless they are the maintainer | |
add_role_or_name <- function(author_df, codemetar_current_authors, desc){ | |
whether_author <- dplyr::left_join(author_df, | |
codemetar_current_authors, | |
by = c("given", "family")) | |
if(any(!is.na(whether_author$role.y))){ | |
print(whether_author$role.y) | |
if(!any(whether_author$role.y == "cre")){ | |
desc$add_role(role = author_df$role, | |
given = author_df$given, | |
family = author_df$family) | |
} | |
}else{ | |
desc$add_author(role = author_df$role, | |
given = author_df$given, | |
family = author_df$family) | |
} | |
} | |
master_contributers <- split(master_contributers, master_contributers$family) | |
purrr::walk(master_contributers, | |
add_role_or_name, | |
codemetar_current_authors, | |
desc) | |
# also add myself | |
desc$add_role(role = "aut", family = "Salmon", given = "Maëlle") | |
# save result | |
desc$write("DESCRIPTION") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment