Files
shields/services/gitlab/gitlab-last-commit.service.js
T
chris48sandGitHub bd3a11b4b6 upgrade to docusaurus 3 (#9820)
* update packages

* add plugin to strip autolinks in code blocks

* fix all the documentation for MDXv3

* remove check-docusaurus-versions

in docusaurus 3 this is now a hard error, not just a warning

* port upstream change to Curl component

fixes performing the 'execute' action when pressing enter
2024-03-23 19:54:57 +00:00

90 lines
2.2 KiB
JavaScript

import Joi from 'joi'
import { pathParam, queryParam } from '../index.js'
import { optionalUrl } from '../validators.js'
import { formatDate } from '../text-formatters.js'
import { age as ageColor } from '../color-formatters.js'
import { description, httpErrorsFor } from './gitlab-helper.js'
import GitLabBase from './gitlab-base.js'
const schema = Joi.array()
.items(
Joi.object({
committed_date: Joi.string().required(),
}).required(),
)
.required()
.min(1)
const queryParamSchema = Joi.object({
ref: Joi.string(),
gitlab_url: optionalUrl,
}).required()
const refText = `
ref can be filled with the name of a branch, tag or revision range of the repository.
`
const lastCommitDescription = description + refText
export default class GitlabLastCommit extends GitLabBase {
static category = 'activity'
static route = {
base: 'gitlab/last-commit',
pattern: ':project+',
queryParamSchema,
}
static openApi = {
'/gitlab/last-commit/{project}': {
get: {
summary: 'GitLab Last Commit',
description: lastCommitDescription,
parameters: [
pathParam({
name: 'project',
example: 'gitlab-org/gitlab',
}),
queryParam({
name: 'gitlab_url',
example: 'https://gitlab.com',
}),
queryParam({
name: 'ref',
example: 'master',
}),
],
},
},
}
static defaultBadgeData = { label: 'last commit' }
static render({ commitDate }) {
return {
message: formatDate(commitDate),
color: ageColor(Date.parse(commitDate)),
}
}
async fetch({ project, baseUrl, ref }) {
// https://docs.gitlab.com/ee/api/commits.html#list-repository-commits
return super.fetch({
url: `${baseUrl}/api/v4/projects/${encodeURIComponent(
project,
)}/repository/commits`,
options: { searchParams: { ref_name: ref } },
schema,
httpErrors: httpErrorsFor('project not found'),
})
}
async handle(
{ project },
{ gitlab_url: baseUrl = 'https://gitlab.com', ref },
) {
const data = await this.fetch({ project, baseUrl, ref })
return this.constructor.render({ commitDate: data[0].committed_date })
}
}