-
Notifications
You must be signed in to change notification settings - Fork 7
/
get_commits.R
49 lines (40 loc) · 1.57 KB
/
get_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
get_commits <- function(path, distinct = TRUE, filter = TRUE,
users = c("l.zappia", "lazappi", "Luke Zappia"),
from = "2016-02-08") {
dirs <- fs::dir_ls(path, type = "directory")
message("Searching ", length(dirs), " directories...")
commits <- purrr::map_dfr(dirs, function(dir) {
message("Processing ", fs::path_file(dir), "...")
if (git2r::in_repository(dir)) {
commits_list <- git2r::commits(dir)
if (length(commits_list) > 0) {
dir_commits <- purrr::map_dfr(commits_list, function(commit) {
tibble::tibble(
SHA = commit$sha,
Name = commit$author$name,
When = lubridate::as_datetime(commit$author$when$time)
)
})
dir_commits$Repository <- fs::path_file(dir)
return(dir_commits)
}
}
})
message("Found ", nrow(commits), " commits")
if (distinct) {
message("Selecting distinct SHAs...")
commits <- dplyr::distinct(commits, SHA, .keep_all = TRUE)
message("Found ", nrow(commits), " distinct commits")
}
message("Filtering dates...")
commits <- dplyr::filter(commits, When >= from)
message("Found ", nrow(commits), " from ", from)
if (filter) {
message("Filtering names...")
commits <- dplyr::filter(
commits, Name %in% users
)
message("Found ", nrow(commits), " commits by me")
}
return(commits)
}