Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [GitHubLastCommit] by committer badge #8537

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions services/github/github-last-commit.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@ const schema = Joi.array()
author: Joi.object({
date: Joi.string().required(),
}).required(),
committer: Joi.object({
date: Joi.string().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 {
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 = [
{
title: 'GitHub last commit',
Expand All @@ -45,6 +59,17 @@ export default class GithubLastCommit extends GithubAuthV3Service {
staticPreview: this.render({ commitDate: '2013-07-31T20:01:41Z' }),
...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' }
Expand All @@ -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 })
return this.constructor.render({ commitDate: body[0].commit.author.date })

return this.constructor.render({
commitDate: body[0].commit[queryParams.display_timestamp].date,
})
}
}
4 changes: 4 additions & 0 deletions services/github/github-last-commit.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ t.create('last commit (on branch)')
.get('/badges/badgr.co/shielded.json')
.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)')
.get('/badges/helmets.json')
.expectBadge({ label: 'last commit', message: 'repo not found' })