Skip to content

Commit

Permalink
feat: allow field to read from context object
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTiedemann committed Jul 12, 2024
1 parent 7cca889 commit 7db25f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
7 changes: 0 additions & 7 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ impl<'a> Changelog<'a> {
}
}

// fn load_commits(&mut self) {
// debug!("Loading commits...");
// self.releases.iter_mut().for_each(|release| {

// })
// }

/// Processes the commits and omits the ones that doesn't match the
/// criteria set by configuration file.
fn process_commits(&mut self) {
Expand Down
31 changes: 15 additions & 16 deletions git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ impl Commit<'_> {
protect_breaking: bool,
filter: bool,
) -> Result<Self> {
let lookup_context = serde_json::to_value(&self).map_err(|e| {
AppError::FieldError(format!(
"failed to convert context into value: {}",
e
))
})?;

for parser in parsers {
let mut regex_checks = Vec::new();
if let Some(message_regex) = parser.message.as_ref() {
Expand All @@ -287,25 +294,17 @@ impl Commit<'_> {
if let (Some(field_name), Some(pattern_regex)) =
(parser.field.as_ref(), parser.pattern.as_ref())
{
regex_checks.push((
pattern_regex,
match field_name.as_str() {
"id" => Some(self.id.clone()),
"message" => Some(self.message.clone()),
"body" => body,
"author.name" => self.author.name.clone(),
"author.email" => self.author.email.clone(),
"committer.name" => self.committer.name.clone(),
"committer.email" => self.committer.email.clone(),
_ => None,
match tera::dotted_pointer(&lookup_context, field_name) {
Some(value) => {
regex_checks.push((pattern_regex, value.to_string()));
}
.ok_or_else(|| {
AppError::FieldError(format!(
None => {
return Err(AppError::FieldError(format!(
"field {} does not have a value",
field_name
))
})?,
));
)));
}
}
}
if parser.sha.clone().map(|v| v.to_lowercase()).as_deref() ==
Some(&self.id)
Expand Down

0 comments on commit 7db25f8

Please sign in to comment.