diff --git a/src/handlers/pull_requests_assignment_update.rs b/src/handlers/pull_requests_assignment_update.rs index fe544afe..95edde32 100644 --- a/src/handlers/pull_requests_assignment_update.rs +++ b/src/handlers/pull_requests_assignment_update.rs @@ -84,3 +84,22 @@ WHERE r.user_id = $1;"; .unwrap(); Ok(row.into()) } + +pub async fn set_review_prefs( + db: &DbClient, + user_id: u64, + max: u32, +) -> anyhow::Result { + let q = " +UPDATE review_prefs r +SET max_assigned_prs = $2 +FROM users u +WHERE r.user_id=$1 AND u.user_id=r.user_id +RETURNING u.username, r.*"; + let row = db + .query_one(q, &[&(max as i32), &(user_id as i64)]) + .await + .context("Error retrieving review preferences") + .unwrap(); + Ok(row.into()) +} diff --git a/src/zulip.rs b/src/zulip.rs index 5c86aeea..4a2fc6e7 100644 --- a/src/zulip.rs +++ b/src/zulip.rs @@ -2,7 +2,7 @@ use crate::db::notifications::add_metadata; use crate::db::notifications::{self, delete_ping, move_indices, record_ping, Identifier}; use crate::github::{get_id_for_username, GithubClient}; use crate::handlers::docs_update::docs_update; -use crate::handlers::pull_requests_assignment_update::get_review_prefs; +use crate::handlers::pull_requests_assignment_update::{get_review_prefs, set_review_prefs}; use crate::handlers::Context; use anyhow::{format_err, Context as _}; use std::env; @@ -157,7 +157,7 @@ fn handle_command<'a>( Some("meta") => add_meta_notification(&ctx, gh_id, words).await .map_err(|e| format_err!("Failed to parse `meta` command. Synopsis: meta : Add to your notification identified by (>0)\n\nError: {e:?}")), Some("work") => query_pr_assignments(&ctx, gh_id, words).await - .map_err(|e| format_err!("Failed to parse `work` command. Synopsis: work : shows your current PRs assignment\n\nError: {e:?}")), + .map_err(|e| format_err!("Failed to parse `work` command. Synopsis:\nwork : shows your current PRs assignment\nwork set : set your max number of assigned PRs to review\n\nError: {e:?}")), _ => { while let Some(word) = next { if word == "@**triagebot**" { @@ -206,6 +206,22 @@ async fn query_pr_assignments( gh_id: u64, mut words: impl Iterator, ) -> anyhow::Result> { + let testers = [ + 1825894, // michaelwoerister + 3161395, // jhpratt + 5910697, // nadriel + 6098822, // apiraino + 20113453, // matthewjasper + 31162821, // jackh726 + 39484203, // jieyouxu + 43851243, // fee1-dead + 74931857, // albertlarsan68 + ]; + + if !testers.contains(&gh_id) { + anyhow::bail!("Sorry, this feature is currently restricted to testers.") + } + let subcommand = match words.next() { Some(subcommand) => subcommand, None => anyhow::bail!("no subcommand provided"), @@ -221,6 +237,22 @@ async fn query_pr_assignments( } rec? } + "set" => { + let max = match words.next() { + Some(max_value) => { + if words.next().is_some() { + anyhow::bail!("Too many parameters."); + } + max_value + .parse::() + .context("Wrong parameter format. Must be a positive integer.")? + } + None => anyhow::bail!("Missing parameter."), + }; + set_review_prefs(&db_client, gh_id, max) + .await + .context("Error occurred while setting review preferences.")? + } _ => anyhow::bail!("Invalid subcommand."), };