« CPAN/Maker/Bootstrapper/Role/Installer.pm
↑ Summary
CPAN/Maker/Bootstrapper/Role/LLM/Reviewer.pm »
| 1 | package CPAN::Maker::Bootstrapper::Role::LLM::ReleaseNotes; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use open ':std', ':encoding(UTF-8)'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Archive::Tar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use CLI::Simple::Constants qw(:booleans); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use CLI::Simple::Utils qw(slurp choose); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use CPAN::Maker::Bootstrapper::Constants qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Git::ReleaseDiffs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use IO::Scalar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Pod::Extract qw(extract_pod); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | ######################################################################## | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub cmd_release_notes { | ||||||||||||||||||||||||||
|
Subroutine
cmd_release_notes: not called CC=31 SCAR=69.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | ######################################################################## | ||||||||||||||||||||||||||||
| 24 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | eval { require Git::Raw; 1; } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | die "ERROR: Git::Raw must be installed to use this command.\n"; | |||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my ( $version, $api_key ) = $self->get_args; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( !$version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $version = eval { slurp('VERSION'); }; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | chomp $version; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | die "ERROR: usage cpan-maker-bootstrapper release-notes [api-key]\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | if !$version; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | die "ERROR: invalid version\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | if $version !~ /\A\d+[.]\d+[.]\d+\z/xsm; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $llm = $self->_check_llm($api_key); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # produce release artifacts from staged changes | ||||||||||||||||||||||||||||
| 48 | 0 | my $release = Git::ReleaseDiffs->new( release_version => $version ); | |||||||||||||||||||||||||||
| 49 | 0 | $release->write_diffs; | |||||||||||||||||||||||||||
| 50 | 0 | $release->write_list; | |||||||||||||||||||||||||||
| 51 | 0 | $release->write_tarball; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # verify artifacts exist | ||||||||||||||||||||||||||||
| 54 | 0 | my @file_list = map {"release-$version.$_"} qw(diffs lst tar.gz); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | foreach my $file (@file_list) { | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | die "ERROR: $file not found or empty!\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $file and -s $file
MC/DC0%0/2
-e $file and -s $file
-e $file
-s $file
Truth table0%0/3
A and B
A= -e $fileB= -s $file
| |||||||||||||||||||||||||||||
| 58 | if !-e $file || !-s $file; | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # truncate ChangeLog to current release section only (in memory) | ||||||||||||||||||||||||||||
| 62 | 0 | my $changelog_excerpt = _extract_changelog_section('ChangeLog'); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my @prompt; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $prompt_text = choose { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return slurp('.prompts/release-notes.prompt') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | if -f '.prompts/release-notes.prompt'; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | return 'Produce release notes in markdown format for this Perl CPAN distribution release.'; | |||||||||||||||||||||||||||
| 72 | 0 | }; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | push @prompt, $llm->text($prompt_text) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | if !$self->get_dryrun; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | push @prompt, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | $llm->document( | ||||||||||||||||||||||||||||
| 79 | data => slurp("release-$version.diffs"), | ||||||||||||||||||||||||||||
| 80 | title => 'Diffs' | ||||||||||||||||||||||||||||
| 81 | ) if !$self->get_dryrun; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | push @prompt, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | $llm->document( | ||||||||||||||||||||||||||||
| 85 | data => slurp("release-$version.lst"), | ||||||||||||||||||||||||||||
| 86 | title => 'Changed Files Listing' | ||||||||||||||||||||||||||||
| 87 | ) if !$self->get_dryrun; | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($changelog_excerpt) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | push @prompt, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | $llm->document( | ||||||||||||||||||||||||||||
| 92 | data => $changelog_excerpt, | ||||||||||||||||||||||||||||
| 93 | title => 'ChangeLog' | ||||||||||||||||||||||||||||
| 94 | ) if !$self->get_dryrun; | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # send updated files from tarball, stripping POD from Perl sources | ||||||||||||||||||||||||||||
| 98 | 0 | my $iter = Archive::Tar->iter( "release-$version.tar.gz", 1 ); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | my $file_limit = $self->get_max_diff_files; | |||||||||||||||||||||||||||
| 101 | 0 | my $file_count = 0; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | while ( my $file = $iter->() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | next if $file->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | next if $file->name =~ /[.](png|jpg|gif|gz|zip|tar)\z/xsmi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | die sprintf "ERROR: max number of files (%s) in diff listing has been reached. Use --max-diff-files to increase\n", | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file_limit and $file_count == $file_limit
MC/DC0%0/2
$file_limit and $file_count == $file_limit
$file_limit
$file_count == $file_limit
Truth table0%0/3
A and B
A= $file_limitB= $file_count == $file_limit
| |||||||||||||||||||||||||||||
| 109 | $file_limit | ||||||||||||||||||||||||||||
| 110 | if $file_limit && $file_count == $file_limit; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $file_content = $file->get_content; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | next if !defined $file_content || $file_content eq q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $file_content or $file_content eq ""
MC/DC0%0/2
not defined $file_content or $file_content eq ""
not defined $file_content
$file_content eq ""
Truth table0%0/3
not(A) or B
A= not defined $file_contentB= $file_content eq ""
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # strip POD from Perl sources to reduce token cost | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ( $file->name =~ /[.]p[ml][.]in\z/xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | $file_content = _strip_pod($file_content); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | push @prompt, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | $llm->document( | ||||||||||||||||||||||||||||
| 123 | data => $file_content, | ||||||||||||||||||||||||||||
| 124 | title => $file->name | ||||||||||||||||||||||||||||
| 125 | ) if !$self->get_dryrun; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | $file_count++; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return $SUCCESS | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | if $self->get_dryrun; | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | my $llm_rsp = $self->_submit_prompt( $llm, \@prompt ); | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my $content = $llm_rsp->content; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ( !$content || !$content->text ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$content and $content->text
MC/DC0%0/2
$content and $content->text
$content
$content->text
Truth table0%0/3
A and B
A= $contentB= $content->text
| |||||||||||||||||||||||||||||
| 138 | 0 | print {*STDERR} $llm_rsp->raw_content; | |||||||||||||||||||||||||||
| 139 | 0 | return $FAILURE; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( $llm_rsp->was_cutoff ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | warn "WARNING: response was truncated (hit max_tokens). Increase --max-tokens for a complete response.\n"; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | my $release_notes_dir = 'release-notes'; | |||||||||||||||||||||||||||
| 147 | 0 | my $release_notes_file = sprintf '%s/release-notes-%s.md', $release_notes_dir, $version; | |||||||||||||||||||||||||||
| 148 | 0 | my $release_notes_link = 'release-notes.md'; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | make_path($release_notes_dir); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | open my $fh, '>', $release_notes_file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | or die "ERROR: could not open $release_notes_file for writing\n$OS_ERROR"; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | print {$fh} $content->text; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | or warn "WARNING: could not close $release_notes_file: $OS_ERROR\n"; | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # create/update symlink release-notes.md -> release-notes/release-notes-VERSION.md | ||||||||||||||||||||||||||||
| 161 | 0 | ▶ | unlink $release_notes_link | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | if -l $release_notes_link; | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | symlink $release_notes_file, $release_notes_link | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | or warn "WARNING: could not create symlink $release_notes_link: $OS_ERROR\n"; | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | $self->_print_token_usage( $llm_rsp, 'Release Notes: Token Usage Report' ); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | ######################################################################## | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _extract_changelog_section { | ||||||||||||||||||||||||||
|
Subroutine
_extract_changelog_section: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 174 | ######################################################################## | ||||||||||||||||||||||||||||
| 175 | 0 | my ($changelog_file) = @_; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | return q{} if !-e $changelog_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | open my $fh, '<', $changelog_file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | or return q{}; | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | my $section = q{}; | |||||||||||||||||||||||||||
| 183 | 0 | my $blocks = 0; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $blocks++ if $line !~ /^\s/xsm && $line =~ /\S/xsm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $line =~ /^\s/msx and $line =~ /\S/msx
MC/DC0%0/2
not $line =~ /^\s/msx and $line =~ /\S/msx
not $line =~ /^\s/msx
$line =~ /\S/msx
Truth table0%0/3
not(A) and B
A= not $line =~ /^\s/msxB= $line =~ /\S/msx
| |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | last if $blocks > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | $section .= $line; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | close $fh; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | return $section; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | ######################################################################## | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub _strip_pod { | ||||||||||||||||||||||||||
|
Subroutine
_strip_pod: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 198 | ######################################################################## | ||||||||||||||||||||||||||||
| 199 | 0 | my (@args) = @_; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $content = @args > 1 && ref $args[0] ? $args[1] : $args[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@args > 1 and ref $args[0]
MC/DC0%0/2
@args > 1 and ref $args[0]
@args > 1
ref $args[0]
Truth table0%0/3
A and B
A= @args > 1B= ref $args[0]
| |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $obj = ref $content ? ${$content} : $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | my $fh = IO::Scalar->new( \$obj ); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | my ( undef, $code ) = extract_pod($fh); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | return $code // $content; | ||||||||||||||||||||||||||
|
Condition0%0/3
$code // $content
MC/DC0%0/2
$code // $content
$code
$content
Truth table0%0/3
A // B
A= $codeB= $content
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 2 | 1; | |||||||||||||||||||||||||||