Skip to content

Commit 038b313

Browse files
authored
Merge pull request #359 from Kobzol/logging
Add more logging around check suites
2 parents 20f1570 + f133817 commit 038b313

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

src/bors/handlers/workflow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ async fn try_complete_build(
170170
.iter()
171171
.any(|check| matches!(check.status, CheckSuiteStatus::Pending))
172172
{
173+
tracing::debug!("Some check suites are still pending: {checks:?}");
173174
return Ok(());
174175
}
175176

src/bors/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use std::fmt;
22
use std::str::FromStr;
33

44
use arc_swap::ArcSwap;
5-
65
pub use command::CommandParser;
76
pub use command::RollupMode;
87
pub use comment::Comment;
98
pub use context::BorsContext;
109
pub use handlers::{handle_bors_global_event, handle_bors_repository_event};
10+
use octocrab::models::CheckSuiteId;
1111
use serde::Serialize;
1212

1313
use crate::config::RepositoryConfig;
@@ -48,7 +48,8 @@ pub enum CheckSuiteStatus {
4848
/// Corresponds to a single GitHub actions workflow run, or to a single external CI check run.
4949
#[derive(Clone, Debug)]
5050
pub struct CheckSuite {
51-
pub(crate) status: CheckSuiteStatus,
51+
pub id: CheckSuiteId,
52+
pub status: CheckSuiteStatus,
5253
}
5354

5455
/// An access point to a single repository.

src/github/api/client.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use anyhow::Context;
22
use octocrab::Octocrab;
33
use octocrab::models::checks::CheckRun;
4-
use octocrab::models::{App, Repository};
4+
use octocrab::models::{App, CheckSuiteId, Repository};
55
use octocrab::params::checks::{CheckRunConclusion, CheckRunOutput, CheckRunStatus};
6+
use std::fmt::Debug;
67
use tracing::log;
78

89
use crate::bors::event::PullRequestComment;
@@ -16,6 +17,7 @@ use crate::github::api::operations::{
1617
use crate::github::{CommitSha, GithubRepoName, PullRequest, PullRequestNumber};
1718
use crate::utils::timing::{measure_network_request, perform_network_request_with_retry};
1819
use futures::TryStreamExt;
20+
use serde::de::DeserializeOwned;
1921

2022
/// Provides access to a single app installation (repository) using the GitHub API.
2123
pub 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
}

src/tests/mocks/repository.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{collections::HashMap, time::SystemTime};
44
use crate::bors::{CheckSuiteStatus, PullRequestStatus};
55
use base64::Engine;
66
use chrono::{DateTime, Utc};
7+
use octocrab::models::CheckSuiteId;
78
use octocrab::models::pulls::MergeableState;
89
use octocrab::models::repos::Object;
910
use octocrab::models::repos::Object::Commit;
@@ -574,6 +575,7 @@ async fn mock_merge_branch(repo: Arc<Mutex<Repo>>, mock_server: &MockServer) {
574575
async fn mock_check_suites(repo: Arc<Mutex<Repo>>, mock_server: &MockServer) {
575576
#[derive(serde::Serialize)]
576577
struct CheckSuitePayload {
578+
id: CheckSuiteId,
577579
conclusion: Option<String>,
578580
head_branch: String,
579581
}
@@ -594,7 +596,9 @@ async fn mock_check_suites(repo: Arc<Mutex<Repo>>, mock_server: &MockServer) {
594596
check_suites: branch
595597
.get_suites()
596598
.iter()
597-
.map(|suite| CheckSuitePayload {
599+
.enumerate()
600+
.map(|(index, suite)| CheckSuitePayload {
601+
id: CheckSuiteId(index as u64),
598602
conclusion: match suite {
599603
CheckSuiteStatus::Pending => None,
600604
CheckSuiteStatus::Success => Some("success".to_string()),

0 commit comments

Comments
 (0)