2022-07-19 17:34:13 +00:00
|
|
|
package App::Changelord::Command::Init;
|
|
|
|
|
|
|
|
use 5.36.0;
|
|
|
|
|
|
|
|
use Moo;
|
|
|
|
use CLI::Osprey desc => 'initialize new changelog source file';
|
|
|
|
|
|
|
|
use Path::Tiny;
|
|
|
|
use JSON;
|
|
|
|
use YAML qw/ Bless /;
|
|
|
|
use List::AllUtils qw/ first min uniq /;
|
|
|
|
use Version::Dotted::Semantic;
|
|
|
|
|
|
|
|
with 'App::Changelord::Role::ChangeTypes';
|
2022-07-25 15:55:42 +00:00
|
|
|
with 'App::Changelord::Role::Changelog';
|
2022-07-19 17:34:13 +00:00
|
|
|
with 'App::Changelord::Role::Versions';
|
|
|
|
|
|
|
|
sub serialize_changelog($self, $changelog = undef) {
|
|
|
|
|
|
|
|
$changelog //= $self->changelog;
|
|
|
|
|
|
|
|
Bless($changelog)->keys(
|
|
|
|
[ uniq qw/
|
|
|
|
project releases change_types
|
|
|
|
/, sort keys %$changelog
|
|
|
|
] );
|
|
|
|
Bless( $changelog->{project} )->keys(
|
|
|
|
[ uniq qw/
|
|
|
|
name homepage
|
|
|
|
/, sort keys $changelog->{project}->%*
|
|
|
|
] );
|
|
|
|
|
|
|
|
for ( grep { ref } $changelog->{releases}->@* ) {
|
|
|
|
Bless($_)->keys( [ uniq qw/ version date changes /, sort keys %$_ ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return YAML::Dump($changelog);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run ($self) {
|
2022-07-25 15:55:42 +00:00
|
|
|
my $src = $self->source;
|
2022-07-19 17:34:13 +00:00
|
|
|
die "file '$src' already exists, aborting\n" if -f $src;
|
|
|
|
|
|
|
|
my $change = {
|
|
|
|
project => {
|
|
|
|
name => undef,
|
|
|
|
homepage => undef,
|
2022-07-20 18:27:53 +00:00
|
|
|
with_stats => 'true',
|
|
|
|
ticket_url => undef,
|
2022-07-25 15:55:42 +00:00
|
|
|
commit_regex => q/^(?<type>[^: ]+):(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$/,
|
2022-07-19 17:34:13 +00:00
|
|
|
},
|
|
|
|
change_types => $self->change_types,
|
|
|
|
releases => [
|
|
|
|
{ version => 'NEXT', changes => [] }
|
|
|
|
]
|
|
|
|
};
|
|
|
|
path($src)->spew( $self->serialize_changelog($change) );
|
|
|
|
|
|
|
|
say "file '$src' created, enjoy!";
|
|
|
|
}
|
|
|
|
|
|
|
|
'end of App::Changelog::Command::Init';
|