forked from jimbrig/github-issue-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
383 lines (330 loc) · 9.06 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
---
title: "Github Issue Dashboard"
author: "Gavin Kelly"
params:
users: macroscian
orgs:
- BABS-STP
output:
flexdashboard::flex_dashboard
---
```{css}
a:link {
color: black;
}
```
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(reactable)
library(tidyverse)
library(glue)
library(gh)
library(emo)
library(htmltools)
library(farver)
library(stringr)
require(flexdashboard)
require(sass)
require(tidyr)
```
```{r repos}
user_repos <- purrr::map(params$users, function(x) {
query <- paste0("/users/", x, "/repos")
repos_out <- gh::gh(query, .limit = Inf) %>%
purrr::map_depth(1, purrr::pluck, "full_name") %>%
purrr::map_chr(purrr::pluck, 1)
repos_out
}) %>% purrr::flatten_chr()
org_repos <- purrr::map(params$orgs, function(x) {
query <- paste0("/orgs/", x, "/repos")
repos_out <- gh::gh(query, .limit = Inf) %>%
purrr::map_depth(1, purrr::pluck, "full_name") %>%
purrr::map_chr(purrr::pluck, 1) %>%
purrr::discard(stringr::str_detect, regex("[:digit:]"))
repos_out
}) %>% purrr::flatten_chr()
repos <- c(user_repos, org_repos)
```
```{r parsing}
#' Read all issues from repositories
#'
#' @param repo Character vector of repositories in the format "owner/name".
#'
#' @return tibble with 1 row per issue.
all_issues <- function(repo) {
map_dfr(repo, github_summary)
}
#' Read all issues from 1 repository
#'
#' @param repo Character of repository in the format "owner/name".
#'
#' @return tibble with 1 row per issue.
github_summary <- function(repo) {
x <- gh(glue("/repos/{repo}/issues"))
map_dfr(x, issue_summary)
}
#' Extract relevant issue information
#'
#' @param repo Output from [gh::gh()]
#'
#' @return List with 7 elements.
issue_summary <- function(x) {
list(
repository = x$repository_url,
title = x$title,
issue_url = x$html_url,
created_at = x$created_at,
updated_at = x$updated_at,
comments = x$comments,
labels = list(x$labels)
)
}
```
```{r, download}
# Download all issues
user_issues <- all_issues(user_repos) %>%
# Combine issue_url and title
mutate(title = glue('<a href="{issue_url}">{title}</a>')) %>%
select(-issue_url)
org_issues <- all_issues(org_repos) %>%
# Combine issue_url and title
mutate(title = glue('<a href="{issue_url}">{title}</a>')) %>%
select(-issue_url)
```
```{r, tidiers}
# Replaces github style emojies with emojies using [emo::ji]
substitute_emoji <- function(x) {
m <- gregexpr(":[^[:space:]]+:", x)
regmatches(x, m) <- lapply(regmatches(x, m), function(xx) map_chr(gsub(":", "", xx), emo::ji))
x
}
# Turns date format into 2020-01-01 format
date_format <- function(value) {
str_sub(value, 1, 10)
}
# Removes `api` and `repos` from Github url
remove_api_url <- function(x) {
url <- str_remove(x, "api\\.")
str_remove(url, "repos/")
}
# Extracts `owner/name` part from github url and create a tag with link to repository
extract_github_url <- function(value) {
url <- remove_api_url(value)
text <- str_remove(url, "https://github.com/")
glue('<a href="{url}">{text}</a>')
}
```
```{r}
# Takes a color and returns white or black depending on what would be the best
# text color for that background color
color_flip <- function(x) {
x <- paste0("#", x)
color_lightness <- farver::convert_colour(t(col2rgb(x)), "rgb", "hsl")[, "l"]
ifelse(color_lightness > 31, "#010101", "#FFFFFF")
}
# Style 1 github issue label to look like label on Website
style_label <- function(x) {
a(substitute_emoji(x$name),
href = remove_api_url(x$url),
style = glue("background: #{x$color};
padding: 0 7px;
color: {color_flip(x$color)};
text-decoration: none;
border-radius: 2em;"))
}
# Styles n labels and combine them in a span
style_labels <- function(x) {
span(map(x, style_label))
}
```
PERSONAL
==============================================
```{r table_prep}
# filter out dependabot
user_issues_dependabot <- user_issues %>%
dplyr::mutate(dependabot = purrr::map(.data$labels, ~purrr::pluck(.x, 1, "name"))) %>%
dplyr::filter(.data$dependabot == "dependencies") %>%
dplyr::select(-dependabot)
user_issues_out <- user_issues %>%
anti_join(user_issues_dependabot)
user_issue_tbl <- user_issues_out %>%
reactable(
highlight = TRUE,
searchable = TRUE,
# Stopping long lines of text wrapping to keep table height consistent
wrap = FALSE,
# Personally customized to fit my screen size and zoom level
defaultPageSize = 18,
minRows = 18,
# Sort table by such that most recently updated issue is at the top by default
defaultSorted = "updated_at",
defaultSortOrder = "desc",
# Sets the searchbar to be 100% width
theme = reactableTheme(
searchInputStyle = list(width = "100%")
),
# All columns have Custom Set Name
# All but last column have pre-specified width set
# Cell modification is done with functions
# Columns which uses html formatting have `html = TRUE` to render html
columns = list(
title = colDef(
name = "Title",
width = 500,
html = TRUE
),
repository = colDef(
name = "Repository",
width = 250,
cell = extract_github_url,
html = TRUE,
),
comments = colDef(
name = "Comments",
width = 100
),
created_at = colDef(
name = "Created",
width = 120,
cell = date_format,
filterable = FALSE
),
updated_at = colDef(
name = "Updated",
width = 120,
cell = date_format,
filterable = FALSE
),
labels = colDef(
name = "Labels",
cell = style_labels,
html = TRUE,
filterable = FALSE
)
)
)
user_dependabot_tbl <- user_issues_dependabot %>%
reactable(
highlight = TRUE,
searchable = TRUE,
# Stopping long lines of text wrapping to keep table height consistent
wrap = FALSE,
# Personally customized to fit my screen size and zoom level
defaultPageSize = 18,
minRows = 18,
# Sort table by such that most recently updated issue is at the top by default
defaultSorted = "updated_at",
defaultSortOrder = "desc",
# Sets the searchbar to be 100% width
theme = reactableTheme(
searchInputStyle = list(width = "100%")
),
# All columns have Custom Set Name
# All but last column have pre-specified width set
# Cell modification is done with functions
# Columns which uses html formatting have `html = TRUE` to render html
columns = list(
title = colDef(
name = "Title",
width = 500,
html = TRUE
),
repository = colDef(
name = "Repository",
width = 250,
cell = extract_github_url,
html = TRUE,
),
comments = colDef(
name = "Comments",
width = 100
),
created_at = colDef(
name = "Created",
width = 120,
cell = date_format,
filterable = FALSE
),
updated_at = colDef(
name = "Updated",
width = 120,
cell = date_format,
filterable = FALSE
),
labels = colDef(
name = "Labels",
cell = style_labels,
html = TRUE,
filterable = FALSE
)
)
)
```
### User Issues - Excluding Dependabot
```{r user_issue_table}
user_issue_tbl
```
### User Issues - Dependabot
```{r user_dependabot_table}
user_dependabot_tbl
```
ORGANIZATIONS
==============================================
```{r}
org_issues %>%
reactable(
highlight = TRUE,
searchable = TRUE,
# Stopping long lines of text wrapping to keep table height consistent
wrap = FALSE,
# Personally customized to fit my screen size and zoom level
defaultPageSize = 18,
minRows = 18,
# Sort table by such that most recently updated issue is at the top by default
defaultSorted = "updated_at",
defaultSortOrder = "desc",
# Sets the searchbar to be 100% width
theme = reactableTheme(
searchInputStyle = list(width = "100%")
),
# All columns have Custom Set Name
# All but last column have pre-specified width set
# Cell modification is done with functions
# Columns which uses html formatting have `html = TRUE` to render html
columns = list(
title = colDef(
name = "Title",
width = 500,
html = TRUE
),
repository = colDef(
name = "Repository",
width = 250,
cell = extract_github_url,
html = TRUE,
),
comments = colDef(
name = "Comments",
width = 100
),
created_at = colDef(
name = "Created",
width = 120,
cell = date_format,
filterable = FALSE
),
updated_at = colDef(
name = "Updated",
width = 120,
cell = date_format,
filterable = FALSE
),
labels = colDef(
name = "Labels",
cell = style_labels,
html = TRUE,
filterable = FALSE
)
)
)
```