Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 41f61df

Browse files
committed
fix #71 gist() can get a specfic revision, bump dev ver
1 parent 54a5cba commit 41f61df

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Description: Work with 'GitHub' 'gists' from 'R' (e.g.,
1010
'gist' 'commits', and get rate limit information when 'authenticated'. Some
1111
requests require authentication and some do not. 'Gists' website:
1212
<https://gist.github.com/>.
13-
Version: 0.4.1.9310
13+
Version: 0.4.1.9313
1414
Authors@R: c(
1515
person("Scott", "Chamberlain", role = c("aut", "cre"), email = "myrmecocystus@gmail.com"),
1616
person("Ramnath", "Vaidyanathan", role = "aut"),

R/gist.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' @export
44
#' @param id (character) A gist id, or a gist URL
5+
#' @param revision (character) A sha. optional
56
#' @param x Object to coerce. Can be an integer (gist id), string
67
#' (gist id), a gist, or an list that can be coerced to a gist.
78
#' @template all
@@ -17,6 +18,13 @@
1718
#' as.gist('f1403260eb92f5dfa7e1')
1819
#' as.gist(10)
1920
#' as.gist(gist('f1403260eb92f5dfa7e1'))
21+
#'
22+
#' # get a specific revision of a gist
23+
#' id <- 'c1e2cb547d9f22bd314da50fe9c7b503'
24+
#' gist(id, 'a5bc5c143beb697f23b2c320ff5a8dacf960b0f3')
25+
#' gist(id, 'b70d94a8222a4326dff46fc85bc69d0179bd1da2')
26+
#' gist(id, '648bb44ab9ae59d57b4ea5de7d85e24103717e8b')
27+
#' gist(id, '0259b13c7653dc95e20193133bcf71811888cbe6')
2028
#'
2129
#' # from a url, or partial url
2230
#' x <- "https://gist.github.com/expersso/4ac33b9c00751fddc7f8"
@@ -42,8 +50,10 @@
4250
#' # httr::GET(url)
4351
#' }
4452

45-
gist <- function(id, ...){
46-
res <- gist_GET(switch_url('id', normalize_id(id)), gist_auth(), ghead(), ...)
53+
gist <- function(id, revision = NULL, ...){
54+
url <- switch_url('id', normalize_id(id))
55+
if (!is.null(revision)) url <- file.path(url, revision)
56+
res <- gist_GET(url, gist_auth(), ghead(), ...)
4757
as.gist(res)
4858
}
4959

man/gist.Rd

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

tests/testthat/test-gist.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ test_that("as.gist works - on random sample of gist ids", {
2525
}))
2626
})
2727

28+
test_that("gist works getting a specific revision", {
29+
skip_on_cran()
30+
31+
id <- 'c1e2cb547d9f22bd314da50fe9c7b503'
32+
rev1 <- gist(id, 'a5bc5c143beb697f23b2c320ff5a8dacf960b0f3')
33+
rev2 <- gist(id, 'b70d94a8222a4326dff46fc85bc69d0179bd1da2')
34+
35+
expect_false(
36+
identical(
37+
rev1$files$clean_species.R$content,
38+
rev2$files$clean_species.R$content
39+
)
40+
)
41+
expect_match(rev1$id, rev2$id)
42+
})
43+
2844
test_that("httr config options work", {
2945
skip_on_cran()
3046

0 commit comments

Comments
 (0)