add 'add' command
This commit is contained in:
parent
cd7815e30c
commit
d4ad827471
@ -141,6 +141,6 @@ sub run($self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subcommand $_ => 'App::Changelord::Command::' . ucfirst $_
|
subcommand $_ => 'App::Changelord::Command::' . ucfirst $_
|
||||||
for qw/ schema validate version bump init/;
|
for qw/ schema validate version bump init add/;
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
68
lib/App/Changelord/Command/Add.pm
Normal file
68
lib/App/Changelord/Command/Add.pm
Normal 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';
|
@ -18,12 +18,9 @@ option json => (
|
|||||||
|
|
||||||
sub run($self) {
|
sub run($self) {
|
||||||
|
|
||||||
my $schema = path(__FILE__)->sibling('changelog-schema.yml')->slurp;
|
my $schema = YAML::Load(path(__FILE__)->sibling('changelog-schema.yml')->slurp);
|
||||||
|
|
||||||
$schema = JSON->new->pretty->encode(YAML::Load($schema));
|
|
||||||
|
|
||||||
print $schema;
|
|
||||||
|
|
||||||
|
print $self->json ? JSON->new->pretty->encode(YAML::Load($schema)) : YAML::Dump($schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
'end of App::Changelog::Command::Schema';
|
'end of App::Changelog::Command::Schema';
|
||||||
|
@ -6,30 +6,43 @@ properties:
|
|||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
homepage:
|
homepage:
|
||||||
type: string
|
type: [ string, 'null' ]
|
||||||
description: url of the project's homepage
|
description: url of the project's homepage
|
||||||
examples:
|
examples:
|
||||||
- https://github.com/yanick/app-changelord
|
- https://github.com/yanick/app-changelord
|
||||||
name:
|
name:
|
||||||
type: string
|
type: [ 'null', string ]
|
||||||
description: name of the project
|
description: name of the project
|
||||||
examples:
|
examples:
|
||||||
- App::Changelord
|
- App::Changelord
|
||||||
type:
|
change_types:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: object
|
type: object
|
||||||
# properties:
|
additionalProperties: false
|
||||||
# type: object
|
properties:
|
||||||
# properties:
|
keywords:
|
||||||
# level: { enum: [ major, minor, patch ] }
|
type: array
|
||||||
# title: { type: string }
|
items: { type: string }
|
||||||
|
level: { enum: [ major, minor, patch ] }
|
||||||
|
title: { type: string }
|
||||||
releases:
|
releases:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
oneOf:
|
oneOf:
|
||||||
- type: string
|
- type: string
|
||||||
- type: object
|
- type: object
|
||||||
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
version: { type: string }
|
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' ] }
|
||||||
|
Loading…
Reference in New Issue
Block a user