diff --git a/src/bors/handlers/mod.rs b/src/bors/handlers/mod.rs index 7b76da53..7a9f77eb 100644 --- a/src/bors/handlers/mod.rs +++ b/src/bors/handlers/mod.rs @@ -185,6 +185,11 @@ async fn handle_comment( let pr_number = comment.pr_number; let commands = ctx.parser.parse_commands(&comment.text); + // Bail if no commands + if commands.is_empty() { + return Ok(()); + } + tracing::debug!("Commands: {commands:?}"); tracing::trace!("Text: {}", comment.text); @@ -324,4 +329,14 @@ mod tests { }) .await; } + + #[sqlx::test] + async fn do_not_load_pr_on_unrelated_comment(pool: sqlx::PgPool) { + run_test(pool, |mut tester| async { + tester.default_repo().lock().pull_request_error = true; + tester.post_comment("no command").await?; + Ok(tester) + }) + .await; + } } diff --git a/src/tests/mocks/pull_request.rs b/src/tests/mocks/pull_request.rs index 29b8bf39..876710dd 100644 --- a/src/tests/mocks/pull_request.rs +++ b/src/tests/mocks/pull_request.rs @@ -30,11 +30,17 @@ pub async fn mock_pull_requests( let repo_name = repo.lock().name.clone(); let prs = repo.lock().pull_requests.clone(); for &pr_number in prs.keys() { + let repo_clone = repo.clone(); Mock::given(method("GET")) .and(path(format!("/repos/{repo_name}/pulls/{pr_number}"))) - .respond_with( - ResponseTemplate::new(200).set_body_json(GitHubPullRequest::new(pr_number)), - ) + .respond_with(move |_: &Request| { + let pull_request_error = repo_clone.lock().pull_request_error.clone(); + if pull_request_error { + ResponseTemplate::new(500) + } else { + ResponseTemplate::new(200).set_body_json(GitHubPullRequest::new(pr_number)) + } + }) .mount(mock_server) .await; diff --git a/src/tests/mocks/repository.rs b/src/tests/mocks/repository.rs index f634c0ba..4259cd5c 100644 --- a/src/tests/mocks/repository.rs +++ b/src/tests/mocks/repository.rs @@ -58,6 +58,8 @@ pub struct Repo { pub cancelled_workflows: Vec, pub workflow_cancel_error: bool, pub pull_requests: HashMap, + // Cause pull request fetch to fail. + pub pull_request_error: bool, } impl Repo { @@ -73,6 +75,7 @@ impl Repo { cancelled_workflows: vec![], workflow_cancel_error: false, pull_requests, + pull_request_error: false, } }