Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track teams in rfcbot #320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Empty file removed migrations/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE fcp_proposal DROP COLUMN teams;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE fcp_proposal ADD COLUMN teams text[];
4 changes: 4 additions & 0 deletions src/domain/rfcbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct NewFcpProposal<'a> {
pub fk_bot_tracking_comment: i32,
pub fcp_start: Option<NaiveDateTime>,
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)]
Expand Down Expand Up @@ -76,6 +78,8 @@ pub struct FcpProposal {
pub fk_bot_tracking_comment: i32,
pub fcp_start: Option<NaiveDateTime>,
pub fcp_closed: bool,
// `None` here is for proposals started before team support
pub teams: Option<Vec<String>>,
}

#[derive(Clone, Debug, Eq, Insertable, Ord, PartialEq, PartialOrd, Serialize)]
Expand Down
6 changes: 6 additions & 0 deletions src/domain/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<Text>>`.
///
/// (Automatically generated by Diesel.)
teams -> Nullable<Array<Text>>,
}
}

Expand Down
21 changes: 19 additions & 2 deletions src/github/nag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn update_nags(comment: &IssueComment) -> DashResult<()> {
.find(comment.fk_user)
.first::<GitHubUser>(conn)?;

let issue_teams = involved_teams(&issue)?;
let subteam_members = subteam_members(&issue)?;
let all_team_members = all_team_members()?;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -688,6 +689,19 @@ where
/// Return a list of all known team members.
fn all_team_members() -> DashResult<Vec<GitHubUser>> { specific_subteam_members(|_| true) }

/// Get all of the teams that will be involved in the FCP.
fn involved_teams(issue: &Issue) -> DashResult<Vec<String>> {
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::<Vec<_>>();

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<Vec<GitHubUser>> {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -873,6 +888,7 @@ fn process_fcp_propose(
author: &GitHubUser,
issue: &Issue,
comment: &IssueComment,
issue_teams: &[String],
team_members: &[GitHubUser],
disp: FcpDisposition,
) -> DashResult<()> {
Expand All @@ -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)
Expand Down