-
Notifications
You must be signed in to change notification settings - Fork 2
/
gh-repo-info.R
115 lines (99 loc) · 3.3 KB
/
gh-repo-info.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
# Library ----
#library(gh)
#library(memoise)
#library(purrr)
#library(dplyr)
#library(tidyr)
#library(glue)
#library(readr)
# gh functions ----------------------------------------------------------------------------------------------------------------------------------
#' gh_workflows
#'
#' Function to create a memorized copy of the repository cache.
#'
#' @param owner repository's owner
#' @param repo repository's name
#' @param ... others paramaters
#'
#' @return
#' @export
gh_workflows <- memoise::memoise(function(owner, repo, ...) {
gh::gh("/repos/{owner}/{repo}/actions/workflows", owner = owner, repo = repo, private = TRUE) %>%
.$workflows
}, cache = memoise::cache_memory())
#' gh_runs
#'
#' Function to create a memorized copy of the repository wokflow id.
#'
#' @param owner repository's owner
#' @param repo repository's name
#' @param workflow_id workflow id
#' @param ... others paramaters
#' @return
#' @export
gh_runs <- memoise::memoise(function(owner, repo, workflow_id, ...) {
lst <- gh::gh(
"/repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs",
owner = owner,
repo = repo,
workflow_id = workflow_id,
per_page = 1,
private = TRUE
)$workflow_runs
if (length(lst) > 0) {
lst <- lst[[1]]
}
lst
}, cache = memoise::cache_memory())
#' gh_url
#'
#' Function to create a memorized copy of the repository url.
#'
#' @param url repository's url
#' @return
#' @export
gh_url <- memoise::memoise(function(url) {
gh::gh(url)
}, cache = memoise::cache_memory())
# get repos -------------------------------------------------------------------------------------------------------------------------------------
#' gh_url
#'
#' Function that creates csv with status repositories.
#'
#' @param repos list of repositories
#' @return
#' @export
gh_get_repo_status <- function(repos) {
repos <- purrr::map_dfr(repos, ~ tibble::tibble(repo = .), .id = "owner")
# repos$repo
repos$workflows <- repos %>% purrr::pmap(gh_workflows)
repos <- repos %>%
tidyr::unnest(workflows) %>%
dplyr::mutate(
workflow_id = purrr::map_chr(workflows, "id"),
badge_url = purrr::map_chr(workflows, "badge_url")
)
repos$runs <- purrr::pmap(repos, gh_runs)
# browser()
repos <- repos %>%
dplyr::filter(purrr::map_int(runs, length) > 0) %>%
dplyr::mutate(
html_url_run = purrr::map_chr(runs, "html_url"),
run_conclusion = purrr::map_chr(runs, ~{if(is.null(.x[["conclusion"]])) "" else .x[["conclusion"]]}),
commit_message = purrr::map_chr(runs, ~ .x$head_commit$message),
commit_id = purrr::map_chr(runs, `[[`, c("head_commit", "id")),
repo_name = purrr::map_chr(runs, `[[`, c("head_repository", "full_name")),
html_url_repo = purrr::map_chr(runs, `[[`, c("head_repository", "html_url")),
.repo = purrr::map(purrr::map_chr(runs, `[[`, c("head_repository", "url")), gh_url),
stargazers_count = purrr::map_dbl(.repo, "stargazers_count"),
watchers_count = purrr::map_dbl(.repo, "watchers_count"),
open_issues_count = purrr::map_dbl(.repo, "open_issues_count"),
forks_count = purrr::map_dbl(.repo, "forks_count"),
open_issues_count = purrr::map_dbl(.repo, "open_issues_count")
)
repos %>%
dplyr::select(-where(is.list)) %>%
dplyr::arrange(repo_name) %>%
readr::write_csv("repos.csv")
repos
}