@@ -3,7 +3,7 @@ use reqwest::header::{HeaderMap, HeaderValue, InvalidHeaderValue, AUTHORIZATION,
33use reqwest:: { blocking:: Client , blocking:: Response } ;
44use serde:: { Deserialize , Serialize } ;
55
6- use crate :: { parse_to_naive_date, Commit , GitDate } ;
6+ use crate :: { parse_to_naive_date, Author , Commit , GitDate , BORS_AUTHOR } ;
77
88#[ derive( Serialize , Deserialize , Debug ) ]
99struct GithubCommitComparison {
@@ -16,8 +16,8 @@ struct GithubCommitElem {
1616}
1717#[ derive( Serialize , Deserialize , Debug ) ]
1818struct GithubCommit {
19- author : GithubAuthor ,
20- committer : GithubAuthor ,
19+ author : Option < GithubAuthor > ,
20+ committer : Option < GithubAuthor > ,
2121 message : String ,
2222}
2323#[ derive( Serialize , Deserialize , Debug ) ]
@@ -38,19 +38,33 @@ pub(crate) struct GithubComment {
3838
3939impl GithubCommitElem {
4040 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" ) ?;
4549 Ok ( parse_to_naive_date ( date_str) ?)
4650 }
4751
4852 fn git_commit ( self ) -> anyhow:: Result < Commit > {
4953 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+ } ;
5063 Ok ( Commit {
5164 sha : self . sha ,
5265 date,
5366 summary : self . commit . message ,
67+ committer,
5468 } )
5569 }
5670}
@@ -123,13 +137,11 @@ impl CommitsQuery<'_> {
123137 let mut commits = Vec :: new ( ) ;
124138
125139 // focus on Pull Request merges, all authored and committed by bors.
126- let author = "bors" ;
127-
128140 let client = Client :: builder ( ) . default_headers ( headers ( ) ?) . build ( ) ?;
129141 for page in 1 .. {
130142 let url = CommitsUrl {
131143 page,
132- author,
144+ author : BORS_AUTHOR ,
133145 since : self . since_date ,
134146 sha : self . most_recent_sha ,
135147 }
@@ -138,21 +150,17 @@ impl CommitsQuery<'_> {
138150 let response: Response = client. get ( & url) . send ( ) ?;
139151
140152 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 {
148155 eprintln ! (
149156 "ending github query because we found starting sha: {}" ,
150157 elem. sha
151158 ) ;
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 } )
156164 } ) ?;
157165
158166 if let Loop :: Break = action {
@@ -254,9 +262,15 @@ mod tests {
254262 #[ test]
255263 fn test_github ( ) {
256264 let c = get_commit ( "25674202bb7415e0c0ecd07856749cfb7f591be6" ) . unwrap ( ) ;
265+ let committer = Author {
266+ name : String :: from ( "bors" ) ,
267+ email : String :: from ( "bors@rust-lang.org" ) ,
268+ date : GitDate :: from_ymd_opt ( 2022 , 5 , 4 ) . unwrap ( ) ,
269+ } ;
257270 let expected_c = Commit { sha : "25674202bb7415e0c0ecd07856749cfb7f591be6" . to_string ( ) ,
258271 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,
260274 } ;
261275 assert_eq ! ( c, expected_c)
262276 }
0 commit comments