Skip to content

Commit 85435f6

Browse files
committed
Refactor PR approval validity check
1 parent 78f8362 commit 85435f6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/bors/handlers/review.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub(super) async fn command_approve(
3838
return Ok(());
3939
};
4040

41-
if !matches!(pr.github.status, PullRequestStatus::Open) {
41+
if let Some(error_comment) = check_pr_approval_validity(pr).await? {
4242
repo_state
4343
.client
44-
.post_comment(pr.number(), approve_non_open_pr_comment())
44+
.post_comment(pr.number(), error_comment)
4545
.await?;
4646
return Ok(());
4747
}
@@ -62,6 +62,16 @@ pub(super) async fn command_approve(
6262
notify_of_approval(&repo_state, pr, approver.as_str()).await
6363
}
6464

65+
/// Check that the given PR can be approved in its current state.
66+
/// Returns `Ok(Some(comment))` if it **cannot** be approved; the comment should be sent to the
67+
/// pull request.
68+
async fn check_pr_approval_validity(pr: &PullRequestData) -> anyhow::Result<Option<Comment>> {
69+
if !matches!(pr.github.status, PullRequestStatus::Open) {
70+
return Ok(Some(approve_non_open_pr_comment()));
71+
}
72+
Ok(None)
73+
}
74+
6575
/// Unapprove a pull request.
6676
/// Pull request's author can also unapprove the pull request.
6777
pub(super) async fn command_unapprove(

0 commit comments

Comments
 (0)