Skip to content

Commit 0c7de61

Browse files
committed
Add reminder to use ready shortcut when using author shortcut
1 parent 5cc4c25 commit 0c7de61

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/handlers/shortcut.rs

+32
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44
55
use crate::{
66
config::ShortcutConfig,
7+
db::issue_data::IssueData,
78
github::{Event, Label},
89
handlers::Context,
910
interactions::ErrorComment,
1011
};
1112
use parser::command::shortcut::ShortcutCommand;
1213

14+
/// Key for the state in the database
15+
const AUTHOR_REMINDER_KEY: &str = "author-reminder";
16+
17+
/// State stored in the database for a PR.
18+
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
19+
struct AuthorReminderState {
20+
/// ID of the reminder comment.
21+
reminder_comment: Option<String>,
22+
}
23+
1324
pub(super) async fn handle_command(
1425
ctx: &Context,
1526
_config: &ShortcutConfig,
@@ -53,5 +64,26 @@ pub(super) async fn handle_command(
5364
.await?;
5465
}
5566

67+
// We add a small reminder for the author to the `@bot ready` when ready
68+
if matches!(input, ShortcutCommand::Author) {
69+
// Get the state of the author reminder for this PR
70+
let mut db = ctx.db.get().await;
71+
let mut state: IssueData<'_, AuthorReminderState> =
72+
IssueData::load(&mut db, &issue, AUTHOR_REMINDER_KEY).await?;
73+
74+
if state.data.reminder_comment.is_none() {
75+
let comment_body = format!(
76+
"Reminder, use `@{bot} ready` to indicate that the PR is ready for review.",
77+
bot = &ctx.username,
78+
);
79+
let comment = issue
80+
.post_comment(&ctx.github, comment_body.as_str())
81+
.await?;
82+
83+
state.data.reminder_comment = Some(comment.node_id);
84+
state.save().await?;
85+
}
86+
}
87+
5688
Ok(())
5789
}

0 commit comments

Comments
 (0)