-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgh-commits.R
139 lines (113 loc) · 3.9 KB
/
gh-commits.R
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
library(tidyverse)
library(gh)
library(lubridate)
library(glue)
library(usethis)
usethis::create_github_token()
gitcreds::gitcreds_set()
gh_token_help()
source('src/fetch_utils.R')
# fetch github repos for a user ----------------------------------------------------
user <- 'jordansread'
repos <- gh("GET /users/{username}/repos",
username = user,
.limit = Inf,
sort = "created")
repos
repo_info <- munge_repos(repos)
repo_info
write_csv(repo_info, 'out/gh_repos.csv')
# get list of contributors for each repo
## contributors, language
repo$language
# look at user commits ----------------------------------------------------
## to get repo-specific info need to know the owner
gh('GET /repos/USGS-R/dataRetrieval/contributors') # contributions
gh('GET /repos/USGS-R/dataRetrieval/languages') # breakdown
gh('GET /repos/USGS-R/dataRetrieval')
gh('GET /repos/jordansread/dataRetrieval')
# parent, full_name is the main repo that's forked
## fetch all commits by a user
all_commits <- map_dfr(repo_info$full_name, function(z){
name_split <- str_split(z, "/")
owner <- name_split[[1]][1]
repo <- name_split[[1]][2]
repo_commits <- gh_safe("/repos/:owner/:repo/commits",
owner = owner,
repo = repo,
author = user,
since = "2011-01-01T00:00:00Z",
until = "2022-12-11T00:00:00Z",
.limit = Inf, .progress = TRUE)
out <- parse_commit(repo_commits, repo = z)
return(out)
})
all_commits$commit_time
my_commits <- all_commits %>%
mutate(commit_time = with_tz(commit_time, tzone = 'America/Chicago')) %>%
mutate(
date = date(commit_time),
wday = wday(date, label = TRUE),
year = year(date),
month = month(date),
week = week(date)
) %>%
left_join(
repo_info,
by = c("repo" = "full_name")
)
all_commits$commit_time[1]
my_commits$commit_time[1]
my_commits$commit_time_test[1]
my_commits$commit_time_cst[1]
my_commits$name %>% unique # repos committed to
my_commits |> write_csv('out/commits_jordansread.csv')
## fixing the time - comapre to known tweet times
# create github heatmap ---------------------------------------------------
gh_pal <- c(green = "#28a745",light_green = "#dcffe4")
label_month <- my_commits %>%
group_by(month) %>%
summarize(week = min(week)) %>%
mutate(month_label = month(month, label = TRUE))
my_commits %>%
group_by(year, month, week, wday) %>%
summarize(n = length(message)) %>%
mutate(label_month = ifelse(week %in% label_month$week, month, NA)) %>%
ggplot() +
geom_tile(aes(x = week, y = wday, width = 0.9, height = 0.9, fill = n),
#fill = '#39d353'
) +
theme_classic() +
scale_y_discrete(expand = c(0, 0),
limits = rev(c('Sun','Mon','Tue','Wed','Thu','Fri','Sat'))) +
scale_x_discrete(expand = c(0, 0),
breaks = label_month$week,
labels = label_month$month_label) +
theme(
axis.title = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(color = 'red'),
panel.grid.minor.x = element_blank(),
legend.position = 'none',
strip.background = element_rect(color = NA),
#strip.text.y = element_text(angle = 0)
) +
facet_grid(year~., switch = 'both') +
coord_fixed(ratio = 1) +
scale_fill_gradient(low = gh_pal["light_green"], high = gh_pal["green"])
## year, week and day with most commits
my_commits %>%
group_by(year, month, week, wday) %>%
summarize(n = length(message)) %>%
arrange(desc(n))
## most repos
my_commits %>%
group_by(year) %>%
summarize(n_repos = length(unique(name))) %>%
arrange(desc(n_repos))
## most popular repos
## number of PRs, issues, code changed through time
## network of collaborators
## commit messages and issues