| 1 | package App::Changelord::Role::Render; | ||||||||||||||||||||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | 5 | $App::Changelord::Role::Render::VERSION = '0.0.2'; | |||||||||||||||||||||||||||
| 4 | 5 | ▶ | use v5.36.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use List::AllUtils qw/ pairmap partition_by /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | sub render_header ($self) { | ||||||||||||||||||||||||||
|
Subroutine
render_header: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my $output = "# Changelog"; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | my $name = $self->changelog->{project}{name}; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | my %links = (); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | if ( $self->changelog->{project}{homepage} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 1 | $name = "[$name][homepage]"; | |||||||||||||||||||||||||||
| 20 | 1 | $links{homepage} = $self->changelog->{project}{homepage}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | $output .= " for $name" if $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | if (%links) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 1 | $output .= "\n\n"; | |||||||||||||||||||||||||||
| 27 | 1 | $output .= $self->render_refs(%links); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | $output .= "\n\n"; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub render_refs ( $self, %links ) { | ||||||||||||||||||||||||||
|
Subroutine
render_refs: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 1 | my $output = ''; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | for my $ref ( sort keys %links ) { | |||||||||||||||||||||||||||
| 38 | 1 | $output .= " [$ref]: $links{$ref}\n"; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | return $output . "\n"; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub as_markdown ($self, $with_next = 1) { | ||||||||||||||||||||||||||
|
Subroutine
as_markdown: called CC=4 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 1 | my $changelog = $self->changelog; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | my $output = $self->render_header; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | my $n = 0; | |||||||||||||||||||||||||||
| 50 | $output .= join "\n", | ||||||||||||||||||||||||||||
| 51 | 0 | map { $self->render_release( $_, $n++ ) } | |||||||||||||||||||||||||||
| 52 | grep { | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $with_next ? 1 : ( $_->{version} && $_->{version} ne 'NEXT' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$_{"version"} and $$_{"version"} ne "NEXT"
MC/DC0%0/2
$$_{"version"} and $$_{"version"} ne "NEXT"
$$_{"version"}
$$_{"version"} ne "NEXT"
Truth table0%0/3
A and B
A= $$_{"version"}B= $$_{"version"} ne "NEXT"
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 1 | $changelog->{releases}->@*; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | return $output; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | ▶ | sub render_release ( $self, $release, $n = 0 ) { | ||||||||||||||||||||||||||
|
Subroutine
render_release: called CC=14 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # it's a string? Okay then! | ||||||||||||||||||||||||||||
| 63 | 4 | ▶ | return $release unless ref $release; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | my $version = $release->{version} || ( $n ? '???' : 'NEXT' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$release{'version'} || ($n ? '???' : 'NEXT')
MC/DC0%0/2
$$release{'version'} || ($n ? '???' : 'NEXT')
$$release{'version'}
($n ? '???' : 'NEXT')
Truth table66%2/3
A || B
A= $$release{'version'}B= ($n ? '???' : 'NEXT')
| |||||||||||||||||||||||||||||
| 66 | 3 | my $date = $release->{date}; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 3 | my $output = ''; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | $output .= "## $version"; | |||||||||||||||||||||||||||
| 71 | 3 | ▶ | $output .= ", $date" if $date; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | $output .= "\n"; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | ▶ | if ( $release->{changes} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | my @changes = | ||||||||||||||||||||||||||||
| 77 | 2 | ▶ | map { ref ? $_ : { desc => $_ } } $release->{changes}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 2 | my @keywords = map { $_->{keywords}->@* } $self->change_types->@*; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # find the generics | ||||||||||||||||||||||||||||
| 82 | my @generics = grep { | ||||||||||||||||||||||||||||
| 83 | 2 | my $type = $_->{type}; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 6 | my $res = !$type; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 6 | ▶ | if ( $type and not grep { $type eq $_ } @keywords ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type and not grep({$type eq $_;} @keywords)
MC/DC0%0/2
$type and not grep({$type eq $_;} @keywords)
$type
not grep({$type eq $_;} @keywords)
Truth table66%2/3
A and not(B)
A= $typeB= not grep({$type eq $_;} @keywords)
| |||||||||||||||||||||||||||||
| 88 | 0 | $res = 1; | |||||||||||||||||||||||||||
| 89 | 0 | warn "change type '$type' is not recognized\n"; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 6 | $res; | |||||||||||||||||||||||||||
| 92 | } @changes; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2 | ▶ | $output .= "\n" if @generics; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 2 | $output .= join '', map { $self->render_change($_) } @generics; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | my %keyword_mapping = map { | ||||||||||||||||||||||||||||
| 98 | 2 | my $title = $_->{title}; | |||||||||||||||||||||||||||
| 99 | 8 | map { $_ => $title } $_->{keywords}->@*; | |||||||||||||||||||||||||||
| 100 | } $self->change_types->@*; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 6 | ▶ | my %groups = partition_by { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 103 | 5 | ▶ | no warnings qw/ uninitialized /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 6 | ▶ | $keyword_mapping{ $_->{type} } || '' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 2 | @changes; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | for my $type ( $self->change_types->@* ) { | |||||||||||||||||||||||||||
| 109 | 8 | ▶ | my $c = $groups{ $type->{title} } or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 2 | $output .= "\n### $type->{title}\n\n"; | |||||||||||||||||||||||||||
| 111 | 2 | $output .= $self->render_change($_) for $c->@*; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | my $links = ''; | |||||||||||||||||||||||||||
| 116 | 3 | $output =~ s/(\n \[.*?\]: .*?)\n/$links .= $1;''/gem; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 3 | return $output . $links . "\n"; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 9 | ▶ | sub render_change ( $self, $change ) { | ||||||||||||||||||||||||||
|
Subroutine
render_change: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 9 | my $out = " * " . $change->{desc}; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 9 | my $link = ""; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 9 | ▶ | if ( $change->{ticket} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 5 | $out .= " [$change->{ticket}]"; | |||||||||||||||||||||||||||
| 128 | 5 | ▶ | if ( $self->changelog->{project}{ticket_url} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 4 | local $_ = $change->{ticket}; | |||||||||||||||||||||||||||
| 130 | 4 | eval $self->changelog->{project}{ticket_url}; | |||||||||||||||||||||||||||
| 131 | 4 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 4 | ▶ | if ($_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 3 | $link = " [$change->{ticket}]: $_"; | |||||||||||||||||||||||||||
| 134 | 3 | $out .= "\n\n$link"; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 9 | return $out . "\n"; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 5 | 1; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||