-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-repo-names.R
54 lines (43 loc) · 1.42 KB
/
01-repo-names.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
# Purpose: fetch GitHub repo information and extract repo names
#' Get GitHub Repo Information for a Named User
#'
#' Uses \code{\link[gh]{gh}} to access the GitHub API and get the details for
#' all of a named user's repos. To use this function you need to have created a
#' GitHub account and to have put a GitHub Personal Access Token (PAT) in your
#' .Renviron. See
#' \href{https://happygitwithr.com/github-pat.html}{Happy Git and GitHub for the UseR}
#' for more information.
#'
#' @param gh_user Character string. A GitHub username.
#'
#' @return A gh_response (list) object.
ghd_get_repos <- function(gh_user) {
cli::cli_alert_info("Fetching GitHub repos for user '{gh_user}'. ")
# Get repos for username
user_repos <-
gh::gh(
endpoint = "/users/:username/repos",
username = gh_user,
.limit = Inf # get all repos
)
cli::cli_alert_success("Found {length(user_repos)} repos.")
return(user_repos)
}
#' Extract Names of GitHub Repos
#'
#' Extract all the 'name' elements from a gh_response object. These are the
#' names of all the GitHub repos.
#'
#' @param repo_object A gh_response object, as returned by
#' \code{\link{ghd_get_repos}}.
#'
#' @return A character vector of GitHub repo names.
ghd_extract_names <- function(repo_object) {
repo_names <-
purrr::map(
.x = repo_object,
.f = purrr::pluck("name")
)
repo_names_vec <- unlist(repo_names)
return(repo_names_vec)
}