1
+ use crate :: test_record;
1
2
use anyhow:: { anyhow, Context } ;
2
3
use async_trait:: async_trait;
3
4
use bytes:: Bytes ;
@@ -30,15 +31,18 @@ impl GithubClient {
30
31
. build ( )
31
32
. with_context ( || format ! ( "building reqwest {}" , req_dbg) ) ?;
32
33
34
+ let test_capture_info = test_record:: capture_request ( & req) ;
33
35
let mut resp = self . client . execute ( req. try_clone ( ) . unwrap ( ) ) . await ?;
34
36
if let Some ( sleep) = Self :: needs_retry ( & resp) . await {
35
37
resp = self . retry ( req, sleep, MAX_ATTEMPTS ) . await ?;
36
38
}
39
+ let status = resp. status ( ) ;
37
40
let maybe_err = resp. error_for_status_ref ( ) . err ( ) ;
38
41
let body = resp
39
42
. bytes ( )
40
43
. await
41
44
. with_context ( || format ! ( "failed to read response body {req_dbg}" ) ) ?;
45
+ test_record:: record_request ( test_capture_info, status, & body) ;
42
46
if let Some ( e) = maybe_err {
43
47
return Err ( anyhow:: Error :: new ( e) )
44
48
. with_context ( || format ! ( "response: {}" , String :: from_utf8_lossy( & body) ) ) ;
@@ -248,7 +252,7 @@ pub struct Issue {
248
252
pub number : u64 ,
249
253
#[ serde( deserialize_with = "opt_string" ) ]
250
254
pub body : String ,
251
- created_at : chrono:: DateTime < Utc > ,
255
+ pub created_at : chrono:: DateTime < Utc > ,
252
256
pub updated_at : chrono:: DateTime < Utc > ,
253
257
/// The SHA for a merge commit.
254
258
///
@@ -264,6 +268,7 @@ pub struct Issue {
264
268
pub html_url : String ,
265
269
pub user : User ,
266
270
pub labels : Vec < Label > ,
271
+ pub milestone : Option < Milestone > ,
267
272
pub assignees : Vec < User > ,
268
273
/// Indicator if this is a pull request.
269
274
///
@@ -330,6 +335,7 @@ impl ZulipGitHubReference {
330
335
331
336
#[ derive( Debug , serde:: Deserialize ) ]
332
337
pub struct Comment {
338
+ pub id : i64 ,
333
339
#[ serde( deserialize_with = "opt_string" ) ]
334
340
pub body : String ,
335
341
pub html_url : String ,
@@ -476,12 +482,22 @@ impl Issue {
476
482
self . state == IssueState :: Open
477
483
}
478
484
479
- pub async fn get_comment ( & self , client : & GithubClient , id : usize ) -> anyhow:: Result < Comment > {
485
+ pub async fn get_comment ( & self , client : & GithubClient , id : u64 ) -> anyhow:: Result < Comment > {
480
486
let comment_url = format ! ( "{}/issues/comments/{}" , self . repository( ) . url( client) , id) ;
481
487
let comment = client. json ( client. get ( & comment_url) ) . await ?;
482
488
Ok ( comment)
483
489
}
484
490
491
+ pub async fn get_comments ( & self , client : & GithubClient ) -> anyhow:: Result < Vec < Comment > > {
492
+ let comment_url = format ! (
493
+ "{}/issues/{}/comments" ,
494
+ self . repository( ) . url( client) ,
495
+ self . number
496
+ ) ;
497
+ let comments = client. json ( client. get ( & comment_url) ) . await ?;
498
+ Ok ( comments)
499
+ }
500
+
485
501
pub async fn edit_body ( & self , client : & GithubClient , body : & str ) -> anyhow:: Result < ( ) > {
486
502
let edit_url = format ! ( "{}/issues/{}" , self . repository( ) . url( client) , self . number) ;
487
503
#[ derive( serde:: Serialize ) ]
@@ -855,8 +871,8 @@ struct MilestoneCreateBody<'a> {
855
871
856
872
#[ derive( Debug , serde:: Deserialize ) ]
857
873
pub struct Milestone {
858
- number : u64 ,
859
- title : String ,
874
+ pub number : u64 ,
875
+ pub title : String ,
860
876
}
861
877
862
878
#[ derive( Debug , serde:: Deserialize ) ]
@@ -1066,6 +1082,15 @@ impl Repository {
1066
1082
|| filters. iter ( ) . any ( |& ( key, _) | key == "no" )
1067
1083
|| is_pr && !include_labels. is_empty ( ) ;
1068
1084
1085
+ let set_is_pr = |issues : & mut [ Issue ] | {
1086
+ if !is_pr {
1087
+ return ;
1088
+ }
1089
+ for issue in issues {
1090
+ issue. pull_request = Some ( PullRequestDetails { } ) ;
1091
+ }
1092
+ } ;
1093
+
1069
1094
// If there are more than `per_page` of issues, we need to paginate
1070
1095
let mut issues = vec ! [ ] ;
1071
1096
loop {
@@ -1085,10 +1110,11 @@ impl Repository {
1085
1110
1086
1111
let result = client. get ( & url) ;
1087
1112
if use_search_api {
1088
- let result = client
1113
+ let mut result = client
1089
1114
. json :: < IssueSearchResult > ( result)
1090
1115
. await
1091
1116
. with_context ( || format ! ( "failed to list issues from {}" , url) ) ?;
1117
+ set_is_pr ( & mut result. items ) ;
1092
1118
issues. extend ( result. items ) ;
1093
1119
if issues. len ( ) < result. total_count {
1094
1120
ordering. page += 1 ;
@@ -1099,7 +1125,8 @@ impl Repository {
1099
1125
issues = client
1100
1126
. json ( result)
1101
1127
. await
1102
- . with_context ( || format ! ( "failed to list issues from {}" , url) ) ?
1128
+ . with_context ( || format ! ( "failed to list issues from {}" , url) ) ?;
1129
+ set_is_pr ( & mut issues) ;
1103
1130
}
1104
1131
1105
1132
break ;
@@ -1239,7 +1266,7 @@ impl Repository {
1239
1266
client : & GithubClient ,
1240
1267
refname : & str ,
1241
1268
sha : & str ,
1242
- ) -> anyhow:: Result < ( ) > {
1269
+ ) -> anyhow:: Result < GitReference > {
1243
1270
let url = format ! ( "{}/git/refs/{}" , self . url( client) , refname) ;
1244
1271
client
1245
1272
. json ( client. patch ( & url) . json ( & serde_json:: json!( {
@@ -1252,8 +1279,7 @@ impl Repository {
1252
1279
"{} failed to update reference {refname} to {sha}" ,
1253
1280
self . full_name
1254
1281
)
1255
- } ) ?;
1256
- Ok ( ( ) )
1282
+ } )
1257
1283
}
1258
1284
1259
1285
/// Returns a list of recent commits on the given branch.
@@ -1563,6 +1589,16 @@ impl Repository {
1563
1589
} ) ?;
1564
1590
Ok ( ( ) )
1565
1591
}
1592
+
1593
+ pub async fn get_pr ( & self , client : & GithubClient , number : u64 ) -> anyhow:: Result < Issue > {
1594
+ let url = format ! ( "{}/pulls/{number}" , self . url( client) ) ;
1595
+ let mut pr: Issue = client
1596
+ . json ( client. get ( & url) )
1597
+ . await
1598
+ . with_context ( || format ! ( "{} failed to get pr {number}" , self . full_name) ) ?;
1599
+ pr. pull_request = Some ( PullRequestDetails { } ) ;
1600
+ Ok ( pr)
1601
+ }
1566
1602
}
1567
1603
1568
1604
pub struct Query < ' a > {
@@ -1864,12 +1900,14 @@ impl GithubClient {
1864
1900
let req = req
1865
1901
. build ( )
1866
1902
. with_context ( || format ! ( "failed to build request {:?}" , req_dbg) ) ?;
1903
+ let test_capture_info = test_record:: capture_request ( & req) ;
1867
1904
let resp = self . client . execute ( req) . await . context ( req_dbg. clone ( ) ) ?;
1868
1905
let status = resp. status ( ) ;
1869
1906
let body = resp
1870
1907
. bytes ( )
1871
1908
. await
1872
1909
. with_context ( || format ! ( "failed to read response body {req_dbg}" ) ) ?;
1910
+ test_record:: record_request ( test_capture_info, status, & body) ;
1873
1911
match status {
1874
1912
StatusCode :: OK => Ok ( Some ( body) ) ,
1875
1913
StatusCode :: NOT_FOUND => Ok ( None ) ,
@@ -2022,6 +2060,7 @@ pub struct GitTreeEntry {
2022
2060
pub sha : String ,
2023
2061
}
2024
2062
2063
+ #[ derive( Debug ) ]
2025
2064
pub struct RecentCommit {
2026
2065
pub title : String ,
2027
2066
pub pr_num : Option < i32 > ,
0 commit comments