Skip to content

Commit bedaab5

Browse files
committed
fix: prevent spam errors
1 parent 417c8e7 commit bedaab5

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/bors/handlers/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ async fn handle_comment(
185185
let pr_number = comment.pr_number;
186186
let commands = ctx.parser.parse_commands(&comment.text);
187187

188+
// Bail if no commands
189+
if commands.is_empty() {
190+
return Ok(());
191+
}
192+
188193
tracing::debug!("Commands: {commands:?}");
189194
tracing::trace!("Text: {}", comment.text);
190195

@@ -324,4 +329,15 @@ mod tests {
324329
})
325330
.await;
326331
}
332+
333+
#[tracing_test::traced_test]
334+
#[sqlx::test]
335+
async fn pr_fetch_error(pool: sqlx::PgPool) {
336+
run_test(pool, |mut tester| async {
337+
tester.default_repo().lock().pull_request_error = true;
338+
tester.post_comment("no command").await?;
339+
Ok(tester)
340+
})
341+
.await;
342+
}
327343
}

src/tests/mocks/pull_request.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ pub async fn mock_pull_requests(
3030
let repo_name = repo.lock().name.clone();
3131
let prs = repo.lock().pull_requests.clone();
3232
for &pr_number in prs.keys() {
33+
let repo_clone = repo.clone();
3334
Mock::given(method("GET"))
3435
.and(path(format!("/repos/{repo_name}/pulls/{pr_number}")))
35-
.respond_with(
36-
ResponseTemplate::new(200).set_body_json(GitHubPullRequest::new(pr_number)),
37-
)
36+
.respond_with(move |_: &Request| {
37+
let pull_request_error = repo_clone.lock().pull_request_error.clone();
38+
if pull_request_error {
39+
ResponseTemplate::new(500)
40+
} else {
41+
ResponseTemplate::new(200).set_body_json(GitHubPullRequest::new(pr_number))
42+
}
43+
})
3844
.mount(mock_server)
3945
.await;
4046

src/tests/mocks/repository.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct Repo {
5858
pub cancelled_workflows: Vec<u64>,
5959
pub workflow_cancel_error: bool,
6060
pub pull_requests: HashMap<u64, PullRequest>,
61+
pub pull_request_error: bool,
6162
}
6263

6364
impl Repo {
@@ -73,6 +74,7 @@ impl Repo {
7374
cancelled_workflows: vec![],
7475
workflow_cancel_error: false,
7576
pull_requests,
77+
pull_request_error: false,
7678
}
7779
}
7880

0 commit comments

Comments
 (0)