3

All I'm trying to do is read all the repos and issues in my organizations private repos. I can from my Windows 7 cmd.exe execute

curl -u "user:pass" https://api.github.com/orgs/:org/repos

and I get back all of my repositories. I can pipe this to a file:

curl -u "user:pass" https://api.github.com/orgs/:org/repos > "C:\Users\Location\file.txt"

and this saves the JSON output. I can replicate this in R but in what seems like a terrible way.

fullRepos = system('curl -s -u "user:pass" -G https://api.github.com/orgs/:org/repos',
                   intern=T,show.output.on.console = F)

This captures the output (intern = T) and the -s gets rid of the progress bars so I can collapse the lines and turn it into a data frame. This gets back all the repositories, public and private.

I tried using RCurl to do the same thing but the code below only provides the public repositories. The httpheader is because otherwise it the API rejects my call.

RCurl::getURL(url="https://api.github.com/orgs/:org/repos",userpwd ="user:pass",
              httpheader = c('User-Agent' = "A user agent")) 

I also tried httr and it also only provides the public repositories.

httr::GET(url="https://api.github.com/orgs/:org/repos",userpwd="user:pass")

What am I doing wrong with RCurl and httr? I'd rather have a workflow that doesn't make a system command and then paste the lines together.

4
  • There are (IIRC) 3 github-API packages for R. Why aren't you using them? Commented Aug 23, 2016 at 15:27
  • 1
    I believe they are all based on OAuth which doesn't give access to private repositories. At least, I can't figure out how to get my application to request access to private repositories. Regardless of the Github specific nature here though, I'm also interested in why I can't replicate the curl call in RCurl or httr. Commented Aug 23, 2016 at 15:38
  • try httr::GET(url="https://api.github.com/orgs/:org/repos", httr::authenticate("user", "pass"), httr::verbose()) Commented Aug 23, 2016 at 16:02
  • @hrbrmstr That works! Would you post it as an answer that I can accept? Commented Aug 23, 2016 at 17:58

1 Answer 1

3

We can use the authenticate() helper function in httr to build the authentication header for us w/o having to manually create it. Also, verbose() can be used to debug HTTP issues:

httr::GET(url="https://api.github.com/orgs/:‌​org/repos",
          httr::authenticate("user", "pass"), 
          httr::verbose())
Sign up to request clarification or add additional context in comments.

1 Comment

Just in case this one catches anybody off-guard, this works, but will only return first page of repos... to get second page, need to add ?page=2. Also, to actually view the content, you'll have to pass through content(x)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.