Skip to content
Merged
Show file tree
Hide file tree
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 parser/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use regex::Regex;

pub mod assign;
pub mod close;
pub mod concern;
pub mod nominate;
pub mod note;
pub mod ping;
Expand All @@ -25,6 +26,7 @@ pub enum Command<'a> {
Shortcut(Result<shortcut::ShortcutCommand, Error<'a>>),
Close(Result<close::CloseCommand, Error<'a>>),
Note(Result<note::NoteCommand, Error<'a>>),
Concern(Result<concern::ConcernCommand, Error<'a>>),
Transfer(Result<transfer::TransferCommand, Error<'a>>),
}

Expand Down Expand Up @@ -97,6 +99,11 @@ impl<'a> Input<'a> {
Command::Note,
&original_tokenizer,
));
success.extend(parse_single_command(
concern::ConcernCommand::parse,
Command::Concern,
&original_tokenizer,
));
success.extend(parse_single_command(
ping::PingCommand::parse,
Command::Ping,
Expand Down Expand Up @@ -206,6 +213,7 @@ impl<'a> Command<'a> {
Command::Shortcut(r) => r.is_ok(),
Command::Close(r) => r.is_ok(),
Command::Note(r) => r.is_ok(),
Command::Concern(r) => r.is_ok(),
Command::Transfer(r) => r.is_ok(),
}
}
Expand Down Expand Up @@ -353,3 +361,27 @@ fn review_ignored() {
assert_eq!(input.next(), None);
}
}

#[test]
fn concern() {
let input = "@bot concern this is my concern";
let mut input = Input::new(input, vec!["bot"]);
assert_eq!(
input.next(),
Some(Command::Concern(Ok(concern::ConcernCommand::Concern {
title: "this is my concern".to_string()
})))
);
}

#[test]
fn resolve() {
let input = "@bot resolve this is my concern";
let mut input = Input::new(input, vec!["bot"]);
assert_eq!(
input.next(),
Some(Command::Concern(Ok(concern::ConcernCommand::Resolve {
title: "this is my concern".to_string()
})))
);
}
48 changes: 48 additions & 0 deletions parser/src/command/concern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::error::Error;
use crate::token::{Token, Tokenizer};
use std::fmt;

#[derive(PartialEq, Eq, Debug)]
pub enum ConcernCommand {
Concern { title: String },
Resolve { title: String },
}

#[derive(PartialEq, Eq, Debug)]
pub enum ParseError {
MissingTitle,
}

impl std::error::Error for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::MissingTitle => write!(f, "missing required title"),
}
}
}

impl ConcernCommand {
pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
let mut toks = input.clone();
if let Some(Token::Word(action @ ("concern" | "resolve"))) = toks.peek_token()? {
toks.next_token()?;

let title = toks.take_line()?.trim().to_string();

if title.is_empty() {
return Err(toks.error(ParseError::MissingTitle));
}

let command = if action == "resolve" {
ConcernCommand::Resolve { title }
} else {
ConcernCommand::Concern { title }
};

Ok(Some(command))
} else {
Ok(None)
}
}
}
16 changes: 16 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) struct Config {
pub(crate) review_requested: Option<ReviewRequestedConfig>,
pub(crate) shortcut: Option<ShortcutConfig>,
pub(crate) note: Option<NoteConfig>,
pub(crate) concern: Option<ConcernConfig>,
pub(crate) mentions: Option<MentionsConfig>,
pub(crate) no_merges: Option<NoMergesConfig>,
// We want this validation to run even without the entry in the config file
Expand Down Expand Up @@ -191,6 +192,14 @@ pub(crate) struct NoteConfig {
_empty: (),
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct ConcernConfig {
/// Set the labels on the PR when concerns are active.
#[serde(default)]
pub(crate) labels: Vec<String>,
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
pub(crate) struct MentionsConfig {
#[serde(flatten)]
Expand Down Expand Up @@ -594,6 +603,9 @@ mod tests {

[note]

[concern]
labels = ["has-concerns"]

[ping.compiler]
message = """\
So many people!\
Expand Down Expand Up @@ -691,6 +703,9 @@ mod tests {
behind_upstream: Some(BehindUpstreamConfig {
days_threshold: Some(14),
}),
concern: Some(ConcernConfig {
labels: vec!["has-concerns".to_string()],
}),
}
);
}
Expand Down Expand Up @@ -742,6 +757,7 @@ mod tests {
}),
note: None,
ping: None,
concern: None,
nominate: None,
shortcut: None,
prioritize: None,
Expand Down
1 change: 1 addition & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ pub struct Comment {
pub updated_at: chrono::DateTime<Utc>,
#[serde(default, rename = "state")]
pub pr_review_state: Option<PullRequestReviewState>,
pub author_association: AuthorAssociation,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, Eq, PartialEq)]
Expand Down
2 changes: 2 additions & 0 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod autolabel;
mod bot_pull_requests;
mod check_commits;
mod close;
mod concern;
pub mod docs_update;
mod github_releases;
mod issue_links;
Expand Down Expand Up @@ -365,6 +366,7 @@ command_handlers! {
shortcut: Shortcut,
close: Close,
note: Note,
concern: Concern,
transfer: Transfer,
}

Expand Down
Loading