diff --git a/libs/live-fns/_index.js b/libs/live-fns/_index.js index 2103647..492ae59 100644 --- a/libs/live-fns/_index.js +++ b/libs/live-fns/_index.js @@ -6,6 +6,7 @@ module.exports = { 'codecov': require('./codecov.js'), 'crates': require('./crates.js'), 'david': require('./david.js'), + 'docker': require('./docker.js'), 'github': require('./github.js'), 'homebrew': require('./homebrew.js'), 'npm': require('./npm.js'), diff --git a/libs/live-fns/docker.js b/libs/live-fns/docker.js new file mode 100644 index 0000000..78e40e9 --- /dev/null +++ b/libs/live-fns/docker.js @@ -0,0 +1,31 @@ +const axios = require('../axios.js') +const millify = require('millify') + +module.exports = async function (topic, namespace, name) { + if (!['stars', 'pulls'].includes(topic)) { + return { + subject: 'docker', + status: 'unknown topic', + color: 'grey' + } + } + + /* eslint-disable camelcase */ + const endpoint = `https://hub.docker.com/v2/repositories/${namespace}/${name}` + const { pull_count, star_count } = await axios(endpoint).then(res => res.data) + + switch (topic) { + case 'stars': + return { + subject: 'docker stars', + status: millify(star_count), + color: 'blue' + } + case 'pulls': + return { + subject: 'docker pulls', + status: millify(pull_count), + color: 'blue' + } + } +}