github
github copied to clipboard
How would one download a release asset
This seems to be an incredible mystery. I can't find any examples for any mechanism to programmatically download a release asset from a private repo.
I had hoped this Gem would have an easy way to do that, but I don't see how to do it here ether.
Any suggestions (or example code)?
Thanks
Hi Robert,
The intro paragraph explains how to navigate the api and links to official docs. After reading official documentation for releases, you will find that the code hierarchy corresponds to with the docs. The api has over 200 methods and I took a lot of time to document the api calls with code examples - see release assets
github = Github.new ....
github.repos.releases.assets.get 'owner', 'repo', 'id'
Excuse the messy Ruby, but this is what I had to do to wind up downloading a single asset:
def get_asset_download_url(github_user, github_repo, asset_id)
api = Github.new
resp = api.repos.releases.assets.get github_user, github_repo, asset_id, accept: 'application/octet-stream'
return resp.headers.location
end
Two issues I came across was passing application/octet-stream to specify that I wanted a binary, then after that having to handle the redirect response GitHub will give.
Would be nice to see downloading to a file handle as an option.
@rberger
I struggled to find it too but it's documented here https://developer.github.com/v3/repos/releases/#response-8
When getting a single asset setting header accept: application/octet-stream will download the asset as binary. Make sure to follow redirects (302).