Skip to content

Commit

Permalink
Support file path for GitHub last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenFrankel committed Mar 22, 2024
1 parent f840417 commit 50ca478
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions services/github/github-last-commit.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const schema = Joi.array()
const displayEnum = ['author', 'committer']

const queryParamSchema = Joi.object({
path: Joi.string().uri({ relativeOnly: true }),
display_timestamp: Joi.string()
.valid(...displayEnum)
.default('author'),
Expand All @@ -45,6 +46,12 @@ export default class GithubLastCommit extends GithubAuthV3Service {
parameters: [
pathParam({ name: 'user', example: 'google' }),
pathParam({ name: 'repo', example: 'skia' }),
queryParam({
name: 'path',
example: 'README.md',
schema: { type: 'string' },
description: 'File path to resolve the last commit for.',
}),
queryParam({
name: 'display_timestamp',
example: 'committer',
Expand All @@ -62,6 +69,12 @@ export default class GithubLastCommit extends GithubAuthV3Service {
pathParam({ name: 'user', example: 'google' }),
pathParam({ name: 'repo', example: 'skia' }),
pathParam({ name: 'branch', example: 'infra/config' }),
queryParam({
name: 'path',
example: 'README.md',
schema: { type: 'string' },
description: 'File path to resolve the last commit for.',
}),
queryParam({
name: 'display_timestamp',
example: 'committer',
Expand All @@ -82,20 +95,21 @@ export default class GithubLastCommit extends GithubAuthV3Service {
}
}

async fetch({ user, repo, branch }) {
async fetch({ user, repo, branch, path }) {
return this._requestJson({
url: `/repos/${user}/${repo}/commits`,
options: { searchParams: { sha: branch } },
options: { searchParams: { sha: branch, path } },
schema,
httpErrors: httpErrorsFor(),
})
}

async handle({ user, repo, branch }, queryParams) {
const body = await this.fetch({ user, repo, branch })
const { path, display_timestamp: displayTimestamp } = queryParams
const body = await this.fetch({ user, repo, branch, path })

return this.constructor.render({
commitDate: body[0].commit[queryParams.display_timestamp].date,
commitDate: body[0].commit[displayTimestamp].date,
})
}
}

0 comments on commit 50ca478

Please sign in to comment.