Răsfoiți Sursa

rename label to relabel

Pietro Albini 6 ani în urmă
părinte
comite
5496e8f462
5 a modificat fișierele cu 25 adăugiri și 25 ștergeri
  1. 6 6
      parser/src/command.rs
  2. 4 4
      parser/src/command/relabel.rs
  3. 2 2
      src/config.rs
  4. 1 1
      src/handlers.rs
  5. 12 12
      src/handlers/relabel.rs

+ 6 - 6
parser/src/command.rs

@@ -2,7 +2,7 @@ use crate::code_block::ColorCodeBlocks;
 use crate::error::Error;
 use crate::token::{Token, Tokenizer};
 
-pub mod label;
+pub mod relabel;
 
 pub fn find_commmand_start(input: &str, bot: &str) -> Option<usize> {
     input.find(&format!("@{}", bot))
@@ -10,7 +10,7 @@ pub fn find_commmand_start(input: &str, bot: &str) -> Option<usize> {
 
 #[derive(Debug)]
 pub enum Command<'a> {
-    Label(Result<label::LabelCommand, Error<'a>>),
+    Relabel(Result<relabel::RelabelCommand, Error<'a>>),
     None,
 }
 
@@ -50,14 +50,14 @@ impl<'a> Input<'a> {
 
         {
             let mut tok = original_tokenizer.clone();
-            let res = label::LabelCommand::parse(&mut tok);
+            let res = relabel::RelabelCommand::parse(&mut tok);
             match res {
                 Ok(None) => {}
                 Ok(Some(cmd)) => {
-                    success.push((tok, Command::Label(Ok(cmd))));
+                    success.push((tok, Command::Relabel(Ok(cmd))));
                 }
                 Err(err) => {
-                    success.push((tok, Command::Label(Err(err))));
+                    success.push((tok, Command::Relabel(Err(err))));
                 }
             }
         }
@@ -94,7 +94,7 @@ impl<'a> Input<'a> {
 impl<'a> Command<'a> {
     pub fn is_ok(&self) -> bool {
         match self {
-            Command::Label(r) => r.is_ok(),
+            Command::Relabel(r) => r.is_ok(),
             Command::None => true,
         }
     }

+ 4 - 4
parser/src/command/label.rs → parser/src/command/relabel.rs

@@ -30,7 +30,7 @@ use std::error::Error as _;
 use std::fmt;
 
 #[derive(Debug)]
-pub struct LabelCommand(pub Vec<LabelDelta>);
+pub struct RelabelCommand(pub Vec<LabelDelta>);
 
 #[derive(Debug, PartialEq, Eq)]
 pub enum LabelDelta {
@@ -124,7 +124,7 @@ fn delta_empty() {
     assert_eq!(err.position(), 1);
 }
 
-impl LabelCommand {
+impl RelabelCommand {
     pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
         let mut toks = input.clone();
         if let Some(Token::Word("modify")) = toks.next_token()? {
@@ -163,7 +163,7 @@ impl LabelCommand {
             if let Some(Token::Dot) | Some(Token::EndOfLine) = toks.peek_token()? {
                 toks.next_token()?;
                 *input = toks;
-                return Ok(Some(LabelCommand(deltas)));
+                return Ok(Some(RelabelCommand(deltas)));
             }
         }
     }
@@ -172,7 +172,7 @@ impl LabelCommand {
 #[cfg(test)]
 fn parse<'a>(input: &'a str) -> Result<Option<Vec<LabelDelta>>, Error<'a>> {
     let mut toks = Tokenizer::new(input);
-    Ok(LabelCommand::parse(&mut toks)?.map(|c| c.0))
+    Ok(RelabelCommand::parse(&mut toks)?.map(|c| c.0))
 }
 
 #[test]

+ 2 - 2
src/config.rs

@@ -14,12 +14,12 @@ lazy_static::lazy_static! {
 
 #[derive(serde::Deserialize)]
 pub(crate) struct Config {
-    pub(crate) label: Option<LabelConfig>,
+    pub(crate) relabel: Option<RelabelConfig>,
 }
 
 #[derive(serde::Deserialize)]
 #[serde(rename_all = "kebab-case")]
-pub(crate) struct LabelConfig {
+pub(crate) struct RelabelConfig {
     #[serde(default)]
     pub(crate) allow_unauthenticated: Vec<String>,
 }

+ 1 - 1
src/handlers.rs

@@ -26,7 +26,7 @@ macro_rules! handlers {
 
 handlers! {
     //assign = assign::AssignmentHandler,
-    label = label::LabelHandler,
+    relabel = relabel::RelabelHandler,
     //tracking_issue = tracking_issue::TrackingIssueHandler,
 }
 

+ 12 - 12
src/handlers/label.rs → src/handlers/relabel.rs

@@ -3,26 +3,26 @@
 //! Labels are checked against the labels in the project; the bot does not support creating new
 //! labels.
 //!
-//! Parsing is done in the `parser::command::label` module.
+//! Parsing is done in the `parser::command::relabel` module.
 //!
 //! If the command was successful, there will be no feedback beyond the label change to reduce
 //! notification noise.
 
 use crate::{
-    config::LabelConfig,
+    config::RelabelConfig,
     github::{self, Event, GithubClient},
     handlers::{Context, Handler},
     interactions::ErrorComment,
 };
 use failure::Error;
-use parser::command::label::{LabelCommand, LabelDelta};
+use parser::command::relabel::{RelabelCommand, LabelDelta};
 use parser::command::{Command, Input};
 
-pub(super) struct LabelHandler;
+pub(super) struct RelabelHandler;
 
-impl Handler for LabelHandler {
-    type Input = LabelCommand;
-    type Config = LabelConfig;
+impl Handler for RelabelHandler {
+    type Input = RelabelCommand;
+    type Config = RelabelConfig;
 
     fn parse_input(&self, ctx: &Context, event: &Event) -> Result<Option<Self::Input>, Error> {
         #[allow(irrefutable_let_patterns)]
@@ -35,8 +35,8 @@ impl Handler for LabelHandler {
 
         let mut input = Input::new(&event.comment.body, &ctx.username);
         match input.parse_command() {
-            Command::Label(Ok(command)) => Ok(Some(command)),
-            Command::Label(Err(err)) => {
+            Command::Relabel(Ok(command)) => Ok(Some(command)),
+            Command::Relabel(Err(err)) => {
                 failure::bail!(
                     "Parsing label command in [comment]({}) failed: {}",
                     event.comment.html_url, err
@@ -49,9 +49,9 @@ impl Handler for LabelHandler {
     fn handle_input(
         &self,
         ctx: &Context,
-        config: &LabelConfig,
+        config: &RelabelConfig,
         event: &Event,
-        input: LabelCommand,
+        input: RelabelCommand,
     ) -> Result<(), Error> {
         #[allow(irrefutable_let_patterns)]
         let event = if let Event::IssueComment(e) = event {
@@ -97,7 +97,7 @@ impl Handler for LabelHandler {
 
 fn check_filter(
     label: &str,
-    config: &LabelConfig,
+    config: &RelabelConfig,
     user: &github::User,
     client: &GithubClient,
 ) -> Result<(), Error> {