Minimalistic GitHub API client in R
Clone or download
jennybc Merge pull request #83 from r-lib/disown
Mod CODEOWNERS to stop auto-request
Latest commit a8b6453 Jul 8, 2018
Permalink
Failed to load latest commit information.
.github Mod CODEOWNERS to stop auto-request Jul 8, 2018
R Allow responses to be written directly to disk (#77) Feb 21, 2018
inst Allow responses to be written directly to disk (#77) Feb 21, 2018
man Allow responses to be written directly to disk (#77) Feb 21, 2018
tests Allow responses to be written directly to disk (#77) Feb 21, 2018
.Rbuildignore Add CODEOWNERS (#81) Jun 18, 2018
.gitignore API tests using httrmock Nov 9, 2016
.travis.yml Set aside httrmock temporarily Jul 12, 2017
DESCRIPTION
LICENSE Add Jenny and Hadley to authors Nov 24, 2016
Makefile
NAMESPACE Allow responses to be written directly to disk (#77) Feb 21, 2018
NEWS.md Move README, NEWS to inst, better DESCRIPTION Jun 8, 2015
README.Rmd r-pkgs -> r-lib Jun 12, 2017
README.md Move README, NEWS to inst, better DESCRIPTION Jun 8, 2015
appveyor.yml Add a whoami function (user, token, scopes); closes #39 (#51) Dec 10, 2016
gh.Rproj Add RStudio project file Nov 8, 2016

README.md

gh

GitHub API

Linux Build Status Windows Build status CRAN RStudio mirror downloads Coverage Status

Minimalistic client to access GitHub's API v3.

Installation

devtools::install_github("r-lib/gh")

Usage

library(gh)

Use the gh() function to access all API endpoints. The endpoints are listed in the documentation.

The first argument of gh() is the endpoint. Note that the leading slash must be included as well. Parameters can be passed as extra arguments. E.g.

my_repos <- gh("/user/repos", type = "public")
vapply(my_repos, "[[", "", "name")
#>  [1] "after"               "argufy"              "ask"                
#>  [4] "baseimports"         "citest"              "clisymbols"         
#>  [7] "cmaker"              "cmark"               "conditions"         
#> [10] "crayon"              "debugme"             "devtools"           
#> [13] "diffobj"             "disposables"         "dotenv"             
#> [16] "elasticsearch-jetty" "falsy"               "fswatch"            
#> [19] "gitty"               "httr"                "httrmock"           
#> [22] "ISA"                 "keypress"            "lintr"              
#> [25] "macBriain"           "maxygen"             "MISO"               
#> [28] "parr"                "parsedate"           "pingr"

The JSON result sent by the API is converted to an R object.

If the end point itself has parameters, these can also be passed as extra arguments:

j_repos <- gh("/users/:username/repos", username = "jeroenooms")
vapply(j_repos, "[[", "", "name")
#>  [1] "apps"               "asantest"           "awk"               
#>  [4] "base64"             "bcrypt"             "blog"              
#>  [7] "brotli"             "cheerio"            "cmark"             
#> [10] "commonmark"         "covr"               "cranlogs"          
#> [13] "curl"               "cyphr"              "daff"              
#> [16] "data"               "data.table.extras"  "devtools"          
#> [19] "DiagrammeR"         "docdbi"             "docplyr"           
#> [22] "docs-travis-ci-com" "dplyr"              "encode"            
#> [25] "evaluate"           "feather"            "fib"               
#> [28] "figures"            "gdtools"            "geojson"

POST, PATCH, PUT and DELETE requests

POST, PATCH, PUT, and DELETE requests can be sent by including the HTTP verb before the endpoint, in the first argument. E.g. to create a repository:

new_repo <- gh("POST /user/repos", name = "my-new-repo-for-gh-testing")

and then delete it:

gh("DELETE /repos/:owner/:repo", owner = "gaborcsardi",
   repo = "my-new-repo-for-gh-testing")

Tokens

By default the GITHUB_PAT environment variable is used. Alternatively, one can set the .token argument of gh().

Pagination

Supply the page parameter to get subsequent pages:

my_repos2 <- gh("GET /users/:username/repos", username = "gaborcsardi",
  type = "public", page = 2)
vapply(my_repos2, "[[", "", "name")
#>  [1] "pkgconfig"               "playground"             
#>  [3] "praise"                  "prettycode"             
#>  [5] "prettyunits"             "progress"               
#>  [7] "prompt"                  "r-font"                 
#>  [9] "R6"                      "rcorpora"               
#> [11] "readline"                "remoji"                 
#> [13] "resume"                  "rhub-presentations"     
#> [15] "rintrojs"                "roxygen"                
#> [17] "scidb"                   "spark"                  
#> [19] "sparklyr"                "splicing"               
#> [21] "tamper"                  "testthat"               
#> [23] "trump"                   "user2016-tutorial-shiny"
#> [25] "webdriver"               "whoami"

License

MIT © Gábor Csárdi, Jennifer Bryan, Hadley Wickham