Skip to content

Commit 80005fe

Browse files
committed
Use separate issues for each month's publication updates
- post_publications.R now creates a new issue each month - update_publications.R finds latest open issue with 'publications' label - Issue is closed after processing (or if no papers selected) - Cleaner than accumulating comments on one issue
1 parent ceb05ff commit 80005fe

File tree

2 files changed

+62
-14
lines changed

2 files changed

+62
-14
lines changed

snippets/post_publications.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ if (nrow(new_papers) > 0) {
1111
bibentries_new_checklist <- paste(
1212
"- [ ]", vapply(bibentries_new, format, character(1))
1313
)
14-
bibentries_comment <- paste(
14+
bibentries_body <- paste(
1515
c(
16-
"Papers published last month:",
16+
"Papers published last month. Check the boxes for papers to add, then the next monthly run will create a PR.",
17+
"",
1718
bibentries_new_checklist,
1819
"<details>",
1920
"",
@@ -25,10 +26,16 @@ if (nrow(new_papers) > 0) {
2526
collapse = "\n"
2627
)
2728

29+
issue_title <- paste(
30+
"Publications update -",
31+
format(lubridate::today(), "%B %Y")
32+
)
33+
2834
gh::gh(
29-
"POST /repos/{gh_repo}/issues/{issue_number}/comments",
35+
"POST /repos/{gh_repo}/issues",
3036
gh_repo = gh_repository,
31-
issue_number = 3,
32-
body = bibentries_comment
37+
title = issue_title,
38+
body = bibentries_body,
39+
labels = list("publications")
3340
)
3441
}

snippets/update_publications.R

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1-
last_comment_pubs <- gh::gh(
2-
"/repos/{gh_repo}/issues/{issue_number}/comments",
1+
# Find the latest open publications issue
2+
open_issues <- gh::gh(
3+
"/repos/{gh_repo}/issues",
34
gh_repo = gh_repository,
4-
issue_number = 3,
5-
.accept = "application/vnd.github.v3.full+json"
6-
) |>
7-
purrr::keep(~ .x$user$login == "github-actions[bot]") |>
8-
tail(1) |>
9-
purrr::map_chr("body_html") |>
10-
xml2::read_html()
5+
state = "open",
6+
labels = "publications",
7+
sort = "created",
8+
direction = "desc",
9+
per_page = 1
10+
)
11+
12+
if (length(open_issues) == 0) {
13+
message("No open publications issue found")
14+
quit(save = "no")
15+
}
16+
17+
issue <- open_issues[[1]]
18+
issue_number <- issue$number
19+
20+
last_comment_pubs <- issue$body_html
21+
if (is.null(last_comment_pubs)) {
22+
# Fetch with HTML body
23+
issue <- gh::gh(
24+
"/repos/{gh_repo}/issues/{issue_number}",
25+
gh_repo = gh_repository,
26+
issue_number = issue_number,
27+
.accept = "application/vnd.github.v3.full+json"
28+
)
29+
last_comment_pubs <- issue$body_html
30+
}
31+
32+
last_comment_pubs <- xml2::read_html(last_comment_pubs)
1133

1234
last_comment_pubs |>
1335
xml2::xml_find_first("//details") |>
@@ -21,6 +43,17 @@ selected <- last_comment_pubs |>
2143
xml2::xml_find_all(".//input") |>
2244
xml2::xml_has_attr("checked")
2345

46+
if (!any(selected)) {
47+
message("No papers selected, closing issue")
48+
gh::gh(
49+
"PATCH /repos/{gh_repo}/issues/{issue_number}",
50+
gh_repo = gh_repository,
51+
issue_number = issue_number,
52+
state = "closed"
53+
)
54+
quit(save = "no")
55+
}
56+
2457
selected_bibentries <- bibentries_previous_month[selected]
2558

2659
bib_new <- vapply(selected_bibentries, format, style = "Bibtex", character(1))
@@ -68,3 +101,11 @@ df <- df |>
68101
dplyr::select(-n, -id, -n_pp)
69102

70103
bib2df::df2bib(df, file = "_data/papers.bib")
104+
105+
# Close the issue after processing
106+
gh::gh(
107+
"PATCH /repos/{gh_repo}/issues/{issue_number}",
108+
gh_repo = gh_repository,
109+
issue_number = issue_number,
110+
state = "closed"
111+
)

0 commit comments

Comments
 (0)