Skip to content

Commit e3c326b

Browse files
committed
Handle more than 100 results from repo branch query
1 parent 1e3594d commit e3c326b

File tree

7 files changed

+78
-49
lines changed

7 files changed

+78
-49
lines changed

DESCRIPTION

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: echogithub
22
Type: Package
33
Title: echoverse module: Extract data and metadata from GitHub
4-
Version: 0.99.2
4+
Version: 0.99.3
55
Authors@R:
66
c(person(given = "Brian",
77
family = "Schilder",
@@ -17,7 +17,12 @@ Authors@R:
1717
family = "Raj",
1818
role = c("aut"),
1919
email = "towfique.raj@mssm.edu",
20-
comment = c(ORCID = "0000-0002-9355-5704"))
20+
comment = c(ORCID = "0000-0002-9355-5704")),
21+
person(given = "Hiranyamaya",
22+
family = "Dash",
23+
role = c("ctb"),
24+
email = "hdash.work@gmail.com",
25+
comment = c(ORCID = "0009-0005-5514-505X"))
2126
)
2227
Description: echoverse module: Extract data and metadata from GitHub.
2328
URL: https://github.com/RajLabMSSM/echogithub
@@ -56,7 +61,7 @@ Suggests:
5661
Remotes:
5762
github::neurogenomics/cranlogs,
5863
github::neurogenomics/rworkflows
59-
RoxygenNote: 7.2.3
64+
RoxygenNote: 7.3.2
6065
VignetteBuilder: knitr
6166
License: GPL-3
6267
Config/testthat/edition: 3

NEWS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# echogithub 0.99.3
2+
3+
## Bug fixes
4+
5+
* `github_branches`
6+
- Handle repos with more than 100 branches.
7+
8+
19
# echogithub 0.99.2
210

311
## New features
@@ -68,4 +76,4 @@
6876
* Switched to using `gh` instead of `httr` to avoid API limits imposed by GitHub.
6977
- Kept `httr` as alternative method.
7078
* `is_url`:
71-
- Add `RCurl::url.exists` check.
79+
- Add `RCurl::url.exists` check.

R/github_branches.R

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#' GitHub branches
2-
#'
2+
#'
33
#' List all branches for a given GitHub repository.
4-
#' @param owner Owner of the GitHub repository.
4+
#' @param owner Owner of the GitHub repository.
55
#' If \code{NULL}, will automatically try to infer the owner
66
#' name from the \emph{DESCRIPTION file}
77
#' (assuming you're working directory is a local R package repo).
8-
#' @param repo GitHub repository name.
8+
#' @param repo GitHub repository name.
99
#' If \code{NULL}, will automatically try to infer the repo name
1010
#' name from the \emph{DESCRIPTION file}
1111
#' (assuming you're working directory is a local R package repo).
12-
#' @param branch [Optional] If \code{branch} is supplied
13-
#' (as a character vector of one or more branch names),
12+
#' @param branch [Optional] If \code{branch} is supplied
13+
#' (as a character vector of one or more branch names),
1414
#' will check to see if that branch exists. If it does, only that branch will
1515
#' be returned. If it doesn't, an error will be thrown.
1616
#' @param master_or_main If \code{branch} is supplied and
1717
#' is either \code{"master"} or \code{"main"},
18-
#' automatically interpret "master" and "main" as synonymous and return
19-
#' whichever branch exists.
18+
#' automatically interpret "master" and "main" as synonymous and return
19+
#' whichever branch exists.
2020
#' @param as_datatable Return the results as a \link[data.table]{data.table}
2121
#' (\code{TRUE}), or as a character vector of branch names
2222
#' (default: \code{FALSE}).
2323
#' @param error Throw an error when no matching branches are fond.
2424
#' @inheritParams github_files
2525
#' @inheritParams description_extract
2626
#' @returns Character vector or \link[data.table]{data.table} of branches.
27-
#'
27+
#'
2828
#' @export
2929
#' @importFrom gh gh_token gh
30-
#' @examples
30+
#' @examples
3131
#' branches <- github_branches(owner="RajLabMSSM", repo="echolocatoR")
3232
github_branches <- function(owner = NULL,
3333
repo = NULL,
@@ -37,36 +37,45 @@ github_branches <- function(owner = NULL,
3737
token = gh::gh_token(),
3838
desc_file = NULL,
3939
error = FALSE,
40-
verbose = TRUE){
40+
verbose = TRUE){
4141
name <- NULL;
42-
42+
4343
out <- infer_owner_repo(owner = owner,
44-
repo = repo,
45-
desc_file = desc_file,
44+
repo = repo,
45+
desc_file = desc_file,
4646
verbose = verbose)
4747
owner <- out$owner
48-
repo <- out$repo
48+
repo <- out$repo
4949
#### Search branches ####
5050
messager("Searching for all branches in:",paste(owner,repo,sep="/"),
5151
v=verbose)
5252
endpoint <- paste(
5353
"https://api.github.com/repos",owner,repo,"branches",
5454
sep="/"
5555
)
56-
gh_response <- gh::gh(endpoint = endpoint,
57-
.token = token,
58-
per_page = 100)
59-
dt <- gh_to_dt(gh_response)
60-
dt <- cbind(owner=owner, repo=repo, dt)
61-
#### Filter branches ####
62-
if(!is.null(branch)){
63-
#### Detect synonymous branches ####
64-
if(isTRUE(master_or_main) &&
65-
any(c("master","main") %in% branch)){
66-
branch <- unique(c("master","main",branch))
67-
}
68-
dt <- dt[name %in% branch,]
56+
page <- 1
57+
repeat {
58+
# Keep iterating pages until we find the branch or run out of pages
59+
gh_response <- gh::gh(endpoint = endpoint,
60+
.token = token,
61+
per_page = 100,
62+
page = page)
63+
if(length(gh_response) == 0) break
64+
dt <- gh_to_dt(gh_response)
65+
dt <- cbind(owner=owner, repo=repo, dt)
66+
#### Filter branches ####
67+
if(!is.null(branch)){
68+
#### Detect synonymous branches ####
69+
if(isTRUE(master_or_main) &&
70+
any(c("master","main") %in% branch)){
71+
branch <- unique(c("master","main",branch))
72+
}
73+
dt <- dt[name %in% branch,]
74+
}
75+
if(nrow(dt)>0) break
76+
page <- page + 1
6977
}
78+
7079
#### Report ####
7180
if(nrow(dt)>0){
7281
messager(paste0(
@@ -78,9 +87,9 @@ github_branches <- function(owner = NULL,
7887
if(isTRUE(error)) {
7988
stop(stp)
8089
} else {
81-
messager("WARNING:",stp,"Returning NULL.",v=verbose)
90+
messager("WARNING:",stp,"Returning NULL.",v=verbose)
8291
return(NULL)
83-
}
92+
}
8493
}
8594
#### Return ####
8695
if(isTRUE(as_datatable)){

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<img src='https://github.com/RajLabMSSM/echogithub/raw/master/inst/hex/hex.png' title='Hex sticker for echogithub' height='300'><br>
22
[![License:
33
GPL-3](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://cran.r-project.org/web/licenses/GPL-3)
4-
[![](https://img.shields.io/badge/devel%20version-0.99.2-black.svg)](https://github.com/RajLabMSSM/echogithub)
4+
[![](https://img.shields.io/badge/devel%20version-0.99.3-black.svg)](https://github.com/RajLabMSSM/echogithub)
55
[![](https://img.shields.io/github/languages/code-size/RajLabMSSM/echogithub.svg)](https://github.com/RajLabMSSM/echogithub)
66
[![](https://img.shields.io/github/last-commit/RajLabMSSM/echogithub.svg)](https://github.com/RajLabMSSM/echogithub/commits/master)
77
<br> [![R build
88
status](https://github.com/RajLabMSSM/echogithub/workflows/rworkflows/badge.svg)](https://github.com/RajLabMSSM/echogithub/actions)
9-
[![](https://codecov.io/gh/RajLabMSSM/echogithub/branch/master/graph/badge.svg)](https://codecov.io/gh/RajLabMSSM/echogithub)
9+
[![](https://codecov.io/gh/RajLabMSSM/echogithub/branch/master/graph/badge.svg)](https://app.codecov.io/gh/RajLabMSSM/echogithub)
1010
<br>
1111
<a href='https://app.codecov.io/gh/RajLabMSSM/echogithub/tree/master' target='_blank'><img src='https://codecov.io/gh/RajLabMSSM/echogithub/branch/master/graphs/icicle.svg' title='Codecov icicle graph' width='200' height='50' style='vertical-align: top;'></a>
1212
<h4>
13-
Authors: <i>Brian Schilder, Jack Humphrey, Towfique Raj</i>
13+
Authors: <i>Brian Schilder, Jack Humphrey, Towfique Raj, Hiranyamaya
14+
Dash</i>
1415
</h4>
1516
<h5>
16-
README updated: <i>Mar-10-2023</i>
17+
README updated: <i>Dec-03-2024</i>
1718
</h5>
1819

1920
## `echogithub`: Extract data and metadata from GitHub.

man/description_extract.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/github_branches.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-github_files.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
test_that("github_files works", {
1+
test_that("github_files works", {
22

3-
# files <- github_files(owner = "RajLabMSSM",
4-
# repo = "Fine_Mapping_Shiny",
5-
# query = ".md$",
6-
# download = TRUE)
7-
# testthat::expect_true(methods::is(files, "data.table"))
8-
# testthat::expect_true(nrow(files)>=1)
3+
files <- github_files(owner = "RajLabMSSM",
4+
repo = "Fine_Mapping_Shiny",
5+
query = ".md$",
6+
download = TRUE)
7+
testthat::expect_true(methods::is(files, "data.table"))
8+
testthat::expect_true(nrow(files)>=1)
99
})

0 commit comments

Comments
 (0)