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
55 changes: 31 additions & 24 deletions src/zulip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::utils::pluralize;
use crate::zulip::api::{MessageApiResponse, Recipient};
use crate::zulip::client::ZulipClient;
use crate::zulip::commands::{
parse_cli, ChatCommand, LookupCmd, StreamCommand, WorkqueueCmd, WorkqueueLimit,
parse_cli, ChatCommand, LookupCmd, PingGoalsArgs, StreamCommand, WorkqueueCmd, WorkqueueLimit,
};
use anyhow::{format_err, Context as _};
use rust_team_data::v1::TeamKind;
Expand Down Expand Up @@ -225,6 +225,8 @@ async fn handle_command<'a>(
ChatCommand::Whoami => whoami_cmd(&ctx, gh_id).await,
ChatCommand::Lookup(cmd) => lookup_cmd(&ctx, cmd).await,
ChatCommand::Work(cmd) => workqueue_commands(ctx, gh_id, cmd).await,
ChatCommand::PingGoals(args) => ping_goals_cmd(ctx, gh_id, &args).await,
ChatCommand::DocsUpdate => trigger_docs_update(message_data, &ctx.zulip),
};

let output = output?;
Expand Down Expand Up @@ -281,32 +283,35 @@ async fn handle_command<'a>(
StreamCommand::Read => post_waiter(&ctx, message_data, WaitingMessage::start_reading())
.await
.map_err(|e| format_err!("Failed to await at this time: {e:?}")),
StreamCommand::PingGoals {
threshold,
next_update,
} => {
if project_goals::check_project_goal_acl(&ctx.github, gh_id).await? {
ping_project_goals_owners(
&ctx.github,
&ctx.zulip,
false,
threshold as i64,
&format!("on {next_update}"),
)
.await
.map_err(|e| format_err!("Failed to await at this time: {e:?}"))?;
Ok(None)
} else {
Err(format_err!(
"That command is only permitted for those running the project-goal program.",
))
}
}
StreamCommand::PingGoals(args) => ping_goals_cmd(ctx, gh_id, &args).await,
StreamCommand::DocsUpdate => trigger_docs_update(message_data, &ctx.zulip),
}
}
}

async fn ping_goals_cmd(
ctx: &Context,
gh_id: u64,
args: &PingGoalsArgs,
) -> anyhow::Result<Option<String>> {
if project_goals::check_project_goal_acl(&ctx.github, gh_id).await? {
ping_project_goals_owners(
&ctx.github,
&ctx.zulip,
false,
args.threshold as i64,
&format!("on {}", args.next_update),
)
.await
.map_err(|e| format_err!("Failed to await at this time: {e:?}"))?;
Ok(None)
} else {
Err(format_err!(
"That command is only permitted for those running the project-goal program.",
))
}
}

/// Returns true if we should notify user who was impersonated by someone who executed this command.
/// More or less, the following holds: `sensitive` == `not read-only`.
fn is_sensitive_command(cmd: &ChatCommand) -> bool {
Expand All @@ -315,8 +320,10 @@ fn is_sensitive_command(cmd: &ChatCommand) -> bool {
| ChatCommand::Add { .. }
| ChatCommand::Move { .. }
| ChatCommand::Meta { .. } => true,
ChatCommand::Whoami => false,
ChatCommand::Lookup(_) => false,
ChatCommand::Whoami
| ChatCommand::DocsUpdate
| ChatCommand::PingGoals(_)
| ChatCommand::Lookup(_) => false,
ChatCommand::Work(cmd) => match cmd {
WorkqueueCmd::Show => false,
WorkqueueCmd::SetPrLimit { .. } => true,
Expand Down
19 changes: 13 additions & 6 deletions src/zulip/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub enum ChatCommand {
/// Inspect or modify your reviewer workqueue.
#[clap(subcommand)]
Work(WorkqueueCmd),
/// Ping project goal owners.
PingGoals(PingGoalsArgs),
/// Update docs
DocsUpdate,
}

#[derive(clap::Parser, Debug, PartialEq)]
Expand Down Expand Up @@ -151,16 +155,19 @@ pub enum StreamCommand {
/// Read a document.
Read,
/// Ping project goal owners.
PingGoals {
/// Number of days before an update is considered stale
threshold: u64,
/// Date of next update
next_update: String,
},
PingGoals(PingGoalsArgs),
/// Update docs
DocsUpdate,
}

#[derive(clap::Parser, Debug, PartialEq)]
pub struct PingGoalsArgs {
/// Number of days before an update is considered stale
pub threshold: u64,
/// Date of next update
pub next_update: String,
}

/// Helper function to parse CLI arguments without any colored help or error output.
pub fn parse_cli<'a, T: Parser, I: Iterator<Item = &'a str>>(input: I) -> anyhow::Result<T> {
// Add a fake first argument, which is expected by clap
Expand Down
Loading