Skip to content

Commit 30de5dd

Browse files
committed
removed use of .data and moved post creation to bottom
1 parent 779f0c3 commit 30de5dd

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

scripts/announcements.R

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -75,65 +75,26 @@ coffee_code_details <-
7575

7676
# Find any existing posts, take the date, and filter out those sessions from the
7777
# session_details dataframe.
78-
keep_only_new <- function(.data) {
78+
keep_only_new <- function(events) {
7979
existing_post_dates <- fs::dir_ls(here::here("_posts"), regexp = ".md$|.markdown$") %>%
8080
str_extract("[0-9]{4}-[0-9]{2}-[0-9]{2}")
8181

82-
.data %>%
82+
events %>%
8383
filter(!as.character(date) %in% existing_post_dates)
8484
}
8585

8686
new_sessions <- keep_only_new(session_details)
8787
new_coffee_code <- keep_only_new(coffee_code_details)
8888

89-
# Create files in _posts/ -------------------------------------------------
90-
# Adds the new sessions/events to the _posts folder.
89+
# Create a GitHub Issue of the session ------------------------------------
9190

9291
# Format as eg August 23
93-
day_month <- function(.date, add_name = TRUE) {
92+
day_month <- function(date_var, add_name = TRUE) {
9493
date_format <- "%B %e" # as August 23
9594
if (add_name) date_format <- "%A, %B %e" # as Monday, August 23
96-
trimws(format(as.Date(.date), format = date_format))
95+
trimws(format(as.Date(date_var), format = date_format))
9796
}
9897

99-
create_new_posts_with_content <- function(.data) {
100-
new_post_filenames <-
101-
glue_data(.data, "{here::here('_posts')}/{date}-{key}.md")
102-
103-
# Get the GitHub Issue URL for the event.
104-
gh_issue_number <- gh::gh("GET /repos/:owner/:repo/issues",
105-
owner = "uoftcoders",
106-
repo = "Events") %>%
107-
map_dfr(~ data_frame(by_title = .$title, url = .$html_url))
108-
109-
new_post_content <- .data %>%
110-
mutate(by_title = str_c(title, " - ", day_month(date, add_name = FALSE))) %>%
111-
left_join(gh_issue_number, by = "by_title") %>%
112-
glue_data(
113-
'
114-
---
115-
title: "{title}"
116-
text: "{description}"
117-
location: "{location}"
118-
link: "{url}"
119-
date: "{as.Date(date)}"
120-
startTime: "{start_time}"
121-
endTime: "{end_time}"
122-
---
123-
'
124-
)
125-
126-
# Save post content to file
127-
fs::dir_create(here::here("_posts"))
128-
map2(new_post_content, new_post_filenames, ~ write_lines(x = .x, path = .y))
129-
usethis:::done("Markdown posts created in _posts/ folder.")
130-
return(invisible())
131-
}
132-
133-
create_new_posts_with_content(new_sessions)
134-
create_new_posts_with_content(new_coffee_code)
135-
136-
# Create a GitHub Issue of the session ------------------------------------
13798

13899
post_gh_issue <- function(title, body, labels) {
139100
# Will need to set up a GitHub PAT via (I think) the function
@@ -156,8 +117,8 @@ post_gh_issue <- function(title, body, labels) {
156117
}
157118
}
158119

159-
gh_issue_info_event <- function(.data) {
160-
content <- .data %>%
120+
gh_issue_info_event <- function(events) {
121+
content <- events %>%
161122
mutate(needs_packages = ifelse(
162123
!is.na(packages),
163124
str_c(
@@ -183,13 +144,13 @@ gh_issue_info_event <- function(.data) {
183144
"
184145
)
185146

186-
.data %>%
147+
events %>%
187148
mutate(content = content, title = str_c(title, " - ", day_month(date, add_name = FALSE))) %>%
188149
select(title, content, skill_level, gh_labels)
189150
}
190151

191-
gh_issue_info_coffee_code <- function(.data) {
192-
content <- .data %>%
152+
gh_issue_info_coffee_code <- function(events) {
153+
content <- events %>%
193154
glue_data(
194155
"
195156
Our bi-weekly 'Coffee and Code' meet-up:
@@ -206,22 +167,62 @@ gh_issue_info_coffee_code <- function(.data) {
206167
"
207168
)
208169

209-
.data %>%
170+
events %>%
210171
mutate(content = content, title = str_c(title, " - ", day_month(date, add_name = FALSE))) %>%
211172
select(title, content, gh_labels)
212173
}
213174

214-
create_gh_issues_coffee_code <- function(.data) {
215-
.data %>%
175+
create_gh_issues_coffee_code <- function(events) {
176+
events %>%
216177
gh_issue_info_coffee_code() %>%
217178
pmap( ~ post_gh_issue(..1, ..2, ..3))
218179
}
219180

220-
create_gh_issues_events <- function(.data) {
221-
.data %>%
181+
create_gh_issues_events <- function(events) {
182+
events %>%
222183
gh_issue_info_event() %>%
223184
pmap( ~ post_gh_issue(..1, ..2, c(..3, ..4)))
224185
}
225186

226187
create_gh_issues_coffee_code(new_coffee_code)
227188
create_gh_issues_events(new_sessions)
189+
190+
# Create files in _posts/ -------------------------------------------------
191+
# Adds the new sessions/events to the _posts folder.
192+
193+
create_new_posts_with_content <- function(events) {
194+
new_post_filenames <-
195+
glue_data(events, "{here::here('_posts')}/{date}-{key}.md")
196+
197+
# Get the GitHub Issue URL for the event.
198+
gh_issue_number <- gh::gh("GET /repos/:owner/:repo/issues",
199+
owner = "uoftcoders",
200+
repo = "Events") %>%
201+
map_dfr(~ data_frame(by_title = .x$title, url = .x$html_url))
202+
203+
new_post_content <- events %>%
204+
mutate(by_title = str_c(title, " - ", day_month(date, add_name = FALSE))) %>%
205+
left_join(gh_issue_number, by = "by_title") %>%
206+
glue_data(
207+
'
208+
---
209+
title: "{title}"
210+
text: "{description}"
211+
location: "{location}"
212+
link: "{url}"
213+
date: "{as.Date(date)}"
214+
startTime: "{start_time}"
215+
endTime: "{end_time}"
216+
---
217+
'
218+
)
219+
220+
# Save post content to file
221+
fs::dir_create(here::here("_posts"))
222+
map2(new_post_content, new_post_filenames, ~ write_lines(x = .x, path = .y))
223+
usethis:::done("Markdown posts created in _posts/ folder.")
224+
return(invisible())
225+
}
226+
227+
create_new_posts_with_content(new_sessions)
228+
create_new_posts_with_content(new_coffee_code)

0 commit comments

Comments
 (0)