Skip to content

Commit

Permalink
Merge branch 'master' into github-last-commit-based-on-committer
Browse files Browse the repository at this point in the history
  • Loading branch information
repo-ranger[bot] authored Oct 20, 2022
2 parents 9084b99 + a251357 commit 5b818c0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
28 changes: 25 additions & 3 deletions services/github/github-release-date.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@ import { documentation, errorMessagesFor } from './github-helpers.js'
const schema = Joi.alternatives(
Joi.object({
created_at: Joi.date().required(),
published_at: Joi.date().required(),
}).required(),
Joi.array()
.items(
Joi.object({
created_at: Joi.date().required(),
published_at: Joi.date().required(),
}).required()
)
.min(1)
)

const queryParamSchema = Joi.object({
display_date: Joi.string()
.valid('created_at', 'published_at')
.default('created_at'),
}).required()

export default class GithubReleaseDate extends GithubAuthV3Service {
static category = 'activity'
static route = {
base: 'github',
pattern: ':variant(release-date|release-date-pre)/:user/:repo',
queryParamSchema,
}

static examples = [
Expand All @@ -46,6 +55,17 @@ export default class GithubReleaseDate extends GithubAuthV3Service {
staticPreview: this.render({ date: '2017-04-13T07:50:27.000Z' }),
documentation,
},
{
title: 'GitHub Release Date - Published_At',
pattern: 'release-date/:user/:repo',
namedParams: {
user: 'microsoft',
repo: 'vscode',
},
queryParams: { display_date: 'published_at' },
staticPreview: this.render({ date: '2022-10-17T07:50:27.000Z' }),
documentation,
},
]

static defaultBadgeData = { label: 'release date' }
Expand All @@ -70,11 +90,13 @@ export default class GithubReleaseDate extends GithubAuthV3Service {
})
}

async handle({ variant, user, repo }) {
async handle({ variant, user, repo }, queryParams) {
const body = await this.fetch({ variant, user, repo })
if (Array.isArray(body)) {
return this.constructor.render({ date: body[0].created_at })
return this.constructor.render({
date: body[0][queryParams.display_date],
})
}
return this.constructor.render({ date: body.created_at })
return this.constructor.render({ date: body[queryParams.display_date] })
}
}
21 changes: 21 additions & 0 deletions services/github/github-release-date.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ t.create('Release Date. e.g release date|today')
message: isFormattedDate,
})

t.create('Release Date - display_date by `created_at` (default)')
.get('/release-date/microsoft/vscode.json?display_date=created_at')
.expectBadge({
label: 'release date',
message: isFormattedDate,
})

t.create('Release Date - display_date by `published_at`')
.get('/release-date/microsoft/vscode.json?display_date=published_at')
.expectBadge({
label: 'release date',
message: isFormattedDate,
})

t.create('Release Date - display_date by `published_at`, incorrect query param')
.get('/release-date/microsoft/vscode.json?display_date=published_attttttttt')
.expectBadge({
label: 'release date',
message: 'invalid query parameter: display_date',
})

t.create(
'Release Date - Should return `no releases or repo not found` for invalid repo'
)
Expand Down

0 comments on commit 5b818c0

Please sign in to comment.