Skip to content

Commit

Permalink
refactor(postprocessors): polish the implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jun 10, 2023
1 parent 58e42b9 commit 6b060f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ impl<'a> Changelog<'a> {
}
for release in &self.releases {
let mut rendered = self.template.render(release)?;
if let Some(preprocessors) =
if let Some(postprocessors) =
self.config.changelog.postprocessors.as_ref()
{
for preprocessor in preprocessors {
preprocessor.replace(&mut rendered, vec![])?;
for postprocessor in postprocessors {
postprocessor.replace(&mut rendered, vec![])?;
}
}

Expand Down
11 changes: 5 additions & 6 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::command;
use crate::error::Result;
use regex::{
Regex,
Expand Down Expand Up @@ -110,7 +111,8 @@ pub struct TextProcessor {
}

impl TextProcessor {
pub(crate) fn replace(
/// Replaces the text with using the given pattern or the command output.
pub fn replace(
&self,
rendered: &mut String,
command_envs: Vec<(&str, &str)>,
Expand All @@ -119,11 +121,8 @@ impl TextProcessor {
*rendered = self.pattern.replace_all(rendered, text).to_string();
} else if let Some(command) = &self.replace_command {
if self.pattern.is_match(rendered) {
*rendered = crate::command::run(
command,
Some(rendered.to_string()),
command_envs,
)?;
*rendered =
command::run(command, Some(rendered.to_string()), command_envs)?;
}
}
Ok(())
Expand Down

0 comments on commit 6b060f8

Please sign in to comment.