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) ) ) ;
@@ -247,7 +251,7 @@ pub struct Issue {
247
251
pub number : u64 ,
248
252
#[ serde( deserialize_with = "opt_string" ) ]
249
253
pub body : String ,
250
- created_at : chrono:: DateTime < Utc > ,
254
+ pub created_at : chrono:: DateTime < Utc > ,
251
255
pub updated_at : chrono:: DateTime < Utc > ,
252
256
/// The SHA for a merge commit.
253
257
///
@@ -263,6 +267,7 @@ pub struct Issue {
263
267
pub html_url : String ,
264
268
pub user : User ,
265
269
pub labels : Vec < Label > ,
270
+ pub milestone : Option < Milestone > ,
266
271
pub assignees : Vec < User > ,
267
272
/// Indicator if this is a pull request.
268
273
///
@@ -329,6 +334,7 @@ impl ZulipGitHubReference {
329
334
330
335
#[ derive( Debug , serde:: Deserialize ) ]
331
336
pub struct Comment {
337
+ pub id : i64 ,
332
338
#[ serde( deserialize_with = "opt_string" ) ]
333
339
pub body : String ,
334
340
pub html_url : String ,
@@ -475,12 +481,22 @@ impl Issue {
475
481
self . state == IssueState :: Open
476
482
}
477
483
478
- pub async fn get_comment ( & self , client : & GithubClient , id : usize ) -> anyhow:: Result < Comment > {
484
+ pub async fn get_comment ( & self , client : & GithubClient , id : u64 ) -> anyhow:: Result < Comment > {
479
485
let comment_url = format ! ( "{}/issues/comments/{}" , self . repository( ) . url( client) , id) ;
480
486
let comment = client. json ( client. get ( & comment_url) ) . await ?;
481
487
Ok ( comment)
482
488
}
483
489
490
+ pub async fn get_comments ( & self , client : & GithubClient ) -> anyhow:: Result < Vec < Comment > > {
491
+ let comment_url = format ! (
492
+ "{}/issues/{}/comments" ,
493
+ self . repository( ) . url( client) ,
494
+ self . number
495
+ ) ;
496
+ let comments = client. json ( client. get ( & comment_url) ) . await ?;
497
+ Ok ( comments)
498
+ }
499
+
484
500
pub async fn edit_body ( & self , client : & GithubClient , body : & str ) -> anyhow:: Result < ( ) > {
485
501
let edit_url = format ! ( "{}/issues/{}" , self . repository( ) . url( client) , self . number) ;
486
502
#[ derive( serde:: Serialize ) ]
@@ -854,8 +870,8 @@ struct MilestoneCreateBody<'a> {
854
870
855
871
#[ derive( Debug , serde:: Deserialize ) ]
856
872
pub struct Milestone {
857
- number : u64 ,
858
- title : String ,
873
+ pub number : u64 ,
874
+ pub title : String ,
859
875
}
860
876
861
877
#[ derive( Debug , serde:: Deserialize ) ]
@@ -1064,6 +1080,15 @@ impl Repository {
1064
1080
|| filters. iter ( ) . any ( |& ( key, _) | key == "no" )
1065
1081
|| is_pr && !include_labels. is_empty ( ) ;
1066
1082
1083
+ let set_is_pr = |issues : & mut [ Issue ] | {
1084
+ if !is_pr {
1085
+ return ;
1086
+ }
1087
+ for issue in issues {
1088
+ issue. pull_request = Some ( PullRequestDetails { } ) ;
1089
+ }
1090
+ } ;
1091
+
1067
1092
// If there are more than `per_page` of issues, we need to paginate
1068
1093
let mut issues = vec ! [ ] ;
1069
1094
loop {
@@ -1083,10 +1108,11 @@ impl Repository {
1083
1108
1084
1109
let result = client. get ( & url) ;
1085
1110
if use_search_api {
1086
- let result = client
1111
+ let mut result = client
1087
1112
. json :: < IssueSearchResult > ( result)
1088
1113
. await
1089
1114
. with_context ( || format ! ( "failed to list issues from {}" , url) ) ?;
1115
+ set_is_pr ( & mut result. items ) ;
1090
1116
issues. extend ( result. items ) ;
1091
1117
if issues. len ( ) < result. total_count {
1092
1118
ordering. page += 1 ;
@@ -1097,7 +1123,8 @@ impl Repository {
1097
1123
issues = client
1098
1124
. json ( result)
1099
1125
. await
1100
- . with_context ( || format ! ( "failed to list issues from {}" , url) ) ?
1126
+ . with_context ( || format ! ( "failed to list issues from {}" , url) ) ?;
1127
+ set_is_pr ( & mut issues) ;
1101
1128
}
1102
1129
1103
1130
break ;
@@ -1237,7 +1264,7 @@ impl Repository {
1237
1264
client : & GithubClient ,
1238
1265
refname : & str ,
1239
1266
sha : & str ,
1240
- ) -> anyhow:: Result < ( ) > {
1267
+ ) -> anyhow:: Result < GitReference > {
1241
1268
let url = format ! ( "{}/git/refs/{}" , self . url( client) , refname) ;
1242
1269
client
1243
1270
. json ( client. patch ( & url) . json ( & serde_json:: json!( {
@@ -1250,8 +1277,7 @@ impl Repository {
1250
1277
"{} failed to update reference {refname} to {sha}" ,
1251
1278
self . full_name
1252
1279
)
1253
- } ) ?;
1254
- Ok ( ( ) )
1280
+ } )
1255
1281
}
1256
1282
1257
1283
/// Returns a list of recent commits on the given branch.
@@ -1511,6 +1537,16 @@ impl Repository {
1511
1537
} ) ?;
1512
1538
Ok ( ( ) )
1513
1539
}
1540
+
1541
+ pub async fn get_pr ( & self , client : & GithubClient , number : u64 ) -> anyhow:: Result < Issue > {
1542
+ let url = format ! ( "{}/pulls/{number}" , self . url( client) ) ;
1543
+ let mut pr: Issue = client
1544
+ . json ( client. get ( & url) )
1545
+ . await
1546
+ . with_context ( || format ! ( "{} failed to get pr {number}" , self . full_name) ) ?;
1547
+ pr. pull_request = Some ( PullRequestDetails { } ) ;
1548
+ Ok ( pr)
1549
+ }
1514
1550
}
1515
1551
1516
1552
pub struct Query < ' a > {
@@ -1812,12 +1848,14 @@ impl GithubClient {
1812
1848
let req = req
1813
1849
. build ( )
1814
1850
. with_context ( || format ! ( "failed to build request {:?}" , req_dbg) ) ?;
1851
+ let test_capture_info = test_record:: capture_request ( & req) ;
1815
1852
let resp = self . client . execute ( req) . await . context ( req_dbg. clone ( ) ) ?;
1816
1853
let status = resp. status ( ) ;
1817
1854
let body = resp
1818
1855
. bytes ( )
1819
1856
. await
1820
1857
. with_context ( || format ! ( "failed to read response body {req_dbg}" ) ) ?;
1858
+ test_record:: record_request ( test_capture_info, status, & body) ;
1821
1859
match status {
1822
1860
StatusCode :: OK => Ok ( Some ( body) ) ,
1823
1861
StatusCode :: NOT_FOUND => Ok ( None ) ,
@@ -1970,6 +2008,7 @@ pub struct GitTreeEntry {
1970
2008
pub sha : String ,
1971
2009
}
1972
2010
2011
+ #[ derive( Debug ) ]
1973
2012
pub struct RecentCommit {
1974
2013
pub title : String ,
1975
2014
pub pr_num : Option < i32 > ,
0 commit comments