[GithubGistLastCommit] GitHub gist last commit (#8272)
* Add github-gist-last-commit.service.js * Still having difficulty with the reponse in the test file for github-gist-last-commit being in svg format, rather than json * Yay, tests are greeeeen, the best sight for sore eyes xD * Apply suggestions from code review - destructuring+rename and path change Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com> * Removed the unnecessary test from github-gist-last-commit Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
This commit is contained in:
47
services/github/github-gist-last-commit.service.js
Normal file
47
services/github/github-gist-last-commit.service.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import Joi from 'joi'
|
||||
import { formatDate } from '../text-formatters.js'
|
||||
import { age as ageColor } from '../color-formatters.js'
|
||||
import { GithubAuthV3Service } from './github-auth-service.js'
|
||||
import { documentation, errorMessagesFor } from './github-helpers.js'
|
||||
|
||||
const schema = Joi.object({
|
||||
updated_at: Joi.string().required(),
|
||||
}).required()
|
||||
|
||||
export default class GithubGistLastCommit extends GithubAuthV3Service {
|
||||
static category = 'activity'
|
||||
static route = { base: 'github-gist/last-commit', pattern: ':gistId' }
|
||||
static examples = [
|
||||
{
|
||||
title: 'GitHub Gist last commit',
|
||||
namedParams: {
|
||||
gistId: '8710649',
|
||||
},
|
||||
staticPreview: this.render({ commitDate: '2022-07-29T20:01:41Z' }),
|
||||
keywords: ['latest'],
|
||||
documentation,
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'last commit' }
|
||||
|
||||
static render({ commitDate }) {
|
||||
return {
|
||||
message: formatDate(commitDate),
|
||||
color: ageColor(Date.parse(commitDate)),
|
||||
}
|
||||
}
|
||||
|
||||
async fetch({ gistId }) {
|
||||
return this._requestJson({
|
||||
url: `/gists/${gistId}`,
|
||||
schema,
|
||||
errorMessages: errorMessagesFor('gist not found'),
|
||||
})
|
||||
}
|
||||
|
||||
async handle({ gistId }) {
|
||||
const { updated_at: commitDate } = await this.fetch({ gistId })
|
||||
return this.constructor.render({ commitDate })
|
||||
}
|
||||
}
|
||||
24
services/github/github-gist-last-commit.tester.js
Normal file
24
services/github/github-gist-last-commit.tester.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createServiceTester } from '../tester.js'
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('last commit in gist (ancient)').get('/871064.json').expectBadge({
|
||||
label: 'last commit',
|
||||
message: 'september 2015',
|
||||
color: 'red',
|
||||
})
|
||||
|
||||
// not checking the color badge, since in August 2022 it is orange but later it will become red
|
||||
t.create('last commit in gist (still ancient but slightly less so)')
|
||||
.get('/870071abadfd66a28bf539677332f12b.json')
|
||||
.expectBadge({
|
||||
label: 'last commit',
|
||||
message: 'october 2020',
|
||||
})
|
||||
|
||||
t.create('last commit in gist (gist not found)')
|
||||
.get('/55555555555555.json')
|
||||
.expectBadge({
|
||||
label: 'last commit',
|
||||
message: 'gist not found',
|
||||
color: 'red',
|
||||
})
|
||||
Reference in New Issue
Block a user