Last active
March 6, 2022 16:00
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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