Code Monkey home page Code Monkey logo

gh's Introduction

gh

R-CMD-check Codecov test coverage CRAN RStudio mirror downloads

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

Installation

Install the package from CRAN as usual:

install.packages("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. 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] "oskeyring"    "parr"         "parsedate"    "prompt"       "r-font"      
#> [21] "r-source"     "rcorpora"     "roxygenlabs"  "sankey"       "secret"      
#> [26] "spark"        "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] "oskeyring"    "testthatlabs" "lpSolve"      "roxygenlabs"  "standalones" 
#>  [6] "altlist"      "svg-term"     "franc"        "sankey"       "r-source"    
#> [11] "secret"       "msgtools"     "notifier"     "prompt"       "parr"        
#> [16] "tamper"       "alexr"        "argufy"       "maxygen"      "keypress"    
#> [21] "macBriain"    "MISO"         "rcorpora"     "disposables"  "spark"       
#> [26] "dotenv"       "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().

Pagination

Supply the page parameter to get subsequent pages:

my_repos2 <- gh("GET /orgs/{org}/repos", org = "r-lib", page = 2)
vapply(my_repos2, "[[", "", "name")
#>  [1] "rcmdcheck"   "vdiffr"      "callr"       "mockery"     "here"       
#>  [6] "revdepcheck" "processx"    "vctrs"       "debugme"     "usethis"    
#> [11] "rlang"       "pkgload"     "httrmock"    "pkgbuild"    "prettycode" 
#> [16] "roxygen2md"  "pkgapi"      "zeallot"     "liteq"       "keyring"    
#> [21] "sloop"       "styler"      "ansistrings" "later"       "crancache"  
#> [26] "zip"         "osname"      "sessioninfo" "available"   "cli"

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

gh's People

Contributors

gaborcsardi avatar jennybc avatar hadley avatar rundel avatar krlmlr avatar noamross avatar batpigandme avatar jimhester avatar gdequeiroz avatar cderv avatar gadenbuie avatar coatless avatar jeroen avatar jsta avatar lionel- avatar maelle avatar realakhmed avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.