@@ -75,65 +75,26 @@ coffee_code_details <-
75
75
76
76
# Find any existing posts, take the date, and filter out those sessions from the
77
77
# session_details dataframe.
78
- keep_only_new <- function (.data ) {
78
+ keep_only_new <- function (events ) {
79
79
existing_post_dates <- fs :: dir_ls(here :: here(" _posts" ), regexp = " .md$|.markdown$" ) %> %
80
80
str_extract(" [0-9]{4}-[0-9]{2}-[0-9]{2}" )
81
81
82
- .data %> %
82
+ events %> %
83
83
filter(! as.character(date ) %in% existing_post_dates )
84
84
}
85
85
86
86
new_sessions <- keep_only_new(session_details )
87
87
new_coffee_code <- keep_only_new(coffee_code_details )
88
88
89
- # Create files in _posts/ -------------------------------------------------
90
- # Adds the new sessions/events to the _posts folder.
89
+ # Create a GitHub Issue of the session ------------------------------------
91
90
92
91
# Format as eg August 23
93
- day_month <- function (.date , add_name = TRUE ) {
92
+ day_month <- function (date_var , add_name = TRUE ) {
94
93
date_format <- " %B %e" # as August 23
95
94
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 ))
97
96
}
98
97
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 ------------------------------------
137
98
138
99
post_gh_issue <- function (title , body , labels ) {
139
100
# Will need to set up a GitHub PAT via (I think) the function
@@ -156,8 +117,8 @@ post_gh_issue <- function(title, body, labels) {
156
117
}
157
118
}
158
119
159
- gh_issue_info_event <- function (.data ) {
160
- content <- .data %> %
120
+ gh_issue_info_event <- function (events ) {
121
+ content <- events %> %
161
122
mutate(needs_packages = ifelse(
162
123
! is.na(packages ),
163
124
str_c(
@@ -183,13 +144,13 @@ gh_issue_info_event <- function(.data) {
183
144
"
184
145
)
185
146
186
- .data %> %
147
+ events %> %
187
148
mutate(content = content , title = str_c(title , " - " , day_month(date , add_name = FALSE ))) %> %
188
149
select(title , content , skill_level , gh_labels )
189
150
}
190
151
191
- gh_issue_info_coffee_code <- function (.data ) {
192
- content <- .data %> %
152
+ gh_issue_info_coffee_code <- function (events ) {
153
+ content <- events %> %
193
154
glue_data(
194
155
"
195
156
Our bi-weekly 'Coffee and Code' meet-up:
@@ -206,22 +167,62 @@ gh_issue_info_coffee_code <- function(.data) {
206
167
"
207
168
)
208
169
209
- .data %> %
170
+ events %> %
210
171
mutate(content = content , title = str_c(title , " - " , day_month(date , add_name = FALSE ))) %> %
211
172
select(title , content , gh_labels )
212
173
}
213
174
214
- create_gh_issues_coffee_code <- function (.data ) {
215
- .data %> %
175
+ create_gh_issues_coffee_code <- function (events ) {
176
+ events %> %
216
177
gh_issue_info_coffee_code() %> %
217
178
pmap( ~ post_gh_issue(..1 , ..2 , ..3 ))
218
179
}
219
180
220
- create_gh_issues_events <- function (.data ) {
221
- .data %> %
181
+ create_gh_issues_events <- function (events ) {
182
+ events %> %
222
183
gh_issue_info_event() %> %
223
184
pmap( ~ post_gh_issue(..1 , ..2 , c(..3 , ..4 )))
224
185
}
225
186
226
187
create_gh_issues_coffee_code(new_coffee_code )
227
188
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