GitHub API

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

Minimalistic client to access GitHub’s API v3.

Installation

Install the package from CRAN as usual:

Usage

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 = "jeroen")
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().

Environment Variables

  • The GITHUB_API_URL environment variable is used for the default github api url.
  • One of GITHUB_PAT or GITHUB_TOKEN environment variables is used, in this order, as default token.

License

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