Vagrant box size for shields.io

node v13.14.0
version: 6.0.0
endpointsharetweet
Returns a valid response for shields.io, containing the size of a Vagrant box hosted on Vagrant Cloud. e.g.: Without provider (default is virtualbox): - endpoint: https://runkit.io/felipecassiors/vagrant-box-size/branches/master/felipecassiors/ubuntu1804-4dev - shields.io: https://img.shields.io/endpoint?url=https://runkit.io/felipecassiors/vagrant-box-size/branches/master/felipecassiors/ubuntu1804-4dev With provider: - endpoint: https://runkit.io/felipecassiors/vagrant-box-size/branches/master/bento/ubuntu-18.04/vmware_desktop - shields.io: https://img.shields.io/endpoint?url=https://runkit.io/felipecassiors/vagrant-box-size/branches/master/bento/ubuntu-18.04/vmware_desktop
const app = require('@runkit/runkit/express-endpoint/1.0.0')(exports); const request = require('request'); // peer dependency const rp = require('request-promise'); const cheerio = require('cheerio'); app.get('/:organization/:boxName/:provider?', async (request, response) => { const url = `https://app.vagrantup.com/${request.params.organization}/boxes/${request.params.boxName}`; const page = cheerio.load(await rp(url)); const selector = `.list-group-item:contains(${request.params.provider || 'virtualbox'})`; const size = page(selector).first().text().split('(')[1].split(')')[0]; response.send({ schemaVersion: 1, namedLogo: 'vagrant', label: 'box size', labelColor: '#1563FF', message: size, }); });
Loading…

no comments

    sign in to comment