Skip to content

Commit 1e3594d

Browse files
committed
Pass up .limit in all functions
1 parent c21ab73 commit 1e3594d

33 files changed

+556
-35
lines changed

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export(add_owner_repo)
44
export(description_extract)
55
export(github_branches)
6+
export(github_code)
67
export(github_commits)
78
export(github_dependencies)
89
export(github_dependents)
@@ -13,12 +14,15 @@ export(github_pages)
1314
export(github_pages_files)
1415
export(github_pages_vignettes)
1516
export(github_permissions)
17+
export(github_repositories)
1618
export(github_traffic)
19+
export(github_user_events)
1720
export(github_workflows)
1821
export(r_repos)
1922
export(r_repos_data)
2023
export(r_repos_downloads)
2124
export(r_repos_opts)
25+
export(r_repos_upset_queries)
2226
importFrom(RCurl,url.exists)
2327
importFrom(data.table,":=")
2428
importFrom(data.table,.SD)
@@ -31,6 +35,7 @@ importFrom(data.table,merge.data.table)
3135
importFrom(data.table,rbindlist)
3236
importFrom(data.table,setnafill)
3337
importFrom(data.table,setnames)
38+
importFrom(data.table,setorderv)
3439
importFrom(gh,gh)
3540
importFrom(gh,gh_token)
3641
importFrom(methods,is)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
- `echogithub::readme_header` --> `rworkflows::use_badges`
99
* `r_repos_data`
1010
- Add new arg `add_hex` to find hex URL with `rworkflows::get_hex`.
11+
* `r_repos`
12+
- New arg `queries`
13+
* New functions:
14+
- `github_user_events`
15+
* Expose `.limit` arg wherever relevant.
1116

1217
## Bug fixes
1318

R/github_code.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' GitHub code
2+
#'
3+
#' Search for GitHub code using specific queries.
4+
#' @source
5+
#' \href{https://docs.github.com/en/search-github/searching-on-github/searching-code}{
6+
#' GitHub Docs: Searching code}
7+
#' @inheritParams github_files
8+
#' @inheritParams gh::gh
9+
#'
10+
#' @export
11+
#' @importFrom gh gh gh_token
12+
#' @importFrom data.table :=
13+
#' @importFrom methods is
14+
#' @examples
15+
#' \dontrun{
16+
#' ## easily exceeds API limit
17+
#' repos <- github_code(query="Package path:DESCRIPTION", .limit=5)
18+
#' }
19+
github_code <- function(query,
20+
token = gh::gh_token(),
21+
.limit = Inf,
22+
verbose = TRUE){
23+
owner_repo <- repo <- NULL;
24+
25+
endpoint <- "https://api.github.com/search/code"
26+
res <- gh::gh(endpoint,
27+
.token = token,
28+
.limit = .limit,
29+
q = query,
30+
#### only beta version supports full-on regex ####
31+
# q = "/(?-i)Package/ path:/(?-i)^DESCRIPTION$/",
32+
per_page = 100)
33+
dt <- gh_to_dt(gh_response = res$items,
34+
verbose = verbose)
35+
dt[,owner_repo:=mapply(repo, FUN=function(x){x$name})]
36+
messager("Returning",formatC(nrow(dt),big.mark = ","),
37+
"GitHub code files.",v=verbose)
38+
return(dt)
39+
}
40+

R/github_commits.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
#'
33
#' Get metadata for all commits to a given GitHub repo.
44
#' @inheritParams github_files
5+
#' @inheritParams gh::gh
56
#' @return A nested list of metadata
67
#'
78
#' @export
89
#' @importFrom gh gh gh_token
910
#' @examples
1011
#' commits <- github_commits(owner="RajLabMSSM",
11-
#' repo="echolocatoR")
12+
#' repo="echolocatoR",
13+
#' limit=100)
1214
github_commits <- function(owner,
1315
repo,
1416
token = gh::gh_token(),
17+
.limit = Inf,
1518
verbose = TRUE) {
1619

1720
#devoptera::args2vars(github_commits)
@@ -20,7 +23,7 @@ github_commits <- function(owner,
2023
owner,repo,"commits",sep="/")
2124
gh_response <- gh::gh(endpoint = endpoint,
2225
.token = token,
23-
.limit = Inf,
26+
.limit = .limit,
2427
per_page = 100)
2528
dt <- gh_to_dt(gh_response)
2629
return(dt)

R/github_files.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#' @param verbose Print messages.
3232
#' @inheritParams github_files_download
3333
#' @inheritParams base::grepl
34+
#' @inheritParams gh::gh
3435
#'
3536
#' @return A list of paths.
3637
#'
@@ -47,6 +48,7 @@ github_files <- function(owner,
4748
ignore.case = FALSE,
4849
method = "gh",
4950
token = gh::gh_token(),
51+
.limit = Inf,
5052
download = FALSE,
5153
download_dir = tempdir(),
5254
overwrite = FALSE,
@@ -77,6 +79,7 @@ github_files <- function(owner,
7779
repo = repo,
7880
branch = branch,
7981
token = token,
82+
.limit = .limit,
8083
verbose = verbose)
8184
}
8285
#### Return NULL early ####

R/github_files_gh.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#' List files in GitHub repo: via \pkg{gh}
22
#'
33
#' Search for files within a public GitHub repository and return their paths.
4-
#' @inheritParams github_files
54
#' @source \href{https://docs.github.com/en/rest/overview/endpoints-available-for-github-apps}{
65
#' GitHub endpoints}
76
#' @source \href{https://docs.github.com/en/rest/git/trees#get-a-tree-recursively}{
87
#' GitHub trees API}
8+
#' @inheritParams github_files
9+
#' @inheritParams gh::gh
910
#' @returns A \link[data.table]{data.table} fo file paths.
1011
#'
1112
#' @keywords internal
@@ -15,6 +16,7 @@ github_files_gh <- function(owner,
1516
repo,
1617
branch = c("master","main"),
1718
token = gh::gh_token(),
19+
.limit = Inf,
1820
verbose = TRUE) {
1921
path <- link <- NULL;
2022

@@ -29,6 +31,7 @@ github_files_gh <- function(owner,
2931
)
3032
gh_response <- gh::gh(endpoint = endpoint,
3133
.token = token,
34+
.limit = .limit,
3235
per_page = 100)
3336
dt <- gh_to_dt(gh_response$tree)
3437
dt[,link:=paste("https://github.com",owner,repo,

R/github_metadata.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#' @param add_traffic Add traffic metadata
55
#' with \link[echogithub]{github_traffic}.
66
#' @inheritParams github_files
7+
#' @inheritParams gh::gh
78
#' @return A \link[data.table]{data.table}.
89
#'
910
#' @export
@@ -16,6 +17,7 @@ github_metadata <- function(owner,
1617
repo,
1718
add_traffic = FALSE,
1819
token = gh::gh_token(),
20+
.limit = Inf,
1921
verbose = TRUE) {
2022

2123
#devoptera::args2vars(github_metadata)
@@ -37,6 +39,7 @@ github_metadata <- function(owner,
3739
owner,repo,sep="/")
3840
gh_response <- gh::gh(endpoint = endpoint,
3941
.token = token,
42+
.limit = .limit,
4043
per_page = 100)
4144
dt <- cbind(
4245
owner=owner,

R/github_pages.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' @param error Throw an error when the GitHub repository does not exist
66
#' (default: \code{TRUE}).
77
#' @inheritParams github_files
8+
#' @inheritParams gh::gh
89
#'
910
#' @export
1011
#' @importFrom gh gh gh_token
@@ -15,13 +16,15 @@ github_pages <- function(owner,
1516
repo,
1617
error = TRUE,
1718
token = gh::gh_token(),
19+
.limit = Inf,
1820
verbose = TRUE){
1921

2022
endpoint <- paste("https://api.github.com","repos",
2123
owner,repo,"pages",sep="/")
2224
res <- tryCatch({
2325
gh::gh(endpoint = endpoint,
2426
.token = token,
27+
.limit = .limit,
2528
per_page = 100)
2629
}, error = function(e){return(e)})
2730
#### Stop if the repo doesn't exist #####

R/github_pages_files.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#' @param local_repo Search a cloned local folder of a git repo instead of
88
#' the remote GitHub repo. If not \code{NULL}, expects a path to the local repo.
99
#' @inheritParams github_files
10+
#' @inheritParams gh::gh
1011
#'
1112
#' @export
1213
#' @importFrom data.table := fwrite data.table
13-
#' @examples
14-
#' dt <- github_pages_files(owner="RajLabMSSM", repo="echolocatoR")
14+
#' @examples
15+
#' dt <- github_pages_files(owner="RajLabMSSM",
16+
#' repo="echolocatoR",
17+
#' .limit=5)
1518
github_pages_files <- function(owner,
1619
repo,
1720
branch = "gh-pages",
@@ -20,6 +23,7 @@ github_pages_files <- function(owner,
2023
local_repo = NULL,
2124
save_path = NULL,
2225
token = gh::gh_token(),
26+
.limit = Inf,
2327
verbose = TRUE) {
2428

2529
link_ghpages_index <- link_ghpages <- link_html <- path <- NULL;
@@ -35,6 +39,7 @@ github_pages_files <- function(owner,
3539
query = query,
3640
branch = branch,
3741
token = token,
42+
.limit = .limit,
3843
verbose = verbose)
3944
} else {
4045
dt <- data.table::data.table(

R/github_repositories.R

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#' GitHub repositories
2+
#'
3+
#' Search for GitHub repositories using specific queries.
4+
#' @source
5+
#' \href{https://docs.github.com/en/rest/search#search-repositories}{
6+
#' GitHub Docs: Search repositories}
7+
#' @source
8+
#' \href{https://docs.github.com/en/rest/search#constructing-a-search-query}{
9+
#' GitHub Docs: Constructing a search query}
10+
#' @source
11+
#' \href{https://docs.github.com/en/search-github/searching-on-github/searching-for-repositories}{
12+
#' Searching GitHub repos}
13+
#' @source
14+
#' \href{https://github.com/orgs/community/discussions/9759}{
15+
#' Case-sensitive GitHub searches}
16+
#' @source \href{https://github.com/r-lib/gh/pull/136}{
17+
#' Examples of using gh to search repositories}
18+
#' @inheritParams github_files
19+
#' @inheritParams gh::gh
20+
#'
21+
#' @export
22+
#' @importFrom gh gh gh_token
23+
#' @importFrom data.table :=
24+
#' @importFrom methods is
25+
#' @examples
26+
#' repos <- github_repositories(query="language:r", .limit=100)
27+
github_repositories <- function(query,
28+
token = gh::gh_token(),
29+
.limit = Inf,
30+
verbose = TRUE){
31+
owner_repo <- repo <- NULL;
32+
33+
endpoint <- "https://api.github.com/search/repositories"
34+
res <- gh::gh(endpoint,
35+
.token = token,
36+
.limit = .limit,
37+
per_page = 100,
38+
q = paste(query, collapse = " ")
39+
)
40+
dt <- gh_to_dt(gh_response = res$items,
41+
verbose = verbose)
42+
dt[,owner_repo:=mapply(repo, FUN=function(x){x$name})]
43+
messager("Returning",formatC(nrow(dt),big.mark = ","),
44+
"GitHub repositories.",v=verbose)
45+
return(dt)
46+
}
47+
48+
# make_query <- function(query,
49+
# sep = ":",
50+
# collapse = " ",
51+
# encode=FALSE) {
52+
# txt <- paste(names(query),
53+
# query,
54+
# sep = sep, collapse = collapse)
55+
# if(encode) utils::URLencode(txt, reserved=TRUE) else {txt}
56+
# }
57+
# endpoint <- paste0("https://api.github.com/",
58+
# "search?q=", make_query(query, encode = TRUE))
59+
# url <- httr::modify_url("https://api.github.com",
60+
# path = "search/",
61+
# query = list(q = make_query(query)))
62+
# req <- httr::GET(url = url)
63+
# cont <- httr::content(req)
64+
# dt <- gh_to_dt(gh_response = cont$items,
65+
# verbose = verbose)

R/github_traffic.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#' Get traffic info on a target GitHub repository.
44
#' @param na_fill Value to fill NAs with.
55
#' @inheritParams github_files
6+
#' @inheritParams gh::gh
67
#' @return A \link[data.table]{data.table}.
78
#'
89
#' @export
@@ -14,6 +15,7 @@
1415
github_traffic <- function(owner,
1516
repo,
1617
token = gh::gh_token(),
18+
.limit = Inf,
1719
na_fill = NULL,
1820
verbose = TRUE) {
1921

@@ -38,7 +40,7 @@ github_traffic <- function(owner,
3840
owner,repo,"traffic","clones",sep="/")
3941
ghr_clones <- gh::gh(endpoint = endpoint,
4042
.token = token,
41-
.limit = Inf,
43+
.limit = .limit,
4244
per_page = 100)
4345
clones <- data.table::data.table(
4446
clones_count=ghr_clones$count,

0 commit comments

Comments
 (0)