From 15f46b0e0c1c13821c8a01d61dc6abfdc1520103 Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Tue, 12 May 2020 00:07:27 +0200 Subject: [PATCH 01/10] Add `glacier` command to track ICEs --- Cargo.lock | 1 + parser/Cargo.toml | 1 + parser/src/command.rs | 8 +++ parser/src/command/glacier.rs | 116 ++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 parser/src/command/glacier.rs diff --git a/Cargo.lock b/Cargo.lock index b7e35bbd5..89baf2b72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -784,6 +784,7 @@ version = "0.1.0" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/parser/Cargo.toml b/parser/Cargo.toml index cb2ed46aa..2ab8fbcc4 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] pulldown-cmark = "0.6.0" log = "0.4" +regex = "1" diff --git a/parser/src/command.rs b/parser/src/command.rs index 1488522d4..3a9bc0290 100644 --- a/parser/src/command.rs +++ b/parser/src/command.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::token::{Token, Tokenizer}; pub mod assign; +pub mod glacier; pub mod nominate; pub mod ping; pub mod prioritize; @@ -21,6 +22,7 @@ pub enum Command<'a> { Nominate(Result>), Prioritize(Result>), Second(Result>), + Glacier(Result>), None, } @@ -109,6 +111,11 @@ impl<'a> Input<'a> { Command::Second, &original_tokenizer, )); + success.extend(parse_single_command( + glacier::GlacierCommand::parse, + Command::Glacier, + &original_tokenizer, + )); if success.len() > 1 { panic!( @@ -149,6 +156,7 @@ 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::None => true, } } diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs new file mode 100644 index 000000000..405a9c121 --- /dev/null +++ b/parser/src/command/glacier.rs @@ -0,0 +1,116 @@ +//! The glacier command parser. +//! +//! This adds the option to track ICEs. +//! +//! The grammar is as follows: +//! +//! ```text +//! Command: `@bot glacier add ?` +//! +//! : +//! - "https://play.rust-lang.org/.*" +//! ``` + +use std::fmt; +use crate::error::Error; +use crate::token::{Token, Tokenizer}; +use regex::Regex; + +#[derive(PartialEq, Eq, Debug)] +pub struct GlacierCommand { + 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"), + Self::InvalidLink => write!(f, "invalid link"), + } + } +} + +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(); + let playground_url = Regex::new("https://play.rust-lang.org/.*").unwrap(); + if playground_url.is_match(&source) { + 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://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a85913678bee64a3262db9a4a59463c2""#), + Ok(Some(GlacierCommand { + source: "https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a85913678bee64a3262db9a4a59463c2".into() + })) + ); + } + +} From f8b15268fc9af7a0fe64f7af42cd81db958a291e Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Tue, 12 May 2020 16:54:04 +0200 Subject: [PATCH 02/10] Fix docs --- parser/src/command/glacier.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs index 405a9c121..b091d6f4c 100644 --- a/parser/src/command/glacier.rs +++ b/parser/src/command/glacier.rs @@ -5,7 +5,7 @@ //! The grammar is as follows: //! //! ```text -//! Command: `@bot glacier add ?` +//! Command: `@bot glacier ` //! //! : //! - "https://play.rust-lang.org/.*" From 5f918222ec50a80872dfa1c9c875ed9eca9fdea3 Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Tue, 12 May 2020 16:55:20 +0200 Subject: [PATCH 03/10] Remove regex dependency --- Cargo.lock | 1 - parser/Cargo.toml | 1 - parser/src/command/glacier.rs | 4 +--- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89baf2b72..b7e35bbd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -784,7 +784,6 @@ version = "0.1.0" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 2ab8fbcc4..cb2ed46aa 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -7,4 +7,3 @@ edition = "2018" [dependencies] pulldown-cmark = "0.6.0" log = "0.4" -regex = "1" diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs index b091d6f4c..14a0aeefc 100644 --- a/parser/src/command/glacier.rs +++ b/parser/src/command/glacier.rs @@ -14,7 +14,6 @@ use std::fmt; use crate::error::Error; use crate::token::{Token, Tokenizer}; -use regex::Regex; #[derive(PartialEq, Eq, Debug)] pub struct GlacierCommand { @@ -46,8 +45,7 @@ impl GlacierCommand { match toks.next_token()? { Some(Token::Quote(s)) => { let source = s.to_owned(); - let playground_url = Regex::new("https://play.rust-lang.org/.*").unwrap(); - if playground_url.is_match(&source) { + if source.starts_with("https://play.rust-lang.org/") { return Ok(Some(GlacierCommand{source})); } else { return Err(toks.error(ParseError::InvalidLink)); From 539e138211258de6d549fd4caf9bb3bddaa72197 Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Thu, 21 May 2020 11:22:16 +0200 Subject: [PATCH 04/10] Handler skeleton --- Cargo.lock | 126 ++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + parser/src/command/glacier.rs | 9 +-- src/config.rs | 4 ++ src/handlers.rs | 1 + src/handlers/glacier.rs | 64 +++++++++++++++++ src/main.rs | 5 ++ 7 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 src/handlers/glacier.rs diff --git a/Cargo.lock b/Cargo.lock index b7e35bbd5..c2551e3a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,11 @@ name = "anyhow" version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "arc-swap" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "async-trait" version = "0.1.31" @@ -172,6 +177,11 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "dotenv" version = "0.14.1" @@ -506,6 +516,23 @@ dependencies = [ "tokio-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hyperx" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "idna" version = "0.2.0" @@ -555,6 +582,11 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "1.4.0" @@ -628,6 +660,17 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mio-named-pipes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio-uds" version = "0.6.8" @@ -649,6 +692,15 @@ dependencies = [ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "miow" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "native-tls" version = "0.2.4" @@ -716,6 +768,24 @@ name = "object" version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "octocrab" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "async-trait 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "hyperx 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", + "snafu 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "once_cell" version = "1.4.0" @@ -1141,6 +1211,15 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "signal-hook-registry" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "siphasher" version = "0.3.3" @@ -1156,6 +1235,37 @@ name = "smallvec" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "snafu" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.48 (registry+https://github.com/rust-lang/crates.io-index)", + "doc-comment 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "snafu-derive 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "snafu-derive" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "socket2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sourcefile" version = "0.1.4" @@ -1247,11 +1357,14 @@ dependencies = [ "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project-lite 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1348,6 +1461,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "octocrab 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)", "parser 0.1.0", @@ -1422,6 +1536,7 @@ dependencies = [ "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1616,6 +1731,7 @@ dependencies = [ "checksum addr2line 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543" "checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" "checksum anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" +"checksum arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62" "checksum async-trait 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "26c4f3195085c36ea8d24d32b2f828d23296a9370a28aa39d111f6f16bef9f3b" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" @@ -1637,6 +1753,7 @@ dependencies = [ "checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +"checksum doc-comment 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" "checksum dotenv 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4424bad868b0ffe6ae351ee463526ba625bbca817978293bbe6bb7dc1804a175" "checksum dtoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" "checksum encoding_rs 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" @@ -1675,12 +1792,14 @@ dependencies = [ "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" "checksum hyper 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96816e1d921eca64d208a85aab4f7798455a8e34229ee5a88c935bdee1b78b14" "checksum hyper-tls 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" +"checksum hyperx 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81d7ed6ec7d25c4de28b999a5693f14609a8b756137b1b4cb4927d119f59ef25" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" "checksum js-sys 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)" = "367647c532db6f1555d7151e619540ec5f713328235b8c062c6b4f63e84adfe3" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" "checksum lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" @@ -1691,8 +1810,10 @@ dependencies = [ "checksum mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" "checksum mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" "checksum mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +"checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" "checksum mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +"checksum miow 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22dfdd1d51b2639a5abd17ed07005c3af05fb7a2a3b1a1d0d7af1000a520c1c7" "checksum native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" "checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" @@ -1700,6 +1821,7 @@ dependencies = [ "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" "checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" "checksum object 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" +"checksum octocrab 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ba5c6067163fe198be510286a88f76dce9ed0a6ab1fc88f17e215609c9aff7d" "checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)" = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" @@ -1747,9 +1869,13 @@ dependencies = [ "checksum serde_path_to_error 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "359b895005d818163c78a24d272cc98567cce80c2461cf73f513da1d296c0b62" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" +"checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" "checksum siphasher 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +"checksum snafu 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c7f5aed652511f5c9123cf2afbe9c244c29db6effa2abb05c866e965c82405ce" +"checksum snafu-derive 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ebf8f7d5720104a9df0f7076a8682024e958bba0fe9848767bb44f251f3648e9" +"checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" diff --git a/Cargo.toml b/Cargo.toml index d3c19aa22..269cf7ba2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ tokio-postgres = { version = "0.5", features = ["with-chrono-0_4"] } postgres-native-tls = "0.3" native-tls = "0.2" serde_path_to_error = "0.1.2" +octocrab = "0.2" [dependencies.serde] version = "1" diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs index 14a0aeefc..ad4a83d30 100644 --- a/parser/src/command/glacier.rs +++ b/parser/src/command/glacier.rs @@ -11,13 +11,13 @@ //! - "https://play.rust-lang.org/.*" //! ``` -use std::fmt; use crate::error::Error; use crate::token::{Token, Tokenizer}; +use std::fmt; #[derive(PartialEq, Eq, Debug)] pub struct GlacierCommand { - source: String + source: String, } #[derive(PartialEq, Eq, Debug)] @@ -46,7 +46,7 @@ impl GlacierCommand { Some(Token::Quote(s)) => { let source = s.to_owned(); if source.starts_with("https://play.rust-lang.org/") { - return Ok(Some(GlacierCommand{source})); + return Ok(Some(GlacierCommand { source })); } else { return Err(toks.error(ParseError::InvalidLink)); } @@ -58,14 +58,12 @@ impl GlacierCommand { return Err(toks.error(ParseError::NoLink)); } } - } else { Ok(None) } } } - #[cfg(test)] mod test { use super::*; @@ -110,5 +108,4 @@ mod test { })) ); } - } diff --git a/src/config.rs b/src/config.rs index cf73536b5..aace8f24c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,7 @@ pub(crate) struct Config { pub(crate) nominate: Option, pub(crate) prioritize: Option, pub(crate) major_change: Option, + pub(crate) glacier: Option, } #[derive(PartialEq, Eq, Debug, serde::Deserialize)] @@ -92,6 +93,9 @@ pub(crate) struct MajorChangeConfig { pub(crate) zulip_stream: u64, } +#[derive(PartialEq, Eq, Debug, serde::Deserialize)] +pub(crate) struct GlacierConfig {} + pub(crate) async fn get(gh: &GithubClient, repo: &str) -> Result, ConfigurationError> { if let Some(config) = get_cached_config(repo) { log::trace!("returning config for {} from cache", repo); diff --git a/src/handlers.rs b/src/handlers.rs index cdd1c54c2..e5beafaa8 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -80,6 +80,7 @@ handlers! { prioritize = prioritize::PrioritizeHandler, major_change = major_change::MajorChangeHandler, //tracking_issue = tracking_issue::TrackingIssueHandler, + glacier = glacier::GlacierHandler, } pub struct Context { diff --git a/src/handlers/glacier.rs b/src/handlers/glacier.rs new file mode 100644 index 000000000..23bb8cf2b --- /dev/null +++ b/src/handlers/glacier.rs @@ -0,0 +1,64 @@ +//! Allows team members to directly create a glacier PR with the code provided. + +use crate::{ + config::GlacierConfig, + github::Event, + handlers::{Context, Handler}, +}; + +use futures::future::{BoxFuture, FutureExt}; +use parser::command::glacier::GlacierCommand; +use parser::command::{Command, Input}; + +pub(super) struct GlacierHandler; + +impl Handler for GlacierHandler { + type Input = GlacierCommand; + type Config = GlacierConfig; + + fn parse_input( + &self, + ctx: &Context, + event: &Event, + _: Option<&GlacierConfig>, + ) -> Result, String> { + let body = if let Some(b) = event.comment_body() { + b + } else { + // not interested in other events + return Ok(None); + }; + + match event { + Event::IssueComment(_) => (), + _ => {return Ok(None);} + }; + + let mut input = Input::new(&body, &ctx.username); + match input.parse_command() { + Command::Glacier(Ok(command)) => Ok(Some(command)), + Command::Glacier(Err(err)) => { + return Err(format!( + "Parsing assign command in [comment]({}) failed: {}", + event.html_url().expect("has html url"), + err + )); + } + _ => Ok(None), + } + } + + fn handle_input<'a>( + &self, + ctx: &'a Context, + _config: &'a GlacierConfig, + event: &'a Event, + cmd: GlacierCommand, + ) -> BoxFuture<'a, anyhow::Result<()>> { + handle_input(ctx, event, cmd).boxed() + } +} + +async fn handle_input(_ctx: &Context, _event: &Event, _cmd: GlacierCommand) -> anyhow::Result<()> { + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index c4bd9057f..9c7def041 100644 --- a/src/main.rs +++ b/src/main.rs @@ -221,6 +221,11 @@ async fn main() { dotenv::dotenv().ok(); logger::init(); + let _octocrab = octocrab::OctocrabBuilder::new() + .personal_token(env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN")) + .build() + .expect("Failed to build octograb."); + let port = env::var("PORT") .ok() .map(|p| p.parse::().expect("parsed PORT")) From 7e4cfd196baeacfa18eccfbe97cfb51810dc27bb Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Thu, 21 May 2020 12:02:20 +0200 Subject: [PATCH 05/10] Fix tests --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index aace8f24c..43fb7b185 100644 --- a/src/config.rs +++ b/src/config.rs @@ -230,6 +230,7 @@ mod tests { }), prioritize: None, major_change: None, + glacier: None, } ); } From c0172196766a4da0b3d3e1fbd06e395426226a2a Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Thu, 21 May 2020 22:52:08 +0200 Subject: [PATCH 06/10] First implementation proposal --- Cargo.lock | 8 ++++--- Cargo.toml | 2 +- parser/src/command/glacier.rs | 10 ++++---- src/handlers/glacier.rs | 45 ++++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2551e3a2..27765769c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -771,16 +771,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "octocrab" version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/XAMPPRocky/octocrab#8f30ce0ca56adf454df47909ce23d138638ff496" dependencies = [ "arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "async-trait 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "hyperx 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_path_to_error 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1461,7 +1463,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "octocrab 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "octocrab 0.2.3 (git+https://github.com/XAMPPRocky/octocrab)", "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)", "parser 0.1.0", @@ -1821,7 +1823,7 @@ dependencies = [ "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" "checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" "checksum object 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" -"checksum octocrab 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ba5c6067163fe198be510286a88f76dce9ed0a6ab1fc88f17e215609c9aff7d" +"checksum octocrab 0.2.3 (git+https://github.com/XAMPPRocky/octocrab)" = "" "checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)" = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" diff --git a/Cargo.toml b/Cargo.toml index 269cf7ba2..8b669ef35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ tokio-postgres = { version = "0.5", features = ["with-chrono-0_4"] } postgres-native-tls = "0.3" native-tls = "0.2" serde_path_to_error = "0.1.2" -octocrab = "0.2" +octocrab = { git = "https://github.com/XAMPPRocky/octocrab", branch = "master" } [dependencies.serde] version = "1" diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs index ad4a83d30..3db479b15 100644 --- a/parser/src/command/glacier.rs +++ b/parser/src/command/glacier.rs @@ -8,7 +8,7 @@ //! Command: `@bot glacier ` //! //! : -//! - "https://play.rust-lang.org/.*" +//! - "https://gist.github.com/.*" //! ``` use crate::error::Error; @@ -17,7 +17,7 @@ use std::fmt; #[derive(PartialEq, Eq, Debug)] pub struct GlacierCommand { - source: String, + pub source: String, } #[derive(PartialEq, Eq, Debug)] @@ -45,7 +45,7 @@ impl GlacierCommand { match toks.next_token()? { Some(Token::Quote(s)) => { let source = s.to_owned(); - if source.starts_with("https://play.rust-lang.org/") { + if source.starts_with("https://gist.github.com/") { return Ok(Some(GlacierCommand { source })); } else { return Err(toks.error(ParseError::InvalidLink)); @@ -102,9 +102,9 @@ mod test { #[test] fn glacier_valid() { assert_eq!( - parse(r#"glacier "https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a85913678bee64a3262db9a4a59463c2""#), + parse(r#"glacier "https://gist.github.com/rust-play/89d6c8a2398dd2dd5fcb7ef3e8109c7b""#), Ok(Some(GlacierCommand { - source: "https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a85913678bee64a3262db9a4a59463c2".into() + source: "https://gist.github.com/rust-play/89d6c8a2398dd2dd5fcb7ef3e8109c7b".into() })) ); } diff --git a/src/handlers/glacier.rs b/src/handlers/glacier.rs index 23bb8cf2b..ccaa9ed23 100644 --- a/src/handlers/glacier.rs +++ b/src/handlers/glacier.rs @@ -9,6 +9,8 @@ use crate::{ use futures::future::{BoxFuture, FutureExt}; use parser::command::glacier::GlacierCommand; use parser::command::{Command, Input}; +use octocrab::params::repos::Reference; +use octocrab::models::Object; pub(super) struct GlacierHandler; @@ -59,6 +61,47 @@ impl Handler for GlacierHandler { } } -async fn handle_input(_ctx: &Context, _event: &Event, _cmd: GlacierCommand) -> anyhow::Result<()> { +async fn handle_input(ctx: &Context, event: &Event, cmd: GlacierCommand) -> anyhow::Result<()> { + let is_team_member = if let Err(_) | Ok(false) = event.user().is_team_member(&ctx.github).await + { + false + } else { + true + }; + + if !is_team_member { + return Ok(()) + }; + + let url = cmd.source; + let response = reqwest::get(&format!("{}{}", url.replace("github", "githubusercontent"), "/playground.rs")).await?; + let body = response.text().await?; + + let number = event.issue().unwrap().number; + let user = event.user(); + + let octocrab = octocrab::instance(); + + let fork = octocrab.repos("rust-lang", "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 { + panic!() + }; + + fork.create_ref(&Reference::Branch(format!("triagebot-ice-{}", number)), master).await?; + fork.create_file(format!("ices/{}.rs", number), format!("This PR was created by {} on issue {}.", user.login, number), body) + .branch("triagebot-ice") + .send() + .await?; + + octocrab.pulls("rust-lang", "glacier") + .create(format!("ICE - {}", number), format!("triagebot-ice-{}", number), "master") + .body("This is a fake new catastrophic avalanche of ICE!") + .send() + .await?; Ok(()) } From 30e671f21fbe4f6473f2549082f0e38d3fc695c6 Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Fri, 22 May 2020 08:42:33 +0200 Subject: [PATCH 07/10] Address review requests --- parser/src/command/glacier.rs | 6 ++++-- src/handlers.rs | 2 ++ src/handlers/glacier.rs | 14 +++++++------- src/main.rs | 10 +++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs index 3db479b15..bf5bb3fbe 100644 --- a/parser/src/command/glacier.rs +++ b/parser/src/command/glacier.rs @@ -1,6 +1,6 @@ //! The glacier command parser. //! -//! This adds the option to track ICEs. +//! This adds the option to track ICEs. Do note that the gist must be from a playground link. //! //! The grammar is as follows: //! @@ -102,7 +102,9 @@ mod test { #[test] fn glacier_valid() { assert_eq!( - parse(r#"glacier "https://gist.github.com/rust-play/89d6c8a2398dd2dd5fcb7ef3e8109c7b""#), + 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/handlers.rs b/src/handlers.rs index e5beafaa8..85d841c46 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,6 +1,7 @@ use crate::config::{self, ConfigurationError}; use crate::github::{Event, GithubClient}; use futures::future::BoxFuture; +use octocrab::Octocrab; use std::fmt; use tokio_postgres::Client as DbClient; @@ -87,6 +88,7 @@ pub struct Context { pub github: GithubClient, pub db: DbClient, pub username: String, + pub octocrab: Octocrab, } pub trait Handler: Sync + Send { diff --git a/src/handlers/glacier.rs b/src/handlers/glacier.rs index ccaa9ed23..b849653cb 100644 --- a/src/handlers/glacier.rs +++ b/src/handlers/glacier.rs @@ -74,15 +74,15 @@ async fn handle_input(ctx: &Context, event: &Event, cmd: GlacierCommand) -> anyh }; let url = cmd.source; - let response = reqwest::get(&format!("{}{}", url.replace("github", "githubusercontent"), "/playground.rs")).await?; + let response = ctx.github.raw().get(&format!("{}{}", url.replace("github", "githubusercontent"), "/playground.rs")).send().await?; let body = response.text().await?; let number = event.issue().unwrap().number; let user = event.user(); - let octocrab = octocrab::instance(); + let octocrab = &ctx.octocrab; - let fork = octocrab.repos("rust-lang", "glacier"); + let fork = octocrab.repos("rustbot", "glacier"); let base = octocrab.repos("rust-lang", "glacier"); let master = base.get_ref(&Reference::Branch("master".to_string())).await?.object; @@ -93,14 +93,14 @@ async fn handle_input(ctx: &Context, event: &Event, cmd: GlacierCommand) -> anyh }; fork.create_ref(&Reference::Branch(format!("triagebot-ice-{}", number)), master).await?; - fork.create_file(format!("ices/{}.rs", number), format!("This PR was created by {} on issue {}.", user.login, number), body) - .branch("triagebot-ice") + fork.create_file(format!("ices/{}.rs", number), format!("Add ICE reproduction for issue #{}.", number), body) + .branch(format!("triagebot-ice-{}", number)) .send() .await?; octocrab.pulls("rust-lang", "glacier") - .create(format!("ICE - {}", number), format!("triagebot-ice-{}", number), "master") - .body("This is a fake new catastrophic avalanche of ICE!") + .create(format!("ICE - {}", number), format!("rustbot:triagebot-ice-{}", number), "master") + .body(format!("Automatically created by @{} in issue #{}", user.login, number),) .send() .await?; Ok(()) diff --git a/src/main.rs b/src/main.rs index 9c7def041..0926e0fc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -185,10 +185,15 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> { client.clone(), env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN"), ); + let oc = octocrab::OctocrabBuilder::new() + .personal_token(env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN")) + .build() + .expect("Failed to build octograb."); let ctx = Arc::new(Context { username: github::User::current(&gh).await.unwrap().login, db: db_client, github: gh, + octocrab: oc, }); let svc = hyper::service::make_service_fn(move |_conn| { @@ -221,11 +226,6 @@ async fn main() { dotenv::dotenv().ok(); logger::init(); - let _octocrab = octocrab::OctocrabBuilder::new() - .personal_token(env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN")) - .build() - .expect("Failed to build octograb."); - let port = env::var("PORT") .ok() .map(|p| p.parse::().expect("parsed PORT")) From 8a3668e0e4f9f350af425b658be418fb3e7ac341 Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Fri, 22 May 2020 15:06:40 +0200 Subject: [PATCH 08/10] Address most review requests --- parser/src/command/glacier.rs | 5 +++-- src/handlers/glacier.rs | 10 +++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/parser/src/command/glacier.rs b/parser/src/command/glacier.rs index bf5bb3fbe..18cfcd531 100644 --- a/parser/src/command/glacier.rs +++ b/parser/src/command/glacier.rs @@ -1,6 +1,7 @@ //! The glacier command parser. //! //! This adds the option to track ICEs. Do note that the gist must be from a playground link. +//! The link must also be in quotes. //! //! The grammar is as follows: //! @@ -31,8 +32,8 @@ 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"), - Self::InvalidLink => write!(f, "invalid link"), + 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"), } } } diff --git a/src/handlers/glacier.rs b/src/handlers/glacier.rs index b849653cb..9d5104716 100644 --- a/src/handlers/glacier.rs +++ b/src/handlers/glacier.rs @@ -31,17 +31,12 @@ impl Handler for GlacierHandler { return Ok(None); }; - match event { - Event::IssueComment(_) => (), - _ => {return Ok(None);} - }; - let mut input = Input::new(&body, &ctx.username); match input.parse_command() { Command::Glacier(Ok(command)) => Ok(Some(command)), Command::Glacier(Err(err)) => { return Err(format!( - "Parsing assign command in [comment]({}) failed: {}", + "Parsing glacier command in [comment]({}) failed: {}", event.html_url().expect("has html url"), err )); @@ -89,7 +84,8 @@ async fn handle_input(ctx: &Context, event: &Event, cmd: GlacierCommand) -> anyh let master = if let Object::Commit { sha, ..} = master { sha } else { - panic!() + log::error!("invalid commit sha - master {:?}", master); + unreachable!() }; fork.create_ref(&Reference::Branch(format!("triagebot-ice-{}", number)), master).await?; From b2d14bc07b4d1bce3762c7e46afd3100da0b84ae Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Fri, 22 May 2020 15:41:13 +0000 Subject: [PATCH 09/10] Update src/handlers/glacier.rs Co-authored-by: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> --- src/handlers/glacier.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/handlers/glacier.rs b/src/handlers/glacier.rs index 9d5104716..ebc970894 100644 --- a/src/handlers/glacier.rs +++ b/src/handlers/glacier.rs @@ -57,12 +57,7 @@ impl Handler for GlacierHandler { } async fn handle_input(ctx: &Context, event: &Event, cmd: GlacierCommand) -> anyhow::Result<()> { - let is_team_member = if let Err(_) | Ok(false) = event.user().is_team_member(&ctx.github).await - { - false - } else { - true - }; + let is_team_member = event.user().is_team_member(&ctx.github).await.unwrap_or(false); if !is_team_member { return Ok(()) From f0af1c60cc3cb0b027c4d9215752e9101ae950ea Mon Sep 17 00:00:00 2001 From: Elinvynia <59487684+Elinvynia@users.noreply.github.com> Date: Fri, 22 May 2020 17:52:27 +0200 Subject: [PATCH 10/10] Replace octocrab git dependency --- Cargo.lock | 57 +++++------------------------------------------------- Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27765769c..bd69552f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -660,17 +660,6 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mio-named-pipes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mio-uds" version = "0.6.8" @@ -692,15 +681,6 @@ dependencies = [ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "miow" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "native-tls" version = "0.2.4" @@ -770,12 +750,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "octocrab" -version = "0.2.3" -source = "git+https://github.com/XAMPPRocky/octocrab#8f30ce0ca56adf454df47909ce23d138638ff496" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "async-trait 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "hyperx 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -784,7 +765,6 @@ dependencies = [ "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "serde_path_to_error 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "snafu 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1213,15 +1193,6 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "signal-hook-registry" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "siphasher" version = "0.3.3" @@ -1257,17 +1228,6 @@ dependencies = [ "syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "socket2" -version = "0.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sourcefile" version = "0.1.4" @@ -1359,14 +1319,11 @@ dependencies = [ "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project-lite 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1463,7 +1420,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "octocrab 0.2.3 (git+https://github.com/XAMPPRocky/octocrab)", + "octocrab 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)", "parser 0.1.0", @@ -1812,10 +1769,8 @@ dependencies = [ "checksum mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" "checksum mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" "checksum mio 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" -"checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" "checksum mio-uds 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum miow 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22dfdd1d51b2639a5abd17ed07005c3af05fb7a2a3b1a1d0d7af1000a520c1c7" "checksum native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" "checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" @@ -1823,7 +1778,7 @@ dependencies = [ "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" "checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" "checksum object 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" -"checksum octocrab 0.2.3 (git+https://github.com/XAMPPRocky/octocrab)" = "" +"checksum octocrab 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72189709b525449bf6f31bec64eb6fdc3106d2b5e58274f1d2a767aa9736ceb5" "checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)" = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd" @@ -1871,13 +1826,11 @@ dependencies = [ "checksum serde_path_to_error 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "359b895005d818163c78a24d272cc98567cce80c2461cf73f513da1d296c0b62" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" -"checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" "checksum siphasher 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum snafu 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c7f5aed652511f5c9123cf2afbe9c244c29db6effa2abb05c866e965c82405ce" "checksum snafu-derive 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ebf8f7d5720104a9df0f7076a8682024e958bba0fe9848767bb44f251f3648e9" -"checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" diff --git a/Cargo.toml b/Cargo.toml index 8b669ef35..7227bc1bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ tokio-postgres = { version = "0.5", features = ["with-chrono-0_4"] } postgres-native-tls = "0.3" native-tls = "0.2" serde_path_to_error = "0.1.2" -octocrab = { git = "https://github.com/XAMPPRocky/octocrab", branch = "master" } +octocrab = "0.3" [dependencies.serde] version = "1"