2022-07-19 20:18:58 +00:00
|
|
|
package App::Changelord::Command::Add;
|
|
|
|
|
|
|
|
use 5.36.0;
|
|
|
|
|
|
|
|
use Moo;
|
2022-07-25 15:34:24 +00:00
|
|
|
use CLI::Osprey
|
|
|
|
desc => 'add a change to the NEXT release',
|
|
|
|
description_pod => <<'END';
|
|
|
|
Add a change entry to the NEXT release.
|
|
|
|
END
|
2022-07-19 20:18:58 +00:00
|
|
|
|
|
|
|
use PerlX::Maybe;
|
|
|
|
use Path::Tiny;
|
|
|
|
use App::Changelord::Command::Init;
|
|
|
|
|
2022-07-25 15:34:24 +00:00
|
|
|
with 'App::Changelord::Role::Changelog';
|
2022-07-19 20:18:58 +00:00
|
|
|
|
|
|
|
# TODO validate the type
|
|
|
|
option type => (
|
|
|
|
format => 's',
|
|
|
|
doc => 'type of change',
|
|
|
|
is => 'ro',
|
|
|
|
);
|
|
|
|
|
|
|
|
option ticket => (
|
|
|
|
format => 's',
|
|
|
|
doc => 'associated ticket',
|
|
|
|
is => 'ro',
|
|
|
|
);
|
|
|
|
|
|
|
|
sub is_next($self,$release) {
|
|
|
|
my $version = $release->{version};
|
|
|
|
return !$version || $version eq 'NEXT';
|
|
|
|
}
|
|
|
|
|
|
|
|
sub next_release($self) {
|
|
|
|
my $changelog = $self->changelog;
|
|
|
|
|
|
|
|
my $release = $changelog->{releases}[0];
|
|
|
|
|
|
|
|
unless( $self->is_next($release) ) {
|
|
|
|
unshift $changelog->{releases}->@*,
|
|
|
|
$release = {
|
|
|
|
version => 'NEXT',
|
|
|
|
changes => [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return $release;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub save_changelog($self) {
|
2022-07-25 15:34:24 +00:00
|
|
|
my $src = $self->source;
|
2022-07-19 20:18:58 +00:00
|
|
|
|
|
|
|
path($src)->spew( App::Changelord::Command::Init::serialize_changelog($self) );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run ($self) {
|
|
|
|
my $version = $self->next_release;
|
|
|
|
|
|
|
|
push $version->{changes}->@*, {
|
|
|
|
maybe type => $self->type,
|
|
|
|
maybe ticket => $self->ticket,
|
|
|
|
desc => join ' ', @ARGV,
|
|
|
|
};
|
|
|
|
|
|
|
|
$self->save_changelog;
|
2022-07-25 15:34:24 +00:00
|
|
|
|
|
|
|
say "change added to the changelog";
|
2022-07-19 20:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
'end of App::Changelog::Command::Add';
|