1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00
shields/services/sourceforge/sourceforge-last-commit.service.js
jNullj 231a48fa87
[sourceforge] add repo param to last commit service (#10935)
* [sourceforge] add repo param to last commit service

some sourceforge projects have multiple repositories, so we need to
specify the repository to use for the last commit service.

* [sourceforge] add redirect for old project param only URLs
2025-03-09 16:23:39 +00:00

60 lines
1.4 KiB
JavaScript

import Joi from 'joi'
import { BaseJsonService, pathParams } from '../index.js'
import { renderDateBadge } from '../date.js'
const schema = Joi.object({
commits: Joi.array()
.items(
Joi.object({
committed_date: Joi.string().required(),
}).required(),
)
.required(),
}).required()
export default class SourceforgeLastCommit extends BaseJsonService {
static category = 'activity'
static route = {
base: 'sourceforge/last-commit',
pattern: ':project/:repo',
}
static openApi = {
'/sourceforge/last-commit/{project}/{repo}': {
get: {
summary: 'SourceForge Last Commit',
parameters: pathParams(
{
name: 'project',
example: 'guitarix',
},
{
name: 'repo',
example: 'git',
description:
'The repository name, usually `git` but might be different.',
},
),
},
},
}
static defaultBadgeData = { label: 'last commit' }
async fetch({ project, repo }) {
return this._requestJson({
url: `https://sourceforge.net/rest/p/${project}/${repo}/commits`,
schema,
httpErrors: {
404: 'project or repo not found',
},
})
}
async handle({ project, repo }) {
const body = await this.fetch({ project, repo })
return renderDateBadge(body.commits[0].committed_date)
}
}