Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix [dockerstars] service #8316

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions services/docker/docker-stars.service.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseService } from '../index.js'
import { BaseJsonService } from '../index.js'
import {
dockerBlue,
buildDockerUrl,
getDockerHubUser,
} from './docker-helpers.js'

export default class DockerStars extends BaseService {
const schema = Joi.object({
star_count: nonNegativeInteger.required(),
}).required()

export default class DockerStars extends BaseJsonService {
static category = 'rating'
static route = buildDockerUrl('stars')
static examples = [
Expand All @@ -31,18 +36,17 @@ export default class DockerStars extends BaseService {
}

async fetch({ user, repo }) {
const url = `https://hub.docker.com/v2/repositories/${getDockerHubUser(
user
)}/${repo}/stars/count/`
const { buffer } = await this._request({
url,
return this._requestJson({
schema,
url: `https://hub.docker.com/v2/repositories/${getDockerHubUser(
user
)}/${repo}/`,
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 })
const { star_count } = await this.fetch({ user, repo })
return this.constructor.render({ stars: star_count })
}
}