Files
shields/services/sourceforge/sourceforge-commit-count.service.js
jNullj 834e4e1f96 Update [SourceForge] commit count badge to support repository parameter (#10954)
* [sourceforge] update commit count service to support repo param

follow-up to #10935
sourceforge commit count also requires the new repo param for some projects.

* [sourceforge] add redirector for legacy commit count URLs

* fix missing openapi path
2025-03-16 20:27:43 +00:00

63 lines
1.4 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/:repo',
}
static openApi = {
'/sourceforge/commit-count/{project}/{repo}': {
get: {
summary: 'SourceForge Commit Count',
parameters: pathParams(
{
name: 'project',
example: 'guitarix',
},
{
name: 'repo',
example: 'git',
description:
'The repository name, usually `git` but might be different.',
},
),
},
},
}
static defaultBadgeData = { label: 'commit count' }
static render({ commitCount }) {
return {
message: metric(commitCount),
color: 'blue',
}
}
async fetch({ project, repo }) {
return this._requestJson({
url: `https://sourceforge.net/rest/p/${project}/${repo}`,
schema,
httpErrors: {
404: 'project or repo not found',
},
})
}
async handle({ project, repo }) {
const body = await this.fetch({ project, repo })
return this.constructor.render({
commitCount: body.commit_count,
})
}
}