Handle zero pr case
@@ -13,6 +13,7 @@ use google_storage1::{
hyper, hyper_rustls,
};
use log::{info, warn};
+use std::cmp::Ordering;
use crate::context::Context;
@@ -594,7 +595,8 @@ impl RFDUpdateAction for UpdatePullRequest {
// Explicitly we will only update a pull request if it is the only open pull request for the
// branch that we are working on
- if open_prs.len() == 1 {
+ match open_prs.len().cmp(&1) {
+ Ordering::Equal => {
if let Some(pull_request) = open_prs.get(0) {
// Let's make sure the title of the pull request is what it should be.
// The pull request title should be equal to the name of the pull request.
@@ -654,12 +656,17 @@ impl RFDUpdateAction for UpdatePullRequest {
.await
.map_err(RFDUpdateActionErr::Continue)?;
}
- } else {
+ }
+ Ordering::Greater => {
info!(
"Found multiple pull requests for RFD {}. Unable to update title",
rfd.number
);
}
+ Ordering::Less => {
+ // Nothing to do, there are no PRs
+ }
+ }
Ok(RFDUpdateActionResponse::default())
}
@@ -686,7 +693,8 @@ impl RFDUpdateAction for UpdateDiscussionUrl {
// Explicitly we will only update a pull request if it is the only open pull request for the
// branch that we are working on
- if open_prs.len() == 1 {
+ match open_prs.len().cmp(&1) {
+ Ordering::Equal => {
if let Some(pull_request) = open_prs.get(0) {
// If the stored discussion link does not match the PR we found, then and
// update is required
@@ -704,12 +712,17 @@ impl RFDUpdateAction for UpdateDiscussionUrl {
requires_source_commit = true;
}
}
- } else {
+ }
+ Ordering::Greater => {
info!(
"Found multiple pull requests for RFD {}. Unable to update discussion url",
rfd.number
);
}
+ Ordering::Less => {
+ // Nothing to do, there are no PRs
+ }
+ }
Ok(RFDUpdateActionResponse { requires_source_commit })
}
@@ -733,7 +746,8 @@ impl RFDUpdateAction for EnsureRFDWithPullRequestIsInValidState {
// Explicitly we will only update a pull request if it is the only open pull request for the
// branch that we are working on
- if open_prs.count() == 1 {
+ match open_prs.count().cmp(&1) {
+ Ordering::Equal => {
// If there is a pull request open for this branch, then check to ensure that it is in one
// of three valid states:
// * published - A RFD may be in this state if it had previously been published and an
@@ -759,12 +773,17 @@ impl RFDUpdateAction for EnsureRFDWithPullRequestIsInValidState {
rfd.update_state("discussion").map_err(RFDUpdateActionErr::Stop)?;
requires_source_commit = true;
}
- } else {
+ }
+ Ordering::Greater => {
info!(
"Found multiple pull requests for RFD {}. Unable to update state to discussion",
rfd.number
);
}
+ Ordering::Less => {
+ // Nothing to do, there are no PRs
+ }
+ }
Ok(RFDUpdateActionResponse { requires_source_commit })
}
