Changelord/Command/Bump.pm

filter: Statementstmt 53.5% 30 / 56 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 45.2% 38 / 84 CC 8 SCAR 36.0
CC
8
Cov
43%
run
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 36.5
↑ Summary Changelord/Command/Version.pm »
1 package App::Changelord::Command::Bump;
2 2 our $AUTHORITY = 'cpan:YANICK';
3 2 $App::Changelord::Command::Bump::VERSION = '0.0.2';
4 2 ▶use 5.36.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use CLI::Osprey desc => 'bump next version',
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 description_pod => <<'END';
9 Set a version for the NEXT release based on the types of its changes.
10 Also set the release date of that release to today.
11 END
12  
13 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use YAML qw/ Bless /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use List::AllUtils qw/ first min uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Version::Dotted::Semantic;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 with 'App::Changelord::Role::Changelog';
20 2 with 'App::Changelord::Role::ChangeTypes';
21 2 with 'App::Changelord::Role::Versions';
22 2 with 'App::Changelord::Role::GitRepo';
23  
24 0 ▶sub run ($self) {
Subroutine run: not called CC=8 SCAR=42.8
Pod undocumented
25 0 my $bump = shift @ARGV;
26  
27 0 ▶ if ( $bump and !grep { $_ eq $bump } qw/ minor major patch / ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bump and not grep({$_ eq $bump;} "minor", "major", "patch")) 0 0 0
Condition0%0/3
$bump and not grep({$_ eq $bump;} "minor", "major", "patch")
!ll&&!rl&&r
000
MC/DC0%0/2
$bump and not grep({$_ eq $bump;} "minor", "major", "patch")
$bump not grep({$_ eq $bump;} "minor", "major", "patch")
Truth table0%0/3
A and not(B)
A= $bumpB= not grep({$_ eq $bump;} "minor", "major", "patch")
ABresult
0X0
100
111
28 0 die "invalid bump type '$bump', must be major, minor, or patch\n";
29 }
30  
31 0 my $version;
32  
33 0 ▶ if ($bump) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bump) { } 0 0 0
34 0 $version = Version::Dotted::Semantic->new( $self->latest_version );
35 0 $version->bump($bump);
36 0 $version = $version->stringify;
37 }
38 else {
39 0 $version = $self->next_version;
40 }
41  
42 0 ▶ if ( $self->changelog->{releases}[0]{version}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->changelog->{"releases"}[0]{"version"} and $self->changelog->{"releases"}[0]{"version"} ne "NEXT") 0 0 0
Condition0%0/3
$self->changelog->{"releases"}[0]{"version"} and $self->changelog->{"releases"}[0]{"version"} ne "NEXT"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->changelog->{"releases"}[0]{"version"} and $self->changelog->{"releases"}[0]{"version"} ne "NEXT"
$self->changelog->{"releases"}[0]{"version"} $self->changelog->{"releases"}[0]{"version"} ne "NEXT"
Truth table0%0/3
A and B
A= $self->changelog->{"releases"}[0]{"version"}B= $self->changelog->{"releases"}[0]{"version"} ne "NEXT"
ABresult
0X0
100
111
43 and $self->changelog->{releases}[0]{version} ne 'NEXT' ) {
44 0 warn
45 "No change detected since last version, hope you know what you're doing.\n";
46 0 unshift $self->changelog->{releases}->@*, { version => 'NEXT', };
47 }
48  
49 0 my @time = localtime;
50  
51 0 $self->changelog->{releases}[0]{version} = $version;
52 0 $self->changelog->{releases}[0]{date} = sprintf "%d-%02d-%02d",
53 $time[5] + 1900, $time[4], $time[3];
54  
55 0 ▶ if( $self->changelog->{project}{with_stats} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->changelog->{"project"}{"with_stats"}) 0 0 0
56 push $self->changelog->{releases}[0]{changes}->@*, {
57 0 type => 'stats', desc => $self->stats
58 };
59 }
60  
61 0 my $change = $self->changelog;
62 0 Bless($change)->keys(
63 [ uniq qw/
64 project releases change_types
65 /, sort keys %$change
66 ] );
67 Bless( $change->{project} )->keys(
68 [ uniq qw/
69 name homepage
70 /, sort keys $change->{project}->%*
71 0 ] );
72  
73 0 for ( grep { ref } $change->{releases}->@* ) {
74 0 Bless($_)->keys( [ uniq qw/ version date changes /, sort keys %$_ ] );
75 }
76  
77 0 path( $self->source )->spew( YAML::Dump($change) );
78  
79 0 say "new version minted: $version";
80 }
81  
82 2 'end of App::Changelog::Command::Bump';
83  
84 __END__
↑ Summary Changelord/Command/Version.pm »