add stats to the changes
This commit is contained in:
parent
d68f49668d
commit
1ad1e9810c
@ -16,6 +16,7 @@ with 'App::Changelord::Role::ChangeTypes';
|
|||||||
has changelog => ( is => 'lazy' );
|
has changelog => ( is => 'lazy' );
|
||||||
|
|
||||||
with 'App::Changelord::Role::Versions';
|
with 'App::Changelord::Role::Versions';
|
||||||
|
with 'App::Changelord::Role::Stats';
|
||||||
|
|
||||||
sub _build_changelog ($self) { $self->parent_command->changelog }
|
sub _build_changelog ($self) { $self->parent_command->changelog }
|
||||||
|
|
||||||
@ -50,6 +51,12 @@ sub run ($self) {
|
|||||||
$self->changelog->{releases}[0]{date} = sprintf "%d-%02d-%02d",
|
$self->changelog->{releases}[0]{date} = sprintf "%d-%02d-%02d",
|
||||||
$time[5] + 1900, $time[4], $time[3];
|
$time[5] + 1900, $time[4], $time[3];
|
||||||
|
|
||||||
|
if( $self->changelog->{project}{with_stats} ) {
|
||||||
|
push $self->changelog->{releases}[0]{changes}->@*, {
|
||||||
|
type => 'stats', desc => $self->stats
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
my $change = $self->changelog;
|
my $change = $self->changelog;
|
||||||
Bless($change)->keys(
|
Bless($change)->keys(
|
||||||
[ uniq qw/
|
[ uniq qw/
|
||||||
|
@ -49,6 +49,8 @@ sub run ($self) {
|
|||||||
project => {
|
project => {
|
||||||
name => undef,
|
name => undef,
|
||||||
homepage => undef,
|
homepage => undef,
|
||||||
|
with_stats => 'true',
|
||||||
|
ticket_url => undef,
|
||||||
},
|
},
|
||||||
change_types => $self->change_types,
|
change_types => $self->change_types,
|
||||||
releases => [
|
releases => [
|
||||||
|
@ -21,6 +21,8 @@ properties:
|
|||||||
examples:
|
examples:
|
||||||
- s!GH(\d+)!https://github.com/yanick/App-Changelord/issue/$1/
|
- s!GH(\d+)!https://github.com/yanick/App-Changelord/issue/$1/
|
||||||
- /^\d+$/ ? "https://.../$_" : undef
|
- /^\d+$/ ? "https://.../$_" : undef
|
||||||
|
with_stats:
|
||||||
|
description: if true, add git statistics when bumping the version.
|
||||||
change_types:
|
change_types:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
@ -18,6 +18,7 @@ sub _build_change_types($self) {
|
|||||||
{ title => 'Features' , level => 'minor', keywords => [ 'feat' ] } ,
|
{ title => 'Features' , level => 'minor', keywords => [ 'feat' ] } ,
|
||||||
{ title => 'Bug fixes' , level => 'patch', keywords => [ 'fix' ] },
|
{ title => 'Bug fixes' , level => 'patch', keywords => [ 'fix' ] },
|
||||||
{ title => 'Package maintenance' , level => 'patch', keywords => [ 'chore', 'maint', 'refactor' ] },
|
{ title => 'Package maintenance' , level => 'patch', keywords => [ 'chore', 'maint', 'refactor' ] },
|
||||||
|
{ title => 'Statistics' , level => 'patch', keywords => [ 'stats' ] },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
48
lib/App/Changelord/Role/Stats.pm
Normal file
48
lib/App/Changelord/Role/Stats.pm
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package App::Changelord::Role::Stats;
|
||||||
|
|
||||||
|
use v5.36.0;
|
||||||
|
|
||||||
|
use Git::Repository;
|
||||||
|
|
||||||
|
use Moo::Role;
|
||||||
|
|
||||||
|
use feature 'try'; no warnings qw/ experimental /;
|
||||||
|
|
||||||
|
requires 'changelog';
|
||||||
|
|
||||||
|
# stolen from Dist::Zilla::Plugin::ChangeStats::Git
|
||||||
|
|
||||||
|
has repo => (
|
||||||
|
is => 'ro',
|
||||||
|
default => sub { Git::Repository->new( work_tree => '.' ) },
|
||||||
|
);
|
||||||
|
|
||||||
|
has stats => (
|
||||||
|
is => 'lazy' );
|
||||||
|
|
||||||
|
sub _build_stats ($self) {
|
||||||
|
my $comparison_data = $self->_get_comparison_data or return;
|
||||||
|
|
||||||
|
my $stats = 'code churn: ' . $comparison_data;
|
||||||
|
return $stats =~ s/\s+/ /gr;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _get_comparison_data($self) {
|
||||||
|
|
||||||
|
# HEAD versus previous release
|
||||||
|
# What are we diffing against? :)
|
||||||
|
my $previous = $self->changelog->{releases}->@* > 1
|
||||||
|
? $self->changelog->{releases}[1]{version}
|
||||||
|
: '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; # empty tree
|
||||||
|
|
||||||
|
my $output = eval {
|
||||||
|
$self->repo->run( 'diff', '--shortstat', $previous, 'HEAD')
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
warn "could not gather stats: $@\n" if $@;
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
27
t/stats.t
Normal file
27
t/stats.t
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use Test2::V0;
|
||||||
|
|
||||||
|
use v5.36.0;
|
||||||
|
|
||||||
|
package TestMe {
|
||||||
|
use Moo;
|
||||||
|
|
||||||
|
has changelog => (
|
||||||
|
is => 'ro',
|
||||||
|
default => sub {{
|
||||||
|
project => { ticket_url => undef },
|
||||||
|
releases => [
|
||||||
|
{ },
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
);
|
||||||
|
|
||||||
|
with 'App::Changelord::Role::Stats';
|
||||||
|
with 'App::Changelord::Role::ChangeTypes';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
my $test = TestMe->new;
|
||||||
|
|
||||||
|
like $test->stats => qr/code churn: /;
|
||||||
|
|
||||||
|
done_testing;
|
Loading…
Reference in New Issue
Block a user