DEV Community

Discussion on: I built a badge API for your GitHub README

Collapse
 
waterboy96 profile image
Waterboy96 • Edited

Hi again Julian,

I tried to create some crack-pot code to fetch the download count of one asset (for my case this is fine since each release only has one asset). I don't know how to test it, but let me know what you think!

app.get('/downloads/:user/:repo/:id', async (req, res) => {
const { user, repo, id } = req.params;
const response = await request(https://api.github.com/repos/${username}/${repo}/releases/assets/${id})
.header(githubHeaders).json();
if (!response.id) return createError(res, response.message);
return res.redirect(https://img.shields.io/badge/Created-${moment(response.download_count).fromNow()}-brightgreen${req.originalUrl.slice(req.originalUrl.indexOf('?'))})
});