1

New Git user here, storing XML documents (each of which represents the metadata for a report) in GitHub:

#Repo: My-Reports

Report1
Report2
Report3 

I need the ability to pull (not in the Git sense of the word) a single file (like Report2) from the repo to an arbitrary client. Being able to pull Report2 with a specific tag is a bonus.

I don't want to clone the repo to the client and do a true git pull as I'm not doing SCM on this box and don't want to install binaries. I just need the document, period.

I see that GitHub REST API has a Get Archive method which will download a tarball/zipball of the entire repo:

 GET /repos/:owner/:repo/:archive_format/:ref

http://developer.github.com/v3/repos/contents/#get-archive-link

I guess I can go this route, but it will force me to manage the "document retrieval process" myself (code the task of unzipping the archive and pulling out what I need ) I'd like to avoid that if I can....but for all I know the document is going to be compressed no matter how ask for it and I just need to live with it...like I said, Git & GitHub newb.

Is there a smarter/better way to approach this? I'll be in Ruby, so I could use the Ocktokit gem, too.

Many Thanks

1
  • You can definitely get a specific version of a file outside of the API: https://raw.github.com/<owner>/<repo>/<tag>/<file>?login_credentials - I'm not sure how you collect and pass in any credentials though. What is wrong with developer.github.com/v3/repos/contents/#get-contents ? Jul 23, 2013 at 11:38

1 Answer 1

4

Looking at octokit gem, I would suggest you use the contents method as follows (example using my own repo, and demonstrates pulling a specific tag - but any git reference can be used):

require 'octokit'
require 'base64'

api_response = Octokit.contents 'neilslater/games_dice', 
  :ref => 'v0.0.1', :path => 'README.md'
text_contents = Base64.decode64( api_response.content )
File.open( 'README.md', 'wb' ) { |file| file.puts text_contents }

This is limited to files up to 1MB max size. Note I have skipped possible issues here with character encoding - if you want to handle text_contents an memory you will need to know correct encoding to use, and apply it. When just writing the file, the simplest thing is to add the 'b' flag when opening the file.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.