Skip to content

Instantly share code, notes, and snippets.

@miwaniec
Created September 1, 2019 18:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miwaniec/26973ca30646b6511a2f26300e2eb71a to your computer and use it in GitHub Desktop.
Save miwaniec/26973ca30646b6511a2f26300e2eb71a to your computer and use it in GitHub Desktop.
Download zipped repository from github. If repo is private, you have to use token (create in user profile).
const request = require('request');
const fs = require('fs');
const repo = 'miwaniec/socket-camera';
const accessToken = ''; /* for private repo, use token - https://github.com/settings/tokens */
var options = {
method: 'GET',
url: 'https://api.github.com/repos/' + repo + '/zipball/',
encoding: 'binary',
headers: {
'Authorization': (accessToken != '' ? 'token ' + accessToken : '' ),
'User-Agent': 'miwaniec-app'
}
};
request(options, function(error, response, body) {
if (error || response.statusCode !== 200) {
console.log('Failed to get repo ', response.statusCode);
} else {
console.log('We got the repo!');
fs.writeFile('repo.zip', body, 'binary', function (err) {});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment