[GitHub] Number of commits between branches/tags/commits (#8394)

closes #6901
This commit is contained in:
Paula Barszcz
2022-09-16 22:48:23 +02:00
committed by GitHub
parent 93fa955dde
commit e8f151eafa
2 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { GithubAuthV3Service } from './github-auth-service.js'
import { documentation, errorMessagesFor } from './github-helpers.js'
const schema = Joi.object({ total_commits: nonNegativeInteger }).required()
const queryParamSchema = Joi.object({
base: Joi.string().required(),
head: Joi.string().required(),
}).required()
export default class GithubCommitsDifference extends GithubAuthV3Service {
static category = 'activity'
static route = {
base: 'github/commits-difference',
pattern: ':user/:repo',
queryParamSchema,
}
static examples = [
{
title: 'GitHub commits difference between two branches/tags/commits',
namedParams: {
user: 'microsoft',
repo: 'vscode',
},
queryParams: {
base: '1.60.0',
head: '82f2db7',
},
staticPreview: this.render({
commitCount: 9227,
}),
documentation,
},
]
static defaultBadgeData = { label: 'commits difference', namedLogo: 'github' }
static render({ commitCount }) {
return {
message: metric(commitCount),
color: 'blue',
}
}
async handle({ user, repo }, { base, head }) {
const notFoundMessage = 'could not establish commit difference between refs'
const { total_commits: commitCount } = await this._requestJson({
schema,
url: `/repos/${user}/${repo}/compare/${base}...${head}`,
errorMessages: errorMessagesFor(notFoundMessage),
})
return this.constructor.render({ commitCount })
}
}