11use anyhow:: Context ;
22use octocrab:: Octocrab ;
33use octocrab:: models:: checks:: CheckRun ;
4- use octocrab:: models:: { App , Repository } ;
4+ use octocrab:: models:: { App , CheckSuiteId , Repository } ;
55use octocrab:: params:: checks:: { CheckRunConclusion , CheckRunOutput , CheckRunStatus } ;
6+ use std:: fmt:: Debug ;
67use tracing:: log;
78
89use crate :: bors:: event:: PullRequestComment ;
@@ -16,6 +17,7 @@ use crate::github::api::operations::{
1617use crate :: github:: { CommitSha , GithubRepoName , PullRequest , PullRequestNumber } ;
1718use crate :: utils:: timing:: { measure_network_request, perform_network_request_with_retry} ;
1819use futures:: TryStreamExt ;
20+ use serde:: de:: DeserializeOwned ;
1921
2022/// Provides access to a single app installation (repository) using the GitHub API.
2123pub struct GithubRepositoryClient {
@@ -96,11 +98,7 @@ impl GithubRepositoryClient {
9698 perform_network_request_with_retry ( "get_branch_sha" , || async {
9799 // https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#get-a-branch
98100 let branch: octocrab:: models:: repos:: Branch = self
99- . client
100- . get (
101- format ! ( "/repos/{}/branches/{name}" , self . repository( ) ) . as_str ( ) ,
102- None :: < & ( ) > ,
103- )
101+ . get_request ( & format ! ( "branches/{name}" ) )
104102 . await
105103 . context ( "Cannot deserialize branch" ) ?;
106104 Ok ( CommitSha ( branch. commit . sha ) )
@@ -210,6 +208,7 @@ impl GithubRepositoryClient {
210208 ) -> anyhow:: Result < Vec < CheckSuite > > {
211209 #[ derive( serde:: Deserialize , Debug ) ]
212210 struct CheckSuitePayload {
211+ id : CheckSuiteId ,
213212 conclusion : Option < String > ,
214213 head_branch : String ,
215214 }
@@ -221,17 +220,7 @@ impl GithubRepositoryClient {
221220
222221 perform_network_request_with_retry ( "get_check_suites_for_commit" , || async {
223222 let response: CheckSuiteResponse = self
224- . client
225- . get (
226- format ! (
227- "/repos/{}/{}/commits/{}/check-suites" ,
228- self . repo_name. owner( ) ,
229- self . repo_name. name( ) ,
230- sha. 0
231- )
232- . as_str ( ) ,
233- None :: < & ( ) > ,
234- )
223+ . get_request ( & format ! ( "commits/{}/check-suites" , sha. 0 ) )
235224 . await
236225 . context ( "Cannot fetch CheckSuiteResponse" ) ?;
237226
@@ -240,6 +229,7 @@ impl GithubRepositoryClient {
240229 . into_iter ( )
241230 . filter ( |suite| suite. head_branch == branch)
242231 . map ( |suite| CheckSuite {
232+ id : suite. id ,
243233 status : match suite. conclusion {
244234 Some ( status) => match status. as_str ( ) {
245235 "success" => CheckSuiteStatus :: Success ,
@@ -249,14 +239,19 @@ impl GithubRepositoryClient {
249239 }
250240 _ => {
251241 tracing:: warn!(
252- "Received unknown check suite status for {}/{}: {status}" ,
253- self . repo_name,
254- sha
242+ "Received unknown check suite conclusion for {}@{sha}: {status}" ,
243+ self . repo_name
255244 ) ;
256245 CheckSuiteStatus :: Pending
257246 }
258247 } ,
259- None => CheckSuiteStatus :: Pending ,
248+ None => {
249+ tracing:: warn!(
250+ "Received empty check suite conclusion for {}@{sha}" ,
251+ self . repo_name,
252+ ) ;
253+ CheckSuiteStatus :: Pending
254+ }
260255 } ,
261256 } )
262257 . collect ( ) ;
@@ -384,6 +379,18 @@ impl GithubRepositoryClient {
384379 Ok ( prs)
385380 }
386381
382+ async fn get_request < T : DeserializeOwned + Debug > ( & self , path : & str ) -> anyhow:: Result < T > {
383+ let url = format ! (
384+ "/repos/{}/{}/{path}" ,
385+ self . repo_name. owner( ) ,
386+ self . repo_name. name( ) ,
387+ ) ;
388+ tracing:: debug!( "Sending request to {url}" ) ;
389+ let response: T = self . client . get ( url. as_str ( ) , None :: < & ( ) > ) . await ?;
390+ tracing:: debug!( "Received response: {response:?}" ) ;
391+ Ok ( response)
392+ }
393+
387394 fn format_pr ( & self , pr : PullRequestNumber ) -> String {
388395 format ! ( "{}/{}" , self . repository( ) , pr)
389396 }
0 commit comments