Parcourir la source

Basic close command structure

kellda il y a 4 ans
Parent
commit
40b8382190
5 fichiers modifiés avec 50 ajouts et 0 suppressions
  1. 8 0
      parser/src/command.rs
  2. 15 0
      parser/src/command/close.rs
  3. 5 0
      src/config.rs
  4. 2 0
      src/handlers.rs
  5. 20 0
      src/handlers/close.rs

+ 8 - 0
parser/src/command.rs

@@ -3,6 +3,7 @@ use crate::error::Error;
 use crate::token::{Token, Tokenizer};
 
 pub mod assign;
+pub mod close;
 pub mod glacier;
 pub mod nominate;
 pub mod ping;
@@ -23,6 +24,7 @@ pub enum Command<'a> {
     Prioritize(Result<prioritize::PrioritizeCommand, Error<'a>>),
     Second(Result<second::SecondCommand, Error<'a>>),
     Glacier(Result<glacier::GlacierCommand, Error<'a>>),
+    Close(Result<close::CloseCommand, Error<'a>>),
 }
 
 #[derive(Debug)]
@@ -110,6 +112,11 @@ impl<'a> Input<'a> {
             Command::Glacier,
             &original_tokenizer,
         ));
+        success.extend(parse_single_command(
+            close::CloseCommand::parse,
+            Command::Close,
+            &original_tokenizer,
+        ));
 
         if success.len() > 1 {
             panic!(
@@ -164,6 +171,7 @@ impl<'a> Command<'a> {
             Command::Prioritize(r) => r.is_ok(),
             Command::Second(r) => r.is_ok(),
             Command::Glacier(r) => r.is_ok(),
+            Command::Close(r) => r.is_ok(),
         }
     }
 

+ 15 - 0
parser/src/command/close.rs

@@ -0,0 +1,15 @@
+use crate::error::Error;
+use crate::token::{Token, Tokenizer};
+
+#[derive(PartialEq, Eq, Debug)]
+pub struct CloseCommand;
+
+impl CloseCommand {
+    pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
+        if let Some(Token::Word("close")) = input.peek_token()? {
+            Ok(Some(Self))
+        } else {
+            Ok(None)
+        }
+    }
+}

+ 5 - 0
src/config.rs

@@ -24,6 +24,7 @@ pub(crate) struct Config {
     pub(crate) prioritize: Option<PrioritizeConfig>,
     pub(crate) major_change: Option<MajorChangeConfig>,
     pub(crate) glacier: Option<GlacierConfig>,
+    pub(crate) close: Option<CloseConfig>,
     pub(crate) autolabel: Option<AutolabelConfig>,
     pub(crate) notify_zulip: Option<NotifyZulipConfig>,
     pub(crate) github_releases: Option<GitHubReleasesConfig>,
@@ -138,6 +139,9 @@ pub(crate) struct MajorChangeConfig {
 #[derive(PartialEq, Eq, Debug, serde::Deserialize)]
 pub(crate) struct GlacierConfig {}
 
+#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
+pub(crate) struct CloseConfig {}
+
 pub(crate) async fn get(gh: &GithubClient, repo: &str) -> Result<Arc<Config>, ConfigurationError> {
     if let Some(config) = get_cached_config(repo) {
         log::trace!("returning config for {} from cache", repo);
@@ -282,6 +286,7 @@ mod tests {
                 prioritize: None,
                 major_change: None,
                 glacier: None,
+                close: None,
                 autolabel: None,
                 notify_zulip: None,
                 github_releases: None,

+ 2 - 0
src/handlers.rs

@@ -25,6 +25,7 @@ impl fmt::Display for HandlerError {
 
 mod assign;
 mod autolabel;
+mod close;
 mod github_releases;
 mod glacier;
 mod major_change;
@@ -224,6 +225,7 @@ command_handlers! {
     prioritize: Prioritize,
     relabel: Relabel,
     major_change: Second,
+    close: Close,
 }
 
 pub struct Context {

+ 20 - 0
src/handlers/close.rs

@@ -0,0 +1,20 @@
+//! Allows to close an issue or a PR
+
+use crate::{config::CloseConfig, github::Event, handlers::Context};
+use parser::command::close::CloseCommand;
+
+pub(super) async fn handle_command(
+    ctx: &Context,
+    _config: &CloseConfig,
+    event: &Event,
+    _cmd: CloseCommand,
+) -> anyhow::Result<()> {
+    let is_team_member = event
+        .user()
+        .is_team_member(&ctx.github)
+        .await
+        .unwrap_or(false);
+    let issue = event.issue().unwrap();
+
+    unimplemented!();
+}