@@ -54,7 +54,7 @@ impl<'a> Changelog<'a> {
54
54
55
55
/// Builds a changelog from releases and config.
56
56
fn build ( releases : Vec < Release < ' a > > , config : & ' a Config ) -> Result < Self > {
57
- let trim = config. changelog . trim . unwrap_or ( true ) ;
57
+ let trim = config. changelog . trim ;
58
58
Ok ( Self {
59
59
releases,
60
60
header_template : match & config. changelog . header {
@@ -127,7 +127,7 @@ impl<'a> Changelog<'a> {
127
127
. cloned ( )
128
128
. filter_map ( |commit| Self :: process_commit ( & commit, & self . config . git ) )
129
129
. flat_map ( |commit| {
130
- if self . config . git . split_commits . unwrap_or ( false ) {
130
+ if self . config . git . split_commits {
131
131
commit
132
132
. message
133
133
. lines ( )
@@ -148,7 +148,7 @@ impl<'a> Changelog<'a> {
148
148
. collect :: < Vec < Commit > > ( ) ;
149
149
} ) ;
150
150
151
- if self . config . git . require_conventional . unwrap_or ( false ) {
151
+ if self . config . git . require_conventional {
152
152
self . check_conventional_commits ( ) ?;
153
153
}
154
154
@@ -203,7 +203,7 @@ impl<'a> Changelog<'a> {
203
203
}
204
204
match & release. previous {
205
205
Some ( prev_release) if prev_release. commits . is_empty ( ) => {
206
- self . config . changelog . render_always . unwrap_or ( false )
206
+ self . config . changelog . render_always
207
207
}
208
208
_ => false ,
209
209
}
@@ -561,12 +561,7 @@ impl<'a> Changelog<'a> {
561
561
/// Generates the changelog and writes it to the given output.
562
562
pub fn generate < W : Write + ?Sized > ( & self , out : & mut W ) -> Result < ( ) > {
563
563
debug ! ( "Generating changelog..." ) ;
564
- let postprocessors = self
565
- . config
566
- . changelog
567
- . postprocessors
568
- . clone ( )
569
- . unwrap_or_default ( ) ;
564
+ let postprocessors = self . config . changelog . postprocessors . clone ( ) ;
570
565
571
566
if let Some ( header_template) = & self . header_template {
572
567
let write_result = writeln ! (
@@ -653,13 +648,7 @@ impl<'a> Changelog<'a> {
653
648
}
654
649
655
650
fn get_body_template ( config : & Config , trim : bool ) -> Result < Template > {
656
- let template_str = config
657
- . changelog
658
- . body
659
- . as_deref ( )
660
- . unwrap_or_default ( )
661
- . to_string ( ) ;
662
- let template = Template :: new ( "body" , template_str, trim) ?;
651
+ let template = Template :: new ( "body" , config. changelog . body . clone ( ) , trim) ?;
663
652
let deprecated_vars = [
664
653
"commit.github" ,
665
654
"commit.gitea" ,
@@ -694,7 +683,7 @@ mod test {
694
683
let config = Config {
695
684
changelog : ChangelogConfig {
696
685
header : Some ( String :: from ( "# Changelog" ) ) ,
697
- body : Some ( String :: from (
686
+ body : String :: from (
698
687
r#"{% if version %}
699
688
## Release [{{ version }}] - {{ timestamp | date(format="%Y-%m-%d") }} - ({{ repository }})
700
689
{% if commit_id %}({{ commit_id }}){% endif %}{% else %}
@@ -704,34 +693,34 @@ mod test {
704
693
#### {{ group }}{% for commit in commits %}
705
694
- {{ commit.message }}{% endfor %}
706
695
{% endfor %}{% endfor %}"# ,
707
- ) ) ,
696
+ ) ,
708
697
footer : Some ( String :: from (
709
698
r#"-- total releases: {{ releases | length }} --"# ,
710
699
) ) ,
711
- trim : Some ( true ) ,
712
- postprocessors : Some ( vec ! [ TextProcessor {
700
+ trim : true ,
701
+ postprocessors : vec ! [ TextProcessor {
713
702
pattern: Regex :: new( "boring" )
714
703
. expect( "failed to compile regex" ) ,
715
704
replace: Some ( String :: from( "exciting" ) ) ,
716
705
replace_command: None ,
717
- } ] ) ,
718
- render_always : None ,
706
+ } ] ,
707
+ render_always : false ,
719
708
output : None ,
720
709
} ,
721
710
git : GitConfig {
722
- conventional_commits : Some ( true ) ,
723
- require_conventional : Some ( false ) ,
724
- filter_unconventional : Some ( false ) ,
725
- split_commits : Some ( false ) ,
726
- commit_preprocessors : Some ( vec ! [ TextProcessor {
711
+ conventional_commits : true ,
712
+ require_conventional : false ,
713
+ filter_unconventional : false ,
714
+ split_commits : false ,
715
+ commit_preprocessors : vec ! [ TextProcessor {
727
716
pattern: Regex :: new( "<preprocess>" )
728
717
. expect( "failed to compile regex" ) ,
729
718
replace: Some ( String :: from(
730
719
"this commit is preprocessed" ,
731
720
) ) ,
732
721
replace_command: None ,
733
- } ] ) ,
734
- commit_parsers : Some ( vec ! [
722
+ } ] ,
723
+ commit_parsers : vec ! [
735
724
CommitParser {
736
725
sha: Some ( String :: from( "tea" ) ) ,
737
726
message: None ,
@@ -864,17 +853,17 @@ mod test {
864
853
field: None ,
865
854
pattern: None ,
866
855
} ,
867
- ] ) ,
868
- protect_breaking_commits : None ,
869
- filter_commits : Some ( false ) ,
856
+ ] ,
857
+ protect_breaking_commits : false ,
858
+ filter_commits : false ,
870
859
tag_pattern : None ,
871
860
skip_tags : Regex :: new ( "v3.*" ) . ok ( ) ,
872
861
ignore_tags : None ,
873
862
count_tags : None ,
874
- use_branch_tags : Some ( false ) ,
875
- topo_order : Some ( false ) ,
876
- sort_commits : Some ( String :: from ( "oldest" ) ) ,
877
- link_parsers : None ,
863
+ use_branch_tags : false ,
864
+ topo_order : false ,
865
+ sort_commits : String :: from ( "oldest" ) ,
866
+ link_parsers : [ ] . to_vec ( ) ,
878
867
limit_commits : None ,
879
868
} ,
880
869
remote : RemoteConfig {
@@ -1150,14 +1139,17 @@ mod test {
1150
1139
#[ test]
1151
1140
fn changelog_generator_split_commits ( ) -> Result < ( ) > {
1152
1141
let ( mut config, mut releases) = get_test_data ( ) ;
1153
- config. git . split_commits = Some ( true ) ;
1154
- config. git . filter_unconventional = Some ( false ) ;
1155
- config. git . protect_breaking_commits = Some ( true ) ;
1156
-
1157
- if let Some ( parsers) = config. git . commit_parsers . as_mut ( ) {
1158
- for parser in parsers. iter_mut ( ) . filter ( |p| p. footer . is_some ( ) ) {
1159
- parser. skip = Some ( true ) ;
1160
- }
1142
+ config. git . split_commits = true ;
1143
+ config. git . filter_unconventional = false ;
1144
+ config. git . protect_breaking_commits = true ;
1145
+
1146
+ for parser in config
1147
+ . git
1148
+ . commit_parsers
1149
+ . iter_mut ( )
1150
+ . filter ( |p| p. footer . is_some ( ) )
1151
+ {
1152
+ parser. skip = Some ( true ) ;
1161
1153
}
1162
1154
1163
1155
releases[ 0 ] . commits . push ( Commit :: new (
@@ -1280,8 +1272,7 @@ chore(deps): fix broken deps
1280
1272
fn changelog_adds_additional_context ( ) -> Result < ( ) > {
1281
1273
let ( mut config, releases) = get_test_data ( ) ;
1282
1274
// add `{{ custom_field }}` to the template
1283
- config. changelog . body = Some (
1284
- r#"{% if version %}
1275
+ config. changelog . body = r#"{% if version %}
1285
1276
## {{ custom_field }} [{{ version }}] - {{ timestamp | date(format="%Y-%m-%d") }}
1286
1277
{% if commit_id %}({{ commit_id }}){% endif %}{% else %}
1287
1278
## Unreleased{% endif %}
@@ -1290,8 +1281,7 @@ chore(deps): fix broken deps
1290
1281
#### {{ group }}{% for commit in commits %}
1291
1282
- {{ commit.message }}{% endfor %}
1292
1283
{% endfor %}{% endfor %}"#
1293
- . to_string ( ) ,
1294
- ) ;
1284
+ . to_string ( ) ;
1295
1285
let mut changelog = Changelog :: new ( releases, & config) ?;
1296
1286
changelog. add_context ( "custom_field" , "Hello" ) ?;
1297
1287
let mut out = Vec :: new ( ) ;
0 commit comments