Minimalistic client to access GitHub’s REST and GraphQL APIs.

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. You can just copy and paste the API endpoints from the documentation. Note that the leading slash must be included as well.

From https://docs.github.com/rest/reference/repos#list-repositories-for-a-user you can copy and paste GET /users/{username}/repos into your gh() call. E.g.

my_repos <- gh("GET /users/{username}/repos", username = "gaborcsardi")
vapply(my_repos, "[[", "", "name")
#>  [1] "alexr"        "altlist"      "argufy"       "disposables"  "dotenv"      
#>  [6] "falsy"        "franc"        "ISA"          "keypress"     "lpSolve"     
#> [11] "macBriain"    "maxygen"      "MISO"         "msgtools"     "notifier"    
#> [16] "parr"         "parsedate"    "prompt"       "r-font"       "r-source"    
#> [21] "rcorpora"     "roxygenlabs"  "sankey"       "secret"       "spark"       
#> [26] "standalones"  "svg-term"     "tamper"       "testthatlabs"

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

Parameters can be passed as extra arguments. E.g.

my_repos <- gh(
  "/users/{username}/repos",
  username = "gaborcsardi",
  sort = "created")
vapply(my_repos, "[[", "", "name")
#>  [1] "testthatlabs" "lpSolve"      "roxygenlabs"  "standalones"  "altlist"     
#>  [6] "svg-term"     "franc"        "sankey"       "r-source"     "secret"      
#> [11] "msgtools"     "notifier"     "prompt"       "parr"         "tamper"      
#> [16] "alexr"        "argufy"       "maxygen"      "keypress"     "macBriain"   
#> [21] "MISO"         "rcorpora"     "disposables"  "spark"        "dotenv"      
#> [26] "parsedate"    "r-font"       "falsy"        "ISA"

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