-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgithub-dashboard.Rmd
More file actions
173 lines (138 loc) · 4.61 KB
/
github-dashboard.Rmd
File metadata and controls
173 lines (138 loc) · 4.61 KB
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
---
title: "`r sprintf('GitHub Dashboard for [%s] on [%s]', Sys.getenv('GITHUB_USER'), Sys.Date())`"
output:
flexdashboard::flex_dashboard:
theme: yeti
orientation: rows
vertical_layout: scroll
---
```{r setup, include=FALSE}
library(flexdashboard)
library(gh) # devtools::install_github("r-pkgs/gh")
library(anytime)
library(tidyverse)
library(DT)
library(knitr)
```
```{r dev, echo=FALSE, include=FALSE}
USER <- Sys.getenv('GITHUB_USER')
user <- gh("/users/:user", user=USER)
repos <- gh("/users/:user/repos", user=USER, .limit = Inf)
issues <- gh("/user/issues", .limit = Inf)
```
```{r dev2, echo=FALSE, include=FALSE}
map_df(repos, ~.[c("name", "html_url", "stargazers_count", "forks_count", "has_issues",
"open_issues", "updated_at", "pushed_at")]) %>%
mutate(updated_at = anytime(pushed_at, asUTC=TRUE), pushed_at = NULL) -> repos_df
map_df(issues, function(x) {
c(list(repo_name = x$repository$full_name,
repo_url = x$repository$html_url,
user_login = x$user$login,
user_url = x$user$url),
x[c("html_url", "number", "state", "updated_at", "created_at", "title", "body")])
}) %>%
mutate(updated_at = anytime(created_at, asUTC=TRUE), created_at = NULL) -> issues_df
```
```{r include=FALSE}
options(
DT.options =
list(
pageLength = 25,
language = list(search = 'Filter:'),
dom = 'Bfrtip',
bInfo = FALSE)
)
pretty_diff <- function(rel) {
map_chr(rel, function(x) {
x <- Sys.time() - as.POSIXct(x, tz=Sys.timezone())
y <- unclass(x)
attr(y, "units") <- NULL
# sprintf("%3.2f %s", abs(y), attr(x, "units"))
paste(format(abs(y), digits = 0, nsmall = 2), attr(x, "units"))
})
}
repos_df %>%
mutate(Repository = sprintf('<a href="%s">%s</a>', html_url, name)) %>%
rename(Stars = stargazers_count, Forks = forks_count,
`Issues` = open_issues) %>%
select(Repository, everything(), -name, -html_url, -has_issues) -> repos_df
issues_df %>%
rename(Title=title) %>%
mutate(Repository = sprintf('<a href="%s">%s</a>', repo_url, repo_name),
`Submitted by` = sprintf('<a href="%s">%s</a>', user_url, user_login),
`Issue #` = sprintf('<a href="%s">#%s</a>', html_url, number),
Age = pretty_diff(updated_at)) -> issues_df
```
Overview
=====================================
Row
-----------------------------------------------------------------------
### Total Repos
```{r}
valueBox(scales::comma(nrow(repos_df)),
icon = "fa-github")
```
### Open Issues
```{r}
valueBox(scales::comma(nrow(filter(issues_df, state == "open"))),
icon = "fa-exclamation-triangle")
```
### Total Stars
```{r}
valueBox(scales::comma(sum(repos_df$Stars)),
icon = "fa-star")
```
Row
-----------------------------------------------------------------------
### Top 10 Repos (sorted initially by stargazers)
```{r}
arrange(repos_df, desc(Stars)) %>%
head(10) %>%
select(-updated_at) %>%
datatable(options = list(bFilter=FALSE, paging=FALSE), escape=FALSE, filter="none")
```
Row
-----------------------------------------------------------------------
### Repos by time of last activity
```{r}
arrange(repos_df, desc(updated_at)) %>%
select(Repository, Age=updated_at, Stars, Forks, Issues) %>%
mutate(Age=pretty_diff(Age)) %>%
datatable(escape=FALSE,
options = list(columnDefs = list(list(className = 'dt-right', targets = 2:5))))
```
Row
-----------------------------------------------------------------------
### Open issues by date
```{r}
filter(issues_df, state == "open") %>%
arrange(desc(updated_at)) %>%
select(Repository, `Submitted by`, Title, `Issue #`, Age) %>%
datatable(escape=FALSE,
options = list(columnDefs = list(list(className = 'dt-right', targets = c(4:5)))))
```
> `r sprintf("%s total open issues", scales::comma(nrow(filter(issues_df, state == "open"))))`
Recent Issue Detail
=====================================
```{r issue_detail, include=FALSE}
options(knitr.duplicate.label = 'allow')
issues_df %>%
mutate(hr_diff = as.numeric(difftime(Sys.time(),
issues_df$updated_at,
units = "hours"))) %>%
filter(hr_diff <= 48) %>%
arrange(hr_diff) -> recent_issues
if (nrow(recent_issues) == 0) {
out <- "### No new issues in the past 48 hours"
} else {
out <- NULL
cat("", file = "/tmp/k.txt")
for (i in 1:nrow(recent_issues)) {
res <- knit_child('issue_detail.Rmd', envir=parent.frame())
cat(res, file="/tmp/k.txt", append = TRUE)
out <- c(out, res)
}
}
options(knitr.duplicate.label = 'no way')
```
`r paste(out, sep=" ", collapse="\n")`