Skip to content

Commit ae1d874

Browse files
committed
Refactor scrape_github_socials()
1 parent 91b16dc commit ae1d874

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

R/buildtools.R

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,10 @@ get_maintainer_info <- function(path = '.'){
465465
login <- Sys.getenv('MAINTAINERLOGIN', "")
466466
if(nchar(login)){
467467
info$login <- tolower(login)
468-
info$mastodon <- scrape_github_social(login, "Mastodon")
469-
info$bluesky <- scrape_github_social(login, "Bluesky")
470-
info$linkedin <- scrape_github_social(login, "LinkedIn")
468+
socials <- scrape_github_socials(login)
469+
info$mastodon <- socials$mastodon
470+
info$bluesky <- socials$bluesky
471+
info$linkedin <- socials$linkedin
471472
}
472473
uuid <- Sys.getenv('MAINTAINERUUID', "")
473474
if(nchar(uuid)){
@@ -488,13 +489,17 @@ get_maintainer_info <- function(path = '.'){
488489
return(info)
489490
}
490491

491-
scrape_github_social <- function(login, network = c('Bluesky', 'Mastodon', 'LinkedIn')){
492+
scrape_github_socials <- function(login){
493+
networks <- c('Bluesky', 'Mastodon', 'LinkedIn')
492494
tryCatch({
493495
doc <- xml2::read_html(paste0("http://github.com/", login))
494-
link <- xml2::xml_find_all(doc, sprintf('//li[svg/title = "%s"]/a', network))
495-
if(length(link)){
496-
xml2::xml_attr(link, 'href')
497-
}
496+
out <- lapply(networks, function(network){
497+
link <- xml2::xml_find_all(doc, sprintf('//li[svg/title = "%s"]/a', network))
498+
if(length(link)){
499+
xml2::xml_attr(link, 'href')
500+
}
501+
})
502+
structure(out, names = tolower(networks))
498503
}, error = message)
499504
}
500505

0 commit comments

Comments
 (0)