1
0
mirror of https://github.com/badges/shields.git synced 2025-08-01 04:46:56 +03:00

Add [GitHubLastCommit] by committer badge (#8537)

* add github last commit by committer badge

* modify queryParam

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
Paula Barszcz
2022-10-20 21:08:48 +02:00
committed by GitHub
parent a251357881
commit c0087cae67
2 changed files with 35 additions and 3 deletions

View File

@ -15,14 +15,28 @@ const schema = Joi.array()
author: Joi.object({ author: Joi.object({
date: Joi.string().required(), date: Joi.string().required(),
}).required(), }).required(),
committer: Joi.object({
date: Joi.string().required(),
}).required(),
}).required(), }).required(),
}).required() }).required()
) )
.required() .required()
const queryParamSchema = Joi.object({
display_timestamp: Joi.string()
.valid('author', 'committer')
.default('author'),
}).required()
export default class GithubLastCommit extends GithubAuthV3Service { export default class GithubLastCommit extends GithubAuthV3Service {
static category = 'activity' static category = 'activity'
static route = { base: 'github/last-commit', pattern: ':user/:repo/:branch*' } static route = {
base: 'github/last-commit',
pattern: ':user/:repo/:branch*',
queryParamSchema,
}
static examples = [ static examples = [
{ {
title: 'GitHub last commit', title: 'GitHub last commit',
@ -45,6 +59,17 @@ export default class GithubLastCommit extends GithubAuthV3Service {
staticPreview: this.render({ commitDate: '2013-07-31T20:01:41Z' }), staticPreview: this.render({ commitDate: '2013-07-31T20:01:41Z' }),
...commonExampleAttrs, ...commonExampleAttrs,
}, },
{
title: 'GitHub last commit (by committer)',
pattern: ':user/:repo',
namedParams: {
user: 'google',
repo: 'skia',
},
queryParams: { display_timestamp: 'committer' },
staticPreview: this.render({ commitDate: '2022-10-15T20:01:41Z' }),
...commonExampleAttrs,
},
] ]
static defaultBadgeData = { label: 'last commit' } static defaultBadgeData = { label: 'last commit' }
@ -65,8 +90,11 @@ export default class GithubLastCommit extends GithubAuthV3Service {
}) })
} }
async handle({ user, repo, branch }) { async handle({ user, repo, branch }, queryParams) {
const body = await this.fetch({ user, repo, branch }) const body = await this.fetch({ user, repo, branch })
return this.constructor.render({ commitDate: body[0].commit.author.date })
return this.constructor.render({
commitDate: body[0].commit[queryParams.display_timestamp].date,
})
} }
} }

View File

@ -14,6 +14,10 @@ t.create('last commit (on branch)')
.get('/badges/badgr.co/shielded.json') .get('/badges/badgr.co/shielded.json')
.expectBadge({ label: 'last commit', message: 'july 2013' }) .expectBadge({ label: 'last commit', message: 'july 2013' })
t.create('last commit (by committer)')
.get('/badges/badgr.co/shielded.json?display_timestamp=committer')
.expectBadge({ label: 'last commit', message: 'july 2013' })
t.create('last commit (repo not found)') t.create('last commit (repo not found)')
.get('/badges/helmets.json') .get('/badges/helmets.json')
.expectBadge({ label: 'last commit', message: 'repo not found' }) .expectBadge({ label: 'last commit', message: 'repo not found' })