Skip to content

fix: ignore unrelated comments #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/bors/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
12 changes: 9 additions & 3 deletions src/tests/mocks/pull_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/tests/mocks/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct Repo {
pub cancelled_workflows: Vec<u64>,
pub workflow_cancel_error: bool,
pub pull_requests: HashMap<u64, PullRequest>,
// Cause pull request fetch to fail.
pub pull_request_error: bool,
}

impl Repo {
Expand All @@ -73,6 +75,7 @@ impl Repo {
cancelled_workflows: vec![],
workflow_cancel_error: false,
pull_requests,
pull_request_error: false,
}
}

Expand Down