Skip to content

Commit 02b0aed

Browse files
committed
shortcut: ping users on ready/author
1 parent 89daaa7 commit 02b0aed

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/handlers/shortcut.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
config::ShortcutConfig,
77
github::{Event, Label},
88
handlers::Context,
9-
interactions::ErrorComment,
9+
interactions::{ErrorComment, PingComment},
1010
};
1111
use parser::command::shortcut::ShortcutCommand;
1212

@@ -37,6 +37,14 @@ pub(super) async fn handle_command(
3737
return Ok(());
3838
}
3939
issue.set_labels(&ctx.github, issue_labels).await?;
40+
41+
let to_ping: Vec<_> = issue
42+
.assignees
43+
.iter()
44+
.map(|user| user.login.as_str())
45+
.collect();
46+
let cmnt = PingComment::new(&issue, &to_ping);
47+
cmnt.post(&ctx.github).await?;
4048
}
4149
ShortcutCommand::Author => {
4250
if assign_and_remove_label(&mut issue_labels, waiting_on_author, waiting_on_review)
@@ -45,6 +53,10 @@ pub(super) async fn handle_command(
4553
return Ok(());
4654
}
4755
issue.set_labels(&ctx.github, issue_labels).await?;
56+
57+
let to_ping = vec![issue.user.login.as_str()];
58+
let cmnt = PingComment::new(&issue, &to_ping);
59+
cmnt.post(&ctx.github).await?;
4860
}
4961
}
5062

src/interactions.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ impl<'a> ErrorComment<'a> {
2929
}
3030
}
3131

32+
pub struct PingComment<'a> {
33+
issue: &'a Issue,
34+
users: &'a [&'a str],
35+
}
36+
37+
impl<'a> PingComment<'a> {
38+
pub fn new(issue: &'a Issue, users: &'a [&str]) -> PingComment<'a> {
39+
PingComment { issue, users }
40+
}
41+
42+
pub async fn post(&self, client: &GithubClient) -> anyhow::Result<()> {
43+
let mut body = String::new();
44+
for user in self.users {
45+
write!(body, "@{} ", user)?;
46+
}
47+
self.issue.post_comment(client, &body).await
48+
}
49+
}
50+
3251
pub struct EditIssueBody<'a> {
3352
issue: &'a Issue,
3453
id: &'static str,

0 commit comments

Comments
 (0)