Skip to content
/ gh Public
forked from r-lib/gh

Minimalistic GitHub API client in R

License

Notifications You must be signed in to change notification settings

bemined/gh

 
 

Repository files navigation

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

About

Minimalistic GitHub API client in R

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 99.6%
  • Makefile 0.4%