Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reminder to use ready shortcut when using author shortcut #1899

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions src/handlers/shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

use crate::{
config::ShortcutConfig,
db::issue_data::IssueData,
github::{Event, Label},
handlers::Context,
interactions::ErrorComment,
};
use parser::command::shortcut::ShortcutCommand;

/// Key for the state in the database
const AUTHOR_REMINDER_KEY: &str = "author-reminder";

/// State stored in the database for a PR.
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
struct AuthorReminderState {
/// ID of the reminder comment.
reminder_comment: Option<String>,
}

pub(super) async fn handle_command(
ctx: &Context,
_config: &ShortcutConfig,
Expand Down Expand Up @@ -53,5 +64,26 @@ pub(super) async fn handle_command(
.await?;
}

// We add a small reminder for the author to the `@bot ready` when ready
if matches!(input, ShortcutCommand::Author) {
// Get the state of the author reminder for this PR
let mut db = ctx.db.get().await;
let mut state: IssueData<'_, AuthorReminderState> =
IssueData::load(&mut db, &issue, AUTHOR_REMINDER_KEY).await?;

if state.data.reminder_comment.is_none() {
let comment_body = format!(
"Reminder, use `@{bot} ready` to indicate that the PR is ready for review.",
bot = &ctx.username,
);
let comment = issue
.post_comment(&ctx.github, comment_body.as_str())
.await?;

state.data.reminder_comment = Some(comment.node_id);
state.save().await?;
}
}

Ok(())
}