Skip to content

Commit 768b4a8

Browse files
committed
Rename ShortcutCommand to ReviewCommand
The ShortcutCommand was born to handle one case (reviews) but I'd like to expand its scope to handle more convenience custom shortcuts for commands that will modify labels. However just adding more code would make things a bit confusing, so I'd first start clarifying the scope of the existing code and in subsequent patches add more shortcut commands. At a high level, I can imagine something like this: - shortcut::ReviewCommand to handle commands like `author`, `review`, `ready`, etc. - shortcut::RegressionCommand to handle future commands for quick switching label regressions (todo) - shortcut:NewCommand (and so on) Functionally this patch changes nothing, it's just renaming things.
1 parent 08781c3 commit 768b4a8

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

parser/src/command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum Command<'a> {
2323
Nominate(Result<nominate::NominateCommand, Error<'a>>),
2424
Prioritize(Result<prioritize::PrioritizeCommand, Error<'a>>),
2525
Second(Result<second::SecondCommand, Error<'a>>),
26-
Shortcut(Result<shortcut::ShortcutCommand, Error<'a>>),
26+
Review(Result<shortcut::ReviewCommand, Error<'a>>),
2727
Close(Result<close::CloseCommand, Error<'a>>),
2828
Note(Result<note::NoteCommand, Error<'a>>),
2929
Concern(Result<concern::ConcernCommand, Error<'a>>),
@@ -125,8 +125,8 @@ impl<'a> Input<'a> {
125125
&original_tokenizer,
126126
));
127127
success.extend(parse_single_command(
128-
shortcut::ShortcutCommand::parse,
129-
Command::Shortcut,
128+
shortcut::ReviewCommand::parse,
129+
Command::Review,
130130
&original_tokenizer,
131131
));
132132
success.extend(parse_single_command(
@@ -210,7 +210,7 @@ impl<'a> Command<'a> {
210210
Command::Nominate(r) => r.is_ok(),
211211
Command::Prioritize(r) => r.is_ok(),
212212
Command::Second(r) => r.is_ok(),
213-
Command::Shortcut(r) => r.is_ok(),
213+
Command::Review(r) => r.is_ok(),
214214
Command::Close(r) => r.is_ok(),
215215
Command::Note(r) => r.is_ok(),
216216
Command::Concern(r) => r.is_ok(),

parser/src/command/shortcut.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! The shortcut command parser.
1+
//! Parser for commands handling a PR review status
22
//!
33
//! This can parse predefined shortcut input, single word commands.
44
//!
@@ -14,7 +14,7 @@ use std::collections::HashMap;
1414
use std::fmt;
1515

1616
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
17-
pub enum ShortcutCommand {
17+
pub enum ReviewCommand {
1818
Ready,
1919
Author,
2020
Blocked,
@@ -31,14 +31,14 @@ impl fmt::Display for ParseError {
3131
}
3232
}
3333

34-
impl ShortcutCommand {
34+
impl ReviewCommand {
3535
pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
3636
let mut shortcuts = HashMap::new();
37-
shortcuts.insert("ready", ShortcutCommand::Ready);
38-
shortcuts.insert("review", ShortcutCommand::Ready);
39-
shortcuts.insert("reviewer", ShortcutCommand::Ready);
40-
shortcuts.insert("author", ShortcutCommand::Author);
41-
shortcuts.insert("blocked", ShortcutCommand::Blocked);
37+
shortcuts.insert("ready", ReviewCommand::Ready);
38+
shortcuts.insert("review", ReviewCommand::Ready);
39+
shortcuts.insert("reviewer", ReviewCommand::Ready);
40+
shortcuts.insert("author", ReviewCommand::Author);
41+
shortcuts.insert("blocked", ReviewCommand::Blocked);
4242

4343
let mut toks = input.clone();
4444
if let Some(Token::Word(word)) = toks.peek_token()? {
@@ -55,32 +55,32 @@ impl ShortcutCommand {
5555
}
5656

5757
#[cfg(test)]
58-
fn parse(input: &str) -> Result<Option<ShortcutCommand>, Error<'_>> {
58+
fn parse(input: &str) -> Result<Option<ReviewCommand>, Error<'_>> {
5959
let mut toks = Tokenizer::new(input);
60-
Ok(ShortcutCommand::parse(&mut toks)?)
60+
Ok(ReviewCommand::parse(&mut toks)?)
6161
}
6262

6363
#[test]
6464
fn test_1() {
65-
assert_eq!(parse("ready."), Ok(Some(ShortcutCommand::Ready)));
65+
assert_eq!(parse("ready."), Ok(Some(ReviewCommand::Ready)));
6666
}
6767

6868
#[test]
6969
fn test_2() {
70-
assert_eq!(parse("ready"), Ok(Some(ShortcutCommand::Ready)));
70+
assert_eq!(parse("ready"), Ok(Some(ReviewCommand::Ready)));
7171
}
7272

7373
#[test]
7474
fn test_3() {
75-
assert_eq!(parse("author"), Ok(Some(ShortcutCommand::Author)),);
75+
assert_eq!(parse("author"), Ok(Some(ReviewCommand::Author)),);
7676
}
7777

7878
#[test]
7979
fn test_4() {
80-
assert_eq!(parse("ready word"), Ok(Some(ShortcutCommand::Ready)));
80+
assert_eq!(parse("ready word"), Ok(Some(ReviewCommand::Ready)));
8181
}
8282

8383
#[test]
8484
fn test_5() {
85-
assert_eq!(parse("blocked"), Ok(Some(ShortcutCommand::Blocked)));
85+
assert_eq!(parse("blocked"), Ok(Some(ReviewCommand::Blocked)));
8686
}

src/handlers/shortcut.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
interactions::ErrorComment,
1111
};
1212
use octocrab::models::AuthorAssociation;
13-
use parser::command::shortcut::ShortcutCommand;
13+
use parser::command::shortcut::ReviewCommand;
1414

1515
/// Key for the state in the database
1616
const AUTHOR_REMINDER_KEY: &str = "author-reminder";
@@ -26,7 +26,7 @@ pub(super) async fn handle_command(
2626
ctx: &Context,
2727
_config: &ShortcutConfig,
2828
event: &Event,
29-
input: ShortcutCommand,
29+
input: ReviewCommand,
3030
) -> anyhow::Result<()> {
3131
let issue = event.issue().unwrap();
3232
// NOTE: if shortcuts available to issues are created, they need to be allowed here
@@ -44,9 +44,9 @@ pub(super) async fn handle_command(
4444
let status_labels = [waiting_on_review, waiting_on_author, blocked, "S-inactive"];
4545

4646
let add = match input {
47-
ShortcutCommand::Ready => waiting_on_review,
48-
ShortcutCommand::Author => waiting_on_author,
49-
ShortcutCommand::Blocked => blocked,
47+
ReviewCommand::Ready => waiting_on_review,
48+
ReviewCommand::Author => waiting_on_author,
49+
ReviewCommand::Blocked => blocked,
5050
};
5151

5252
if !issue_labels.iter().any(|l| l.name == add) {
@@ -70,7 +70,7 @@ pub(super) async fn handle_command(
7070
// Except if the author is a member (or the owner) of the repository, as
7171
// the author should already know about the `ready` command and already
7272
// have the required permissions to update the labels manually anyway.
73-
if matches!(input, ShortcutCommand::Author)
73+
if matches!(input, ReviewCommand::Author)
7474
&& !matches!(
7575
issue.author_association,
7676
AuthorAssociation::Member | AuthorAssociation::Owner

0 commit comments

Comments
 (0)