add 'add' command

releases
Yanick Champoux 2022-07-19 16:18:58 -04:00
parent cd7815e30c
commit d4ad827471
4 changed files with 93 additions and 15 deletions

View File

@ -141,6 +141,6 @@ sub run($self) {
}
subcommand $_ => 'App::Changelord::Command::' . ucfirst $_
for qw/ schema validate version bump init/;
for qw/ schema validate version bump init add/;
1;

View File

@ -0,0 +1,68 @@
package App::Changelord::Command::Add;
use 5.36.0;
use Moo;
use CLI::Osprey desc => 'add a change to the changelog';
use PerlX::Maybe;
use Path::Tiny;
use App::Changelord::Command::Init;
has changelog => ( is => 'lazy' );
sub _build_changelog ($self) { $self->parent_command->changelog }
# 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) {
my $src = $self->parent_command->source;
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;
}
'end of App::Changelog::Command::Add';

View File

@ -18,12 +18,9 @@ option json => (
sub run($self) {
my $schema = path(__FILE__)->sibling('changelog-schema.yml')->slurp;
$schema = JSON->new->pretty->encode(YAML::Load($schema));
print $schema;
my $schema = YAML::Load(path(__FILE__)->sibling('changelog-schema.yml')->slurp);
print $self->json ? JSON->new->pretty->encode(YAML::Load($schema)) : YAML::Dump($schema);
}
'end of App::Changelog::Command::Schema';

View File

@ -6,30 +6,43 @@ properties:
additionalProperties: false
properties:
homepage:
type: string
type: [ string, 'null' ]
description: url of the project's homepage
examples:
- https://github.com/yanick/app-changelord
name:
type: string
type: [ 'null', string ]
description: name of the project
examples:
- App::Changelord
type:
change_types:
type: array
items:
type: object
# properties:
# type: object
# properties:
# level: { enum: [ major, minor, patch ] }
# title: { type: string }
additionalProperties: false
properties:
keywords:
type: array
items: { type: string }
level: { enum: [ major, minor, patch ] }
title: { type: string }
releases:
type: array
items:
oneOf:
- type: string
- type: object
additionalProperties: false
properties:
version: { type: string }
date: { type: string }
date: { type: ['null',string] }
changes: { type: 'array', items: { $ref: '#/$defs/change' } }
$defs:
change:
type: object
required: [ desc ]
additionalProperties: false
properties:
desc: { type: string }
ticket: { type: [ string, 'null' ] }
type: { type: [ string, 'null' ] }