diff --git a/migrations/.gitkeep b/migrations/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/migrations/2023-11-25-224550_add_teams_column_to_proposal/down.sql b/migrations/2023-11-25-224550_add_teams_column_to_proposal/down.sql new file mode 100644 index 00000000..2840a963 --- /dev/null +++ b/migrations/2023-11-25-224550_add_teams_column_to_proposal/down.sql @@ -0,0 +1 @@ +ALTER TABLE fcp_proposal DROP COLUMN teams; diff --git a/migrations/2023-11-25-224550_add_teams_column_to_proposal/up.sql b/migrations/2023-11-25-224550_add_teams_column_to_proposal/up.sql new file mode 100644 index 00000000..47097cff --- /dev/null +++ b/migrations/2023-11-25-224550_add_teams_column_to_proposal/up.sql @@ -0,0 +1 @@ +ALTER TABLE fcp_proposal ADD COLUMN teams text[]; diff --git a/src/domain/rfcbot.rs b/src/domain/rfcbot.rs index 9ae18f51..a4a95bfd 100644 --- a/src/domain/rfcbot.rs +++ b/src/domain/rfcbot.rs @@ -41,6 +41,8 @@ pub struct NewFcpProposal<'a> { pub fk_bot_tracking_comment: i32, pub fcp_start: Option, pub fcp_closed: bool, + // `None` here is for proposals started before team support + pub teams: Option<&'a [String]>, } #[derive(Clone, Debug, Eq, Insertable, Ord, PartialEq, PartialOrd, Serialize)] @@ -76,6 +78,8 @@ pub struct FcpProposal { pub fk_bot_tracking_comment: i32, pub fcp_start: Option, pub fcp_closed: bool, + // `None` here is for proposals started before team support + pub teams: Option>, } #[derive(Clone, Debug, Eq, Insertable, Ord, PartialEq, PartialOrd, Serialize)] diff --git a/src/domain/schema.rs b/src/domain/schema.rs index 6d30f577..9783b578 100644 --- a/src/domain/schema.rs +++ b/src/domain/schema.rs @@ -95,6 +95,12 @@ table! { /// /// (Automatically generated by Diesel.) fcp_closed -> Bool, + /// The `teams` column of the `fcp_proposal` table. + /// + /// Its SQL type is `Nullable>`. + /// + /// (Automatically generated by Diesel.) + teams -> Nullable>, } } diff --git a/src/github/nag.rs b/src/github/nag.rs index 7cbc8ef6..85df43d7 100644 --- a/src/github/nag.rs +++ b/src/github/nag.rs @@ -56,6 +56,7 @@ pub fn update_nags(comment: &IssueComment) -> DashResult<()> { .find(comment.fk_user) .first::(conn)?; + let issue_teams = involved_teams(&issue)?; let subteam_members = subteam_members(&issue)?; let all_team_members = all_team_members()?; @@ -84,7 +85,7 @@ pub fn update_nags(comment: &IssueComment) -> DashResult<()> { } debug!("processing rfcbot command: {:?}", &command); - let process = command.process(&author, &issue, comment, &subteam_members); + let process = command.process(&author, &issue, comment, &issue_teams, &subteam_members); ok_or!(process, why => { error!("Unable to process command for comment id {}: {:?}", comment.id, why); @@ -688,6 +689,19 @@ where /// Return a list of all known team members. fn all_team_members() -> DashResult> { specific_subteam_members(|_| true) } +/// Get all of the teams that will be involved in the FCP. +fn involved_teams(issue: &Issue) -> DashResult> { + let setup = SETUP.read().unwrap(); + let teams = setup.teams(); + + let involved = teams + .filter(|&(label, _)| issue.labels.contains(&label.0)) + .map(|(label, _)| label.0.clone()) + .collect::>(); + + Ok(involved) +} + /// Check if an issue comment is written by a member of one of the subteams /// labelled on the issue. fn subteam_members(issue: &Issue) -> DashResult> { @@ -758,12 +772,13 @@ impl<'a> RfcBotCommand<'a> { author: &GitHubUser, issue: &Issue, comment: &IssueComment, + issue_teams: &[String], team_members: &[GitHubUser], ) -> DashResult<()> { use self::RfcBotCommand::*; match self { StartPoll { teams, question } => process_poll(author, issue, comment, question, teams), - FcpPropose(disp) => process_fcp_propose(author, issue, comment, team_members, disp), + FcpPropose(disp) => process_fcp_propose(author, issue, comment, issue_teams, team_members, disp), FcpCancel => process_fcp_cancel(author, issue), Reviewed => process_reviewed(author, issue), NewConcern(concern_name) => process_new_concern(author, issue, comment, concern_name), @@ -873,6 +888,7 @@ fn process_fcp_propose( author: &GitHubUser, issue: &Issue, comment: &IssueComment, + issue_teams: &[String], team_members: &[GitHubUser], disp: FcpDisposition, ) -> DashResult<()> { @@ -896,6 +912,7 @@ fn process_fcp_propose( disposition: disp.repr(), fcp_start: None, fcp_closed: false, + teams: Some(issue_teams), }; let proposal = diesel::insert_into(fcp_proposal) .values(&proposal)