Skip to content

Commit

Permalink
outsource
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Jul 1, 2024
1 parent 3cb3a88 commit 879544f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 100 deletions.
102 changes: 2 additions & 100 deletions .github/workflows/update-publications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,7 @@ jobs:
- uses: r-lib/actions/setup-renv@v2

- name: Create bibtex file with selected entries
run: |
last_comment_pubs <- gh::gh(
"/repos/{gh_repo}/issues/{issue_number}/comments",
gh_repo = "${{ github.repository }}",
issue_number = 3,
.accept = "application/vnd.github.v3.full+json"
) |>
purrr::keep(~ .x$user$login == "github-actions[bot]") |>
tail(1) |>
purrr::map_chr("body_html") |>
xml2::read_html()
last_comment_pubs |>
xml2::xml_find_first("//details") |>
xml2::xml_text() |>
write("bibentries_previous_month.bib")
bibentries_previous_month <- bibtex::read.bib("bibentries_previous_month.bib")
selected <- last_comment_pubs |>
xml2::xml_find_first("//ul") |>
xml2::xml_find_all("//input") |>
xml2::xml_has_attr("checked")
selected_bibentries <- bibentries_previous_month[selected]
bib_new <- vapply(selected_bibentries, format, style = "Bibtex", character(1))
bib_old <- readLines("_data/papers.bib")
bib <- paste(c(bib_old, bib_new), collapse = "\n")
write(bib, "_data/papers.bib")
## filter latest version
df <- bib2df("_data/papers.bib") |>
dplyr::mutate(
version = dplyr::if_else(
grepl("wellcomeopenres", DOI),
sub("^.*\\.([1-9][0-9]*)$", "\\1", DOI),
"1"
),
base_doi = dplyr::if_else(
grepl("wellcomeopenres", DOI),
sub("\\.([1-9][0-9]*)$", "", DOI),
DOI
)
) |>
dplyr::group_by(base_doi) |>
dplyr::filter(version == max(version)) |>
dplyr::ungroup() |>
dplyr::select(-base_doi, -version)
## filter preprints
df <- df |>
dplyr::group_by(TITLE) |>
dplyr::mutate(n = dplyr::n()) |>
dplyr::mutate(id = seq_len(dplyr::n())) |>
dplyr::mutate(n_pp = sum(JOURNAL == "medRxiv")) |>
dplyr::filter(
!((n_pp < n) & (JOURNAL == "medRxiv"))
) |>
dplyr::filter(
!(n > 1 & id < max(id))
) |>
dplyr::ungroup()
run: source("snippets/update_publications.R")
shell: Rscript {0}

- uses: peter-evans/create-pull-request@v6
Expand Down Expand Up @@ -130,37 +64,5 @@ jobs:
- uses: r-lib/actions/setup-renv@v2

- name: Post a comment listing new papers
run: |
options(width = 10000) # do not hard-wrap formatted citations
source("_automation/get_new_papers.R")
month_1st <- format(lubridate::floor_date(lubridate::today()-1, "month"))
new_papers <- get_new_papers_team(from_date = month_1st)
if (nrow(new_papers) > 0) {
bibentries_new <- create_bibentries(new_papers)
saveRDS(bibentries_new, paste0("bibentries_previous_month.rds"))
bibentries_new_checklist <- paste("- [ ]", vapply(bibentries_new, format, character(1)))
bibentries_comment <- paste(
c(
"Papers published last month:",
bibentries_new_checklist,
"<details>",
"",
"```",
vapply(bibentries_new, format, character(1), "bibtex"),
"```",
"</details>"
),
collapse = "\n"
)
gh::gh(
"POST /repos/{gh_repo}/issues/{issue_number}/comments",
gh_repo = "${{ github.repository }}",
issue_number = 3,
body = bibentries_comment
)
}
run: source("snippets/post_publication.R")
shell: Rscript {0}
34 changes: 34 additions & 0 deletions snippets/post_publications.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
options(width = 10000) # do not hard-wrap formatted citations

source("_automation/get_new_papers.R")
month_1st <- format(lubridate::floor_date(lubridate::today() - 1, "month"))
new_papers <- get_new_papers_team(from_date = month_1st)

if (nrow(new_papers) > 0) {
bibentries_new <- create_bibentries(new_papers)
saveRDS(bibentries_new, paste0("bibentries_previous_month.rds"))

bibentries_new_checklist <- paste(
"- [ ]", vapply(bibentries_new, format, character(1))
)
bibentries_comment <- paste(
c(
"Papers published last month:",
bibentries_new_checklist,
"<details>",
"",
"```",
vapply(bibentries_new, format, character(1), "bibtex"),
"```",
"</details>"
),
collapse = "\n"
)

gh::gh(
"POST /repos/{gh_repo}/issues/{issue_number}/comments",
gh_repo = "${{ github.repository }}",
issue_number = 3,
body = bibentries_comment
)
}
65 changes: 65 additions & 0 deletions snippets/update_publications.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
last_comment_pubs <- gh::gh(
"/repos/{gh_repo}/issues/{issue_number}/comments",
gh_repo = "${{ github.repository }}",
issue_number = 3,
.accept = "application/vnd.github.v3.full+json"
) |>
purrr::keep(~ .x$user$login == "github-actions[bot]") |>
tail(1) |>
purrr::map_chr("body_html") |>
xml2::read_html()

last_comment_pubs |>
xml2::xml_find_first("//details") |>
xml2::xml_text() |>
write("bibentries_previous_month.bib")

bibentries_previous_month <- bibtex::read.bib("bibentries_previous_month.bib")

selected <- last_comment_pubs |>
xml2::xml_find_first("//ul") |>
xml2::xml_find_all("//input") |>
xml2::xml_has_attr("checked")

selected_bibentries <- bibentries_previous_month[selected]

bib_new <- vapply(selected_bibentries, format, style = "Bibtex", character(1))

bib_old <- readLines("_data/papers.bib")

bib <- paste(c(bib_old, bib_new), collapse = "\n")

write(bib, "_data/papers.bib")

## filter latest version
df <- bib2df::bib2df("_data/papers.bib") |>
dplyr::mutate(
version = dplyr::if_else(
grepl("wellcomeopenres", DOI),
sub("^.*\\.([1-9][0-9]*)$", "\\1", DOI),
"1"
),
base_doi = dplyr::if_else(
grepl("wellcomeopenres", DOI),
sub("\\.([1-9][0-9]*)$", "", DOI),
DOI
)
) |>
dplyr::group_by(base_doi) |>
dplyr::filter(version == max(version)) |>
dplyr::ungroup() |>
dplyr::select(-base_doi, -version)

## filter preprints
df <- df |>
dplyr::group_by(TITLE) |>
dplyr::mutate(n = dplyr::n()) |>
dplyr::mutate(id = seq_len(dplyr::n())) |>
dplyr::mutate(n_pp = sum(JOURNAL == "medRxiv")) |>
dplyr::filter(
!((n_pp < n) & (JOURNAL == "medRxiv"))
) |>
dplyr::filter(
!(n > 1 & id < max(id))
) |>
dplyr::ungroup()

0 comments on commit 879544f

Please sign in to comment.