Files
shields/services/docker/docker-stars.service.js
dependabot-preview[bot] 478d14300c Build(deps-dev): bump eslint-plugin-import from 2.20.1 to 2.20.2 (#4859)
* Build(deps-dev): bump eslint-plugin-import from 2.20.1 to 2.20.2

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.20.1 to 2.20.2.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.20.1...v2.20.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Fixes

* refactor: combine imports

* refactor: combine imports

* refactor: combine imports

* refactor: update import ordering

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
Co-authored-by: Paul Melnikow <email@paulmelnikow.com>
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com>
2020-04-16 18:39:13 -05:00

61 lines
1.3 KiB
JavaScript

'use strict'
const { metric } = require('../text-formatters')
const { nonNegativeInteger } = require('../validators')
const { BaseService } = require('..')
const {
dockerBlue,
buildDockerUrl,
getDockerHubUser,
} = require('./docker-helpers')
module.exports = class DockerStars extends BaseService {
static get category() {
return 'rating'
}
static get route() {
return buildDockerUrl('stars')
}
static get examples() {
return [
{
title: 'Docker Stars',
namedParams: {
user: '_',
repo: 'ubuntu',
},
staticPreview: this.render({ stars: 9000 }),
},
]
}
static get defaultBadgeData() {
return { label: 'docker stars' }
}
static render({ stars }) {
return {
message: metric(stars),
color: dockerBlue,
}
}
async fetch({ user, repo }) {
const url = `https://hub.docker.com/v2/repositories/${getDockerHubUser(
user
)}/${repo}/stars/count/`
const { buffer } = await this._request({
url,
errorMessages: { 404: 'repo not found' },
})
return this.constructor._validate(buffer, nonNegativeInteger)
}
async handle({ user, repo }) {
const stars = await this.fetch({ user, repo })
return this.constructor.render({ stars })
}
}