Skip to content

Instantly share code, notes, and snippets.

@Pustur
Last active March 6, 2022 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pustur/f00dd1100196dffc708295bd614d2d35 to your computer and use it in GitHub Desktop.
Save Pustur/f00dd1100196dffc708295bd614d2d35 to your computer and use it in GitHub Desktop.
Downloads the release assets for a private repo (requires nodejs --experimental-fetch flag)
// Imports
const fs = require('node:fs');
require('dotenv/config');
// Variables
const owner = 'Pustur';
const repo = 'epic-store-bot';
// Init
fetch(`https://api.github.com/repos/${owner}/${repo}/releases/latest`, {
method: 'GET',
headers: {
Accept: `application/vnd.github.v3+json`,
Authorization: `token ${process.env.GITHUB_TOKEN}`,
},
})
.then(res => res.json())
.then(json =>
Promise.all(
json.assets.map(asset =>
fetch(asset.url, {
headers: {
Accept: 'application/octet-stream',
Authorization: `token ${process.env.GITHUB_TOKEN}`,
},
})
.then(res => res.arrayBuffer())
.then(arrayBuffer =>
fs.promises.writeFile(asset.name, Buffer.from(arrayBuffer)),
),
),
),
)
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment