|
4 | 4 |
|
5 | 5 | use crate::{
|
6 | 6 | config::ShortcutConfig,
|
| 7 | + db::issue_data::IssueData, |
7 | 8 | github::{Event, Label},
|
8 | 9 | handlers::Context,
|
9 | 10 | interactions::ErrorComment,
|
10 | 11 | };
|
11 | 12 | use parser::command::shortcut::ShortcutCommand;
|
12 | 13 |
|
| 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 | + |
13 | 24 | pub(super) async fn handle_command(
|
14 | 25 | ctx: &Context,
|
15 | 26 | _config: &ShortcutConfig,
|
@@ -53,5 +64,26 @@ pub(super) async fn handle_command(
|
53 | 64 | .await?;
|
54 | 65 | }
|
55 | 66 |
|
| 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 | + |
56 | 88 | Ok(())
|
57 | 89 | }
|
0 commit comments