@@ -42,16 +42,18 @@ pub struct Changelog<'a> {
42
42
43
43
impl < ' a > Changelog < ' a > {
44
44
/// Constructs a new instance.
45
- ///
46
- /// Processes the commits/releases and fetches the remote data
47
- /// if `process_data` is set to `true`.
48
- pub fn new (
49
- releases : Vec < Release < ' a > > ,
50
- config : Config ,
51
- process_data : bool ,
52
- ) -> Result < Self > {
45
+ pub fn new ( releases : Vec < Release < ' a > > , config : Config ) -> Result < Self > {
46
+ let mut changelog = Changelog :: build ( releases, config) ?;
47
+ changelog. add_remote_data ( ) ?;
48
+ changelog. process_commits ( ) ;
49
+ changelog. process_releases ( ) ;
50
+ Ok ( changelog)
51
+ }
52
+
53
+ /// Builds a changelog from releases and config.
54
+ fn build ( releases : Vec < Release < ' a > > , config : Config ) -> Result < Self > {
53
55
let trim = config. changelog . trim . unwrap_or ( true ) ;
54
- let mut changelog = Self {
56
+ Ok ( Self {
55
57
releases,
56
58
header_template : match & config. changelog . header {
57
59
Some ( header) => {
@@ -68,18 +70,12 @@ impl<'a> Changelog<'a> {
68
70
} ,
69
71
config,
70
72
additional_context : HashMap :: new ( ) ,
71
- } ;
72
- if process_data {
73
- changelog. add_remote_data ( ) ?;
74
- changelog. process_commits ( ) ;
75
- changelog. process_releases ( ) ;
76
- }
77
- Ok ( changelog)
73
+ } )
78
74
}
79
75
80
76
/// Constructs an instance from a serialized context object.
81
77
pub fn from_context < R : Read > ( input : & mut R , config : Config ) -> Result < Self > {
82
- Changelog :: new ( serde_json:: from_reader ( input) ?, config, false )
78
+ Changelog :: build ( serde_json:: from_reader ( input) ?, config)
83
79
}
84
80
85
81
/// Adds a key value pair to the template context.
@@ -1030,7 +1026,7 @@ mod test {
1030
1026
#[ test]
1031
1027
fn changelog_generator ( ) -> Result < ( ) > {
1032
1028
let ( config, releases) = get_test_data ( ) ;
1033
- let mut changelog = Changelog :: new ( releases, config, true ) ?;
1029
+ let mut changelog = Changelog :: new ( releases, config) ?;
1034
1030
changelog. bump_version ( ) ?;
1035
1031
changelog. releases [ 0 ] . timestamp = 0 ;
1036
1032
let mut out = Vec :: new ( ) ;
@@ -1149,7 +1145,7 @@ chore(deps): fix broken deps
1149
1145
" ,
1150
1146
) ,
1151
1147
) ) ;
1152
- let changelog = Changelog :: new ( releases, config, true ) ?;
1148
+ let changelog = Changelog :: new ( releases, config) ?;
1153
1149
let mut out = Vec :: new ( ) ;
1154
1150
changelog. generate ( & mut out) ?;
1155
1151
assert_eq ! (
@@ -1253,7 +1249,7 @@ chore(deps): fix broken deps
1253
1249
{% endfor %}{% endfor %}"#
1254
1250
. to_string ( ) ,
1255
1251
) ;
1256
- let mut changelog = Changelog :: new ( releases, config, true ) ?;
1252
+ let mut changelog = Changelog :: new ( releases, config) ?;
1257
1253
changelog. add_context ( "custom_field" , "Hello" ) ?;
1258
1254
let mut out = Vec :: new ( ) ;
1259
1255
changelog. generate ( & mut out) ?;
0 commit comments