Skip to content
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
24 changes: 6 additions & 18 deletions src/handlers/concern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
github::{Event, Label},
handlers::Context,
interactions::EditIssueBody,
utils::is_issue_under_rfcbot_fcp,
};
use parser::command::concern::ConcernCommand;

Expand Down Expand Up @@ -45,24 +46,11 @@ pub(super) async fn handle_command(
};
let issue = &issue_comment.issue;

// Verify that this issue isn't a rfcbot FCP, skip if it is
match crate::rfcbot::get_all_fcps().await {
Ok(fcps) => {
if fcps.iter().any(|(_, fcp)| {
u64::from(fcp.issue.number) == issue.number
&& fcp.issue.repository == issue_comment.repository.full_name
}) {
tracing::info!(
"{}#{} tried to register a concern, blocked by our rfcbot FCP check",
issue_comment.repository.full_name,
issue.number,
);
return Ok(());
}
}
Err(err) => {
tracing::warn!("unable to fetch rfcbot active FCPs: {err:?}, skipping check");
}
// Verify that this issue isn't a rfcbot FCP
if is_issue_under_rfcbot_fcp(&issue_comment.repository.full_name, issue.number).await {
return user_error!(
"Cannot set `@rustbot concern` on an active [rfcbot](https://rfcbot.rs/) FCP, use `@rfcbot concern` instead."
);
}

// Verify that the comment author is a team member in our team repo
Expand Down
14 changes: 14 additions & 0 deletions src/handlers/major_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Display;

use crate::errors::user_error;
use crate::jobs::Job;
use crate::utils::is_issue_under_rfcbot_fcp;
use crate::zulip::api::Recipient;
use crate::{
config::MajorChangeConfig,
Expand Down Expand Up @@ -262,6 +263,13 @@ pub(super) async fn handle_command(
return user_error!("Only team members can second issues.");
}

// Verify that this issue isn't a rfcbot FCP
if is_issue_under_rfcbot_fcp(&issue.repository().full_repo_name(), issue.number).await {
return user_error!(
"Cannot second a major change on an active [rfcbot](https://rfcbot.rs/) FCP."
);
}

let has_concerns = if let Some(concerns_label) = &config.concerns_label {
issue.labels().iter().any(|l| &l.name == concerns_label)
} else {
Expand Down Expand Up @@ -474,6 +482,7 @@ enum SecondedLogicError {
at: DateTime<Utc>,
},
NoMajorChangeConfig,
UnderRfcBotFcp,
}

impl std::error::Error for SecondedLogicError {}
Expand Down Expand Up @@ -506,6 +515,7 @@ impl Display for SecondedLogicError {
write!(f, "concerns label added at {at}")
}
SecondedLogicError::NoMajorChangeConfig => write!(f, "no `[major_change]` config"),
SecondedLogicError::UnderRfcBotFcp => write!(f, "under rfcbot fcp"),
}
}
}
Expand Down Expand Up @@ -679,6 +689,10 @@ async fn try_accept_mcp(
open: issue.is_open()
});
}

if is_issue_under_rfcbot_fcp(&major_change.repo, major_change.issue).await {
anyhow::bail!(SecondedLogicError::UnderRfcBotFcp);
}
}

if !issue.labels.iter().any(|l| l.name == config.accept_label) {
Expand Down
21 changes: 21 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,24 @@ pub(crate) async fn is_repo_autorized(

Ok(true)
}

pub(crate) async fn is_issue_under_rfcbot_fcp(
issue_full_repo_name: &str,
issue_number: u64,
) -> bool {
match crate::rfcbot::get_all_fcps().await {
Ok(fcps) => {
if fcps.iter().any(|(_, fcp)| {
u64::from(fcp.issue.number) == issue_number
&& fcp.issue.repository == issue_full_repo_name
}) {
return true;
}
}
Err(err) => {
tracing::warn!("unable to fetch rfcbot active FCPs: {err:?}, skipping check");
}
}

false
}
Loading