@@ -3,7 +3,7 @@ use reqwest::header::{HeaderMap, HeaderValue, InvalidHeaderValue, AUTHORIZATION,
3
3
use reqwest:: { self , blocking:: Client , blocking:: Response } ;
4
4
use serde:: { Deserialize , Serialize } ;
5
5
6
- use crate :: { parse_to_naive_date, Commit , GitDate } ;
6
+ use crate :: { parse_to_naive_date, Author , Commit , GitDate , BORS_AUTHOR } ;
7
7
8
8
#[ derive( Serialize , Deserialize , Debug ) ]
9
9
struct GithubCommitComparison {
@@ -16,8 +16,8 @@ struct GithubCommitElem {
16
16
}
17
17
#[ derive( Serialize , Deserialize , Debug ) ]
18
18
struct GithubCommit {
19
- author : GithubAuthor ,
20
- committer : GithubAuthor ,
19
+ author : Option < GithubAuthor > ,
20
+ committer : Option < GithubAuthor > ,
21
21
message : String ,
22
22
}
23
23
#[ derive( Serialize , Deserialize , Debug ) ]
@@ -38,19 +38,33 @@ pub(crate) struct GithubComment {
38
38
39
39
impl GithubCommitElem {
40
40
fn date ( & self ) -> anyhow:: Result < GitDate > {
41
- let ( date_str, _) =
42
- self . commit . committer . date . split_once ( 'T' ) . context (
43
- "commit date should folllow the ISO 8061 format, eg: 2022-05-04T09:55:51Z" ,
44
- ) ?;
41
+ let ( date_str, _) = self
42
+ . commit
43
+ . committer
44
+ . as_ref ( )
45
+ . ok_or_else ( || anyhow:: anyhow!( "commit should have committer" ) ) ?
46
+ . date
47
+ . split_once ( 'T' )
48
+ . context ( "commit date should folllow the ISO 8061 format, eg: 2022-05-04T09:55:51Z" ) ?;
45
49
Ok ( parse_to_naive_date ( date_str) ?)
46
50
}
47
51
48
52
fn git_commit ( self ) -> anyhow:: Result < Commit > {
49
53
let date = self . date ( ) ?;
54
+ let committer = self
55
+ . commit
56
+ . committer
57
+ . ok_or_else ( || anyhow:: anyhow!( "commit should have committer" ) ) ?;
58
+ let committer = Author {
59
+ name : committer. name ,
60
+ email : committer. email ,
61
+ date,
62
+ } ;
50
63
Ok ( Commit {
51
64
sha : self . sha ,
52
65
date,
53
66
summary : self . commit . message ,
67
+ committer,
54
68
} )
55
69
}
56
70
}
@@ -123,13 +137,11 @@ impl CommitsQuery<'_> {
123
137
let mut commits = Vec :: new ( ) ;
124
138
125
139
// focus on Pull Request merges, all authored and committed by bors.
126
- let author = "bors" ;
127
-
128
140
let client = Client :: builder ( ) . default_headers ( headers ( ) ?) . build ( ) ?;
129
141
for page in 1 .. {
130
142
let url = CommitsUrl {
131
143
page,
132
- author,
144
+ author : BORS_AUTHOR ,
133
145
since : self . since_date ,
134
146
sha : self . most_recent_sha ,
135
147
}
@@ -138,21 +150,17 @@ impl CommitsQuery<'_> {
138
150
let response: Response = client. get ( & url) . send ( ) ?;
139
151
140
152
let action = parse_paged_elems ( response, |elem : GithubCommitElem | {
141
- let date = elem. date ( ) ?;
142
- let sha = elem. sha . clone ( ) ;
143
- let summary = elem. commit . message ;
144
- let commit = Commit { sha, date, summary } ;
145
- commits. push ( commit) ;
146
-
147
- Ok ( if elem. sha == self . earliest_sha {
153
+ let found_last = elem. sha == self . earliest_sha ;
154
+ if found_last {
148
155
eprintln ! (
149
156
"ending github query because we found starting sha: {}" ,
150
157
elem. sha
151
158
) ;
152
- Loop :: Break
153
- } else {
154
- Loop :: Next
155
- } )
159
+ }
160
+ let commit = elem. git_commit ( ) ?;
161
+ commits. push ( commit) ;
162
+
163
+ Ok ( if found_last { Loop :: Break } else { Loop :: Next } )
156
164
} ) ?;
157
165
158
166
if let Loop :: Break = action {
@@ -254,9 +262,15 @@ mod tests {
254
262
#[ test]
255
263
fn test_github ( ) {
256
264
let c = get_commit ( "25674202bb7415e0c0ecd07856749cfb7f591be6" ) . unwrap ( ) ;
265
+ let committer = Author {
266
+ name : String :: from ( "bors" ) ,
267
+ email : String :: from ( "[email protected] " ) ,
268
+ date : GitDate :: from_ymd_opt ( 2022 , 5 , 4 ) . unwrap ( ) ,
269
+ } ;
257
270
let expected_c = Commit { sha : "25674202bb7415e0c0ecd07856749cfb7f591be6" . to_string ( ) ,
258
271
date : parse_to_naive_date ( "2022-05-04" ) . unwrap ( ) ,
259
- summary : "Auto merge of #96695 - JohnTitor:rollup-oo4fc1h, r=JohnTitor\n \n Rollup of 6 pull requests\n \n Successful merges:\n \n - #96597 (openbsd: unbreak build on native platform)\n - #96662 (Fix typo in lint levels doc)\n - #96668 (Fix flaky rustdoc-ui test because it did not replace time result)\n - #96679 (Quick fix for #96223.)\n - #96684 (Update `ProjectionElem::Downcast` documentation)\n - #96686 (Add some TAIT-related tests)\n \n Failed merges:\n \n r? `@ghost`\n `@rustbot` modify labels: rollup" . to_string ( )
272
+ summary : "Auto merge of #96695 - JohnTitor:rollup-oo4fc1h, r=JohnTitor\n \n Rollup of 6 pull requests\n \n Successful merges:\n \n - #96597 (openbsd: unbreak build on native platform)\n - #96662 (Fix typo in lint levels doc)\n - #96668 (Fix flaky rustdoc-ui test because it did not replace time result)\n - #96679 (Quick fix for #96223.)\n - #96684 (Update `ProjectionElem::Downcast` documentation)\n - #96686 (Add some TAIT-related tests)\n \n Failed merges:\n \n r? `@ghost`\n `@rustbot` modify labels: rollup" . to_string ( ) ,
273
+ committer,
260
274
} ;
261
275
assert_eq ! ( c, expected_c)
262
276
}
0 commit comments