@@ -24,6 +24,7 @@ const schema = Joi.array()
24
24
const displayEnum = [ 'author' , 'committer' ]
25
25
26
26
const queryParamSchema = Joi . object ( {
27
+ path : Joi . string ( ) . uri ( { relativeOnly : true } ) ,
27
28
display_timestamp : Joi . string ( )
28
29
. valid ( ...displayEnum )
29
30
. default ( 'author' ) ,
@@ -45,6 +46,12 @@ export default class GithubLastCommit extends GithubAuthV3Service {
45
46
parameters : [
46
47
pathParam ( { name : 'user' , example : 'google' } ) ,
47
48
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
+ } ) ,
48
55
queryParam ( {
49
56
name : 'display_timestamp' ,
50
57
example : 'committer' ,
@@ -62,6 +69,12 @@ export default class GithubLastCommit extends GithubAuthV3Service {
62
69
pathParam ( { name : 'user' , example : 'google' } ) ,
63
70
pathParam ( { name : 'repo' , example : 'skia' } ) ,
64
71
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
+ } ) ,
65
78
queryParam ( {
66
79
name : 'display_timestamp' ,
67
80
example : 'committer' ,
@@ -82,20 +95,21 @@ export default class GithubLastCommit extends GithubAuthV3Service {
82
95
}
83
96
}
84
97
85
- async fetch ( { user, repo, branch } ) {
98
+ async fetch ( { user, repo, branch, path } ) {
86
99
return this . _requestJson ( {
87
100
url : `/repos/${ user } /${ repo } /commits` ,
88
- options : { searchParams : { sha : branch } } ,
101
+ options : { searchParams : { sha : branch , path } } ,
89
102
schema,
90
103
httpErrors : httpErrorsFor ( ) ,
91
104
} )
92
105
}
93
106
94
107
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 } )
96
110
97
111
return this . constructor . render ( {
98
- commitDate : body [ 0 ] . commit [ queryParams . display_timestamp ] . date ,
112
+ commitDate : body [ 0 ] . commit [ displayTimestamp ] . date ,
99
113
} )
100
114
}
101
115
}
0 commit comments