Only look for open PRs
@@ -579,8 +579,16 @@ impl RFDUpdateAction for UpdatePullRequest {
..
} = ctx;
- if pull_requests.len() == 1 {
- if let Some(pull_request) = pull_requests.iter().next() {
+ // We only want to operate on open pull requests
+ let open_prs = pull_requests
+ .iter()
+ .filter(|pr| pr.state == "open")
+ .collect::<Vec<&GitHubPullRequest>>();
+
+ // 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 {
+ 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.
if rfd.name != pull_request.title {
@@ -663,8 +671,16 @@ impl RFDUpdateAction for UpdateDiscussionUrl {
let mut requires_source_commit = false;
- if pull_requests.len() == 1 {
- if let Some(pull_request) = pull_requests.iter().next() {
+ // We only want to operate on open pull requests
+ let open_prs = pull_requests
+ .iter()
+ .filter(|pr| pr.state == "open")
+ .collect::<Vec<&GitHubPullRequest>>();
+
+ // 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 {
+ 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
if rfd.discussion != pull_request.html_url && !pull_request.html_url.is_empty() {
@@ -705,6 +721,12 @@ impl RFDUpdateAction for EnsureRFDWithPullRequestIsInValidState {
let mut requires_source_commit = false;
+ // We only want to operate on open pull requests
+ let open_prs = pull_requests.iter().filter(|pr| pr.state == "open");
+
+ // 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 {
// 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
@@ -727,16 +749,15 @@ impl RFDUpdateAction for EnsureRFDWithPullRequestIsInValidState {
&& rfd.state != "ideation"
&& rfd.state != "abandoned"
{
- if pull_requests.len() == 1 {
rfd.update_state("discussion").map_err(RFDUpdateActionErr::Stop)?;
requires_source_commit = true;
+ }
} else {
info!(
"Found multiple pull requests for RFD {}. Unable to update state to discussion",
rfd.number
);
}
- }
Ok(RFDUpdateActionResponse { requires_source_commit })
}
