Files
shields/services/sourceforge/sourceforge-commit-count.service.js
chris48s 0bc512707f migrate examples to openApi part 7; affects [reuse sourceforge sourcegraph spack stackexchange testspace treeware twitch] (#9464)
* migrate some services from examples to openApi

* capitalize all words in sourceforge titles
2023-09-04 11:02:05 +01:00

55 lines
1.2 KiB
JavaScript

import Joi from 'joi'
import { BaseJsonService, pathParams } from '../index.js'
import { metric } from '../text-formatters.js'
const schema = Joi.object({
commit_count: Joi.number().required(),
}).required()
export default class SourceforgeCommitCount extends BaseJsonService {
static category = 'activity'
static route = {
base: 'sourceforge/commit-count',
pattern: ':project',
}
static openApi = {
'/sourceforge/commit-count/{project}': {
get: {
summary: 'SourceForge Commit Count',
parameters: pathParams({
name: 'project',
example: 'guitarix',
}),
},
},
}
static defaultBadgeData = { label: 'commit count' }
static render({ commitCount }) {
return {
message: metric(commitCount),
color: 'blue',
}
}
async fetch({ project }) {
return this._requestJson({
url: `https://sourceforge.net/rest/p/${project}/git`,
schema,
httpErrors: {
404: 'project not found',
},
})
}
async handle({ project }) {
const body = await this.fetch({ project })
return this.constructor.render({
commitCount: body.commit_count,
})
}
}