Skip to content

Commit 50ca478

Browse files
committedMar 22, 2024
Support file path for GitHub last commit
1 parent f840417 commit 50ca478

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed
 

‎services/github/github-last-commit.service.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const schema = Joi.array()
2424
const displayEnum = ['author', 'committer']
2525

2626
const queryParamSchema = Joi.object({
27+
path: Joi.string().uri({ relativeOnly: true }),
2728
display_timestamp: Joi.string()
2829
.valid(...displayEnum)
2930
.default('author'),
@@ -45,6 +46,12 @@ export default class GithubLastCommit extends GithubAuthV3Service {
4546
parameters: [
4647
pathParam({ name: 'user', example: 'google' }),
4748
pathParam({ name: 'repo', example: 'skia' }),
49+
queryParam({
50+
name: 'path',
51+
example: 'README.md',
52+
schema: { type: 'string' },
53+
description: 'File path to resolve the last commit for.',
54+
}),
4855
queryParam({
4956
name: 'display_timestamp',
5057
example: 'committer',
@@ -62,6 +69,12 @@ export default class GithubLastCommit extends GithubAuthV3Service {
6269
pathParam({ name: 'user', example: 'google' }),
6370
pathParam({ name: 'repo', example: 'skia' }),
6471
pathParam({ name: 'branch', example: 'infra/config' }),
72+
queryParam({
73+
name: 'path',
74+
example: 'README.md',
75+
schema: { type: 'string' },
76+
description: 'File path to resolve the last commit for.',
77+
}),
6578
queryParam({
6679
name: 'display_timestamp',
6780
example: 'committer',
@@ -82,20 +95,21 @@ export default class GithubLastCommit extends GithubAuthV3Service {
8295
}
8396
}
8497

85-
async fetch({ user, repo, branch }) {
98+
async fetch({ user, repo, branch, path }) {
8699
return this._requestJson({
87100
url: `/repos/${user}/${repo}/commits`,
88-
options: { searchParams: { sha: branch } },
101+
options: { searchParams: { sha: branch, path } },
89102
schema,
90103
httpErrors: httpErrorsFor(),
91104
})
92105
}
93106

94107
async handle({ user, repo, branch }, queryParams) {
95-
const body = await this.fetch({ user, repo, branch })
108+
const { path, display_timestamp: displayTimestamp } = queryParams
109+
const body = await this.fetch({ user, repo, branch, path })
96110

97111
return this.constructor.render({
98-
commitDate: body[0].commit[queryParams.display_timestamp].date,
112+
commitDate: body[0].commit[displayTimestamp].date,
99113
})
100114
}
101115
}

0 commit comments

Comments
 (0)