diff --git a/parser/src/command.rs b/parser/src/command.rs index 27334596b..ecdd2ec86 100644 --- a/parser/src/command.rs +++ b/parser/src/command.rs @@ -5,7 +5,6 @@ use regex::Regex; pub mod assign; pub mod close; -pub mod glacier; pub mod nominate; pub mod note; pub mod ping; @@ -23,7 +22,6 @@ pub enum Command<'a> { Nominate(Result>), Prioritize(Result>), Second(Result>), - Glacier(Result>), Shortcut(Result>), Close(Result>), Note(Result>), @@ -119,11 +117,6 @@ impl<'a> Input<'a> { Command::Second, &original_tokenizer, )); - success.extend(parse_single_command( - glacier::GlacierCommand::parse, - Command::Glacier, - &original_tokenizer, - )); success.extend(parse_single_command( shortcut::ShortcutCommand::parse, Command::Shortcut, @@ -210,7 +203,6 @@ impl<'a> Command<'a> { Command::Nominate(r) => r.is_ok(), Command::Prioritize(r) => r.is_ok(), Command::Second(r) => r.is_ok(), - Command::Glacier(r) => r.is_ok(), Command::Shortcut(r) => r.is_ok(), Command::Close(r) => r.is_ok(), Command::Note(r) => r.is_ok(), diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs deleted file mode 100644 index 5d90e0793..000000000 --- a/parser/src/command/glacier.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! The glacier command parser. -//! -//! This adds the option to track ICEs. The must be in quotes. -//! -//! The grammar is as follows: -//! -//! ```text -//! Command: `@bot glacier ` -//! -//! : any URL that resolves to plain-text Rust code -//! ``` - -use crate::error::Error; -use crate::token::{Token, Tokenizer}; -use std::fmt; - -#[derive(PartialEq, Eq, Debug)] -pub struct GlacierCommand { - pub source: String, -} - -#[derive(PartialEq, Eq, Debug)] -pub enum ParseError { - NoLink, - InvalidLink, -} - -impl std::error::Error for ParseError {} - -impl fmt::Display for ParseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Self::NoLink => write!(f, "no link provided - did you forget the quotes around it?"), - Self::InvalidLink => write!(f, "invalid link - must be from a playground gist"), - } - } -} - -impl GlacierCommand { - pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result, Error<'a>> { - let mut toks = input.clone(); - if let Some(Token::Word("glacier")) = toks.peek_token()? { - toks.next_token()?; - match toks.next_token()? { - Some(Token::Quote(s)) => { - let source = s.to_owned(); - if source.starts_with("https://gist.github.com/") { - return Ok(Some(GlacierCommand { source })); - } else { - return Err(toks.error(ParseError::InvalidLink)); - } - } - Some(Token::Word(_)) => { - return Err(toks.error(ParseError::InvalidLink)); - } - _ => { - return Err(toks.error(ParseError::NoLink)); - } - } - } else { - Ok(None) - } - } -} - -#[cfg(test)] -mod test { - use super::*; - - fn parse<'a>(input: &'a str) -> Result, Error<'a>> { - let mut toks = Tokenizer::new(input); - Ok(GlacierCommand::parse(&mut toks)?) - } - - #[test] - fn glacier_empty() { - use std::error::Error; - assert_eq!( - parse("glacier") - .unwrap_err() - .source() - .unwrap() - .downcast_ref(), - Some(&ParseError::NoLink), - ); - } - - #[test] - fn glacier_invalid() { - use std::error::Error; - assert_eq!( - parse("glacier hello") - .unwrap_err() - .source() - .unwrap() - .downcast_ref(), - Some(&ParseError::InvalidLink), - ); - } - - #[test] - fn glacier_valid() { - assert_eq!( - parse( - r#"glacier "https://gist.github.com/rust-play/89d6c8a2398dd2dd5fcb7ef3e8109c7b""# - ), - Ok(Some(GlacierCommand { - source: "https://gist.github.com/rust-play/89d6c8a2398dd2dd5fcb7ef3e8109c7b".into() - })) - ); - } -} diff --git a/src/config.rs b/src/config.rs index 9f5e6eb0b..de2462b4a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,6 @@ pub(crate) struct Config { pub(crate) nominate: Option, pub(crate) prioritize: Option, pub(crate) major_change: Option, - pub(crate) glacier: Option, pub(crate) close: Option, pub(crate) autolabel: Option, pub(crate) notify_zulip: Option, @@ -384,10 +383,6 @@ impl MajorChangeConfig { } } -#[derive(PartialEq, Eq, Debug, serde::Deserialize)] -#[serde(deny_unknown_fields)] -pub(crate) struct GlacierConfig {} - #[derive(PartialEq, Eq, Debug, serde::Deserialize)] #[serde(deny_unknown_fields)] pub(crate) struct CloseConfig {} @@ -673,7 +668,6 @@ mod tests { shortcut: Some(ShortcutConfig { _empty: () }), prioritize: None, major_change: None, - glacier: None, close: None, autolabel: None, notify_zulip: None, @@ -752,7 +746,6 @@ mod tests { shortcut: None, prioritize: None, major_change: None, - glacier: None, close: None, autolabel: None, notify_zulip: None, diff --git a/src/handlers.rs b/src/handlers.rs index 6c93131a2..90e5a6a04 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -31,7 +31,6 @@ mod check_commits; mod close; pub mod docs_update; mod github_releases; -mod glacier; mod issue_links; mod major_change; mod mentions; @@ -358,7 +357,6 @@ macro_rules! command_handlers { // preceded by the module containing the corresponding `handle_command` function command_handlers! { assign: Assign, - glacier: Glacier, nominate: Nominate, ping: Ping, prioritize: Prioritize, diff --git a/src/handlers/glacier.rs b/src/handlers/glacier.rs deleted file mode 100644 index 941c9edf4..000000000 --- a/src/handlers/glacier.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Allows team members to directly create a glacier PR with the code provided. - -use crate::{config::GlacierConfig, github::Event, handlers::Context}; -use models::repos::Object; -use octocrab::models; -use octocrab::params::repos::Reference; -use parser::command::glacier::GlacierCommand; -use tracing as log; - -pub(super) async fn handle_command( - ctx: &Context, - _config: &GlacierConfig, - event: &Event, - cmd: GlacierCommand, -) -> anyhow::Result<()> { - let is_team_member = event - .user() - .is_team_member(&ctx.github) - .await - .unwrap_or(false); - - if !is_team_member { - return Ok(()); - }; - - let body = ctx - .github - .raw_gist_from_url(&cmd.source, "playground.rs") - .await?; - - let number = event.issue().unwrap().number; - let user = event.user(); - - let octocrab = &ctx.octocrab; - - let fork = octocrab.repos(&ctx.username, "glacier"); - let base = octocrab.repos("rust-lang", "glacier"); - - let master = base - .get_ref(&Reference::Branch("master".to_string())) - .await? - .object; - let master = if let Object::Commit { sha, .. } = master { - sha - } else { - log::error!("invalid commit sha - master {:?}", master); - unreachable!() - }; - - fork.create_ref( - &Reference::Branch(format!("triagebot-ice-{}", number)), - master, - ) - .await?; - fork.create_file( - format!("ices/{}.rs", number), - format!("Add ICE reproduction for issue rust-lang/rust#{}.", number), - body, - ) - .branch(format!("triagebot-ice-{}", number)) - .send() - .await?; - - octocrab - .pulls("rust-lang", "glacier") - .create( - format!("ICE - rust-lang/rust#{}", number), - format!("{}:triagebot-ice-{}", ctx.username, number), - "master", - ) - .body(format!( - "Automatically created by @{} in issue rust-lang/rust#{}", - user.login, number - )) - .send() - .await?; - Ok(()) -}