lib/App/GHGen/Fixer.pm

filter: Statementstmt 99.2% 134 / 135 Branchbran 85.0% 51 / 60 Conditioncond 95.2% 40 / 42 MC/DCmcdc 91.3% 21 / 23 Subroutinesub 96.4% 27 / 28 Podpod 23.0% 3 / 13 totaltotal 91.6% 276 / 301 CC 58 SCAR 18.6
CC
58
Cov
95%
detect_and_create_cache_step
13.0
add_caching
10.1
update_actions
8.1
CRAP 6.4
« lib/App/GHGen/Analyzer.pm ↑ Summary lib/App/GHGen/Interactive.pm »
1 package App::GHGen::Fixer;
2  
3 67 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 67 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 67 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 67 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 67 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 67 ▶use YAML::XS qw(LoadFile DumpFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 66 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 66 our @EXPORT_OK = qw(
13 apply_fixes
14 can_auto_fix
15 fix_workflow
16 %ACTION_UPDATES
17 );
18  
19 66 our $VERSION = '0.13';
20  
21 66 Readonly my $DEFAULT_TIMEOUT_MINUTES => 60;
22  
23 =encoding utf-8
24  
25 =head1 PACKAGE DATA
26  
27 =head2 %ACTION_UPDATES
28  
29 Canonical mapping of outdated action strings to their current replacements.
30  
31 'old/action@vN' => 'old/action@vM'
32  
33 This hash is the B<single source of truth> for action version knowledge.
34 Both C<find_outdated_actions> (detection) and C<update_actions> (mutation)
35 consume it so that detecting an outdated action always implies the ability
36 to fix it - and vice versa.
37  
38 Premise 1: the Analyzer reports every key in this hash as "outdated".
39 Premise 2: the Fixer replaces every key with its value.
40 Conclusion: no detected issue is unfixable, and no fix targets an undetected issue.
41  
42 =cut
43  
44 66 our %ACTION_UPDATES = (
45 'actions/cache@v4' => 'actions/cache@v5',
46 'actions/cache@v3' => 'actions/cache@v5',
47 'actions/checkout@v5' => 'actions/checkout@v6',
48 'actions/checkout@v4' => 'actions/checkout@v6',
49 'actions/checkout@v2' => 'actions/checkout@v6',
50 'actions/checkout@v3' => 'actions/checkout@v6',
51 'actions/setup-node@v3' => 'actions/setup-node@v4',
52 'actions/setup-python@v4' => 'actions/setup-python@v5',
53 'actions/setup-go@v4' => 'actions/setup-go@v5',
54 );
55  
56 =head1 NAME
57  
58 App::GHGen::Fixer - Auto-fix workflow issues
59  
60 =head1 SYNOPSIS
61  
62 use App::GHGen::Fixer qw(apply_fixes);
63  
64 my $fixed = apply_fixes($workflow, \@issues);
65  
66 =head1 FUNCTIONS
67  
68 =head2 can_auto_fix($issue)
69  
70 Determine whether a given issue can be automatically resolved.
71  
72 =head3 Purpose
73  
74 Act as a capability gate before calling C<apply_fixes>. Returns true only
75 for the four issue types that the Fixer knows how to handle.
76  
77 =head3 Arguments
78  
79 =over 4
80  
81 =item C<$issue> (HashRef, required)
82  
83 An issue hash with at least a C<type> key. Recognised types are
84 C<performance>, C<security>, C<cost>, and C<maintenance>.
85  
86 =back
87  
88 =head3 Returns
89  
90 C<1> (true) when the issue type is auto-fixable; C<0> (false) otherwise.
91  
92 =head3 Side Effects
93  
94 None. Pure predicate.
95  
96 =head3 Usage Example
97  
98 if (can_auto_fix($issue)) {
99 apply_fixes($workflow, [$issue]);
100 }
101  
102 =head3 API SPECIFICATION
103  
104 =head4 Input
105  
106 { issue => { type => 'hashref', required => 1 } }
107  
108 =head4 Output
109  
110 { type => 'scalar' } # boolean: 1 or 0
111  
112 =head3 FORMAL SPECIFICATION
113  
114 can_auto_fix : Issue → 𝔹
115  
116 FixableTypes ≔ { performance, security, cost, maintenance }
117  
118 can_auto_fix(i) ≡ i.type ∈ FixableTypes
119  
120 =cut
121  
122 43 ▶sub can_auto_fix($issue) {
Subroutine can_auto_fix: called CC=2 SCAR=6.9
Pod documented
123 43 my %fixable = (
124 'performance' => 1, # Can add caching
125 'security' => 1, # Can update action versions and add permissions
126 'cost' => 1, # Can add concurrency, filters
127 'maintenance' => 1, # Can update runners
128 );
129  
130 43 ▶ return $fixable{$issue->{type}} // 0;
Condition100%2/2
$fixable{$issue->{"type"}} // 0
l!l
385
MC/DC100%1/1
$fixable{$issue->{"type"}} // 0
$fixable{$issue->{"type"}}
Truth table100%2/2
A
A= $fixable{$issue->{"type"}}
Aresult
11
00
131 }
132  
133 =head2 apply_fixes($workflow, $issues)
134  
135 Apply all auto-fixable changes from C<$issues> directly to C<$workflow>.
136  
137 =head3 Purpose
138  
139 Iterate over C<$issues>, skip issues that are not auto-fixable, and call
140 the appropriate internal fix routine for each fixable type/message
141 combination. Modifies C<$workflow> in place.
142  
143 =head3 Arguments
144  
145 =over 4
146  
147 =item C<$workflow> (HashRef, required)
148  
149 The parsed workflow hash to be mutated.
150  
151 =item C<$issues> (ArrayRef[HashRef], required)
152  
153 The issues to process. Each must have C<type> and C<message> keys.
154  
155 =back
156  
157 =head3 Returns
158  
159 The number of individual fix operations applied (an integer >= 0).
160  
161 =head3 Side Effects
162  
163 Modifies C<$workflow> in place.
164  
165 =head3 Usage Example
166  
167 my $n = apply_fixes($workflow, \@issues);
168 say "$n fix(es) applied.";
169  
170 =head3 API SPECIFICATION
171  
172 =head4 Input
173  
174 {
175 workflow => { type => 'hashref', required => 1 },
176 issues => { type => 'arrayref', required => 1 },
177 }
178  
179 =head4 Output
180  
181 { type => 'scalar' } # non-negative integer
182  
183 =head3 FORMAL SPECIFICATION
184  
185 apply_fixes : Workflow × seq Issue → ℕ
186  
187 applied ≔ ∑ { fix(w, i) ∣ i ∈ issues, can_auto_fix(i) }
188 result ≔ applied
189  
190 Mutates w by applying each fix in sequence.
191  
192 =cut
193  
194 # File-scoped dispatch table for apply_fixes.
195 # Premise: can_auto_fix guarantees type ∈ {performance,security,cost,maintenance}.
196 # Conclusion: we only need to match on (type, message pattern) — no further type
197 # validation is required inside the loop.
198 # Each rule: [ type_string, compiled_pattern, handler_sub ].
199 # Using anonymous delegates (not direct coderefs) so symbol-table mocks work.
200 my @_APPLY_RULES = (
201 4 ▶ [ 'performance', qr/caching/, sub($wf) { add_caching($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
202 0 ▶ [ 'security', qr/unpinned/, sub($wf) { fix_unpinned_actions($wf) } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
203 2 ▶ [ 'security', qr/permissions/, sub($wf) { add_permissions($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
204 2 ▶ [ 'maintenance', qr/outdated action/, sub($wf) { update_actions($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
205 8 ▶ [ 'cost', qr/concurrency/, sub($wf) { add_concurrency($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
206 3 ▶ [ 'cost', qr/triggers/, sub($wf) { add_trigger_filters($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
207 3 ▶ [ 'maintenance', qr/runner/, sub($wf) { update_runners($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
208 5 ▶ [ 'performance', qr/missing timeout-minutes/, sub($wf) { add_missing_timeout($wf) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
209 );
210  
211 25 ▶sub apply_fixes($workflow, $issues) {
Subroutine apply_fixes: called CC=6 SCAR=17.9
Pod documented
212 25 my $modified = 0;
213  
214 25 for my $issue (@$issues) {
215 # Guard: can_auto_fix is a complete predicate — if it returns false the
216 # type is guaranteed not in the dispatch table, so skip immediately.
217 33 ▶ next unless can_auto_fix($issue);
Branch: 1 branch
BranchTrueFalseTotal
unless can_auto_fix($issue) 3 30 33
218  
219 30 for my $rule (@_APPLY_RULES) {
220 161 my ($type, $pattern, $handler) = @$rule;
221 161 ▶ if ($issue->{type} eq $type && $issue->{message} =~ $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue->{"type"} eq $type and $issue->{"message"} =~ /$pattern/u) 27 134 161
Condition100%3/3
$issue->{"type"} eq $type and $issue->{"message"} =~ /$pattern/u
!ll&&!rl&&r
1151927
MC/DC100%2/2
$issue->{"type"} eq $type and $issue->{"message"} =~ /$pattern/u
$issue->{"type"} eq $type $issue->{"message"} =~ /$pattern/u
Truth table100%3/3
A and B
A= $issue->{"type"} eq $typeB= $issue->{"message"} =~ /$pattern/u
ABresult
0X0
100
111
222 27 $modified += $handler->($workflow);
223 27 last; # first-match-wins; one issue maps to exactly one fix
224 }
225 }
226 }
227  
228 25 return $modified;
229 }
230  
231 =head2 fix_workflow($file, $issues)
232  
233 Load a workflow YAML file, apply fixes, and write it back to disk.
234  
235 =head3 Purpose
236  
237 Persist the results of C<apply_fixes> by reading the workflow from C<$file>
238 with C<YAML::XS::LoadFile>, calling C<apply_fixes>, and rewriting the file
239 with C<YAML::XS::DumpFile> when at least one fix was applied.
240  
241 =head3 Arguments
242  
243 =over 4
244  
245 =item C<$file> (Str, required)
246  
247 Path to a YAML workflow file. Passed directly to C<YAML::XS::LoadFile>.
248  
249 =item C<$issues> (ArrayRef[HashRef], required)
250  
251 Issues to fix, each with C<type> and C<message> keys.
252  
253 =back
254  
255 =head3 Returns
256  
257 The number of fixes applied (an integer >= 0). The file is only rewritten
258 when the count is greater than zero.
259  
260 =head3 Side Effects
261  
262 Reads C<$file> from disk; rewrites C<$file> in place when fixes are applied.
263  
264 =head3 Usage Example
265  
266 my $n = fix_workflow('.github/workflows/ci.yml', \@issues);
267 say "$n fix(es) written to ci.yml.";
268  
269 =head3 API SPECIFICATION
270  
271 =head4 Input
272  
273 {
274 file => { type => 'scalar', required => 1 },
275 issues => { type => 'arrayref', required => 1 },
276 }
277  
278 =head4 Output
279  
280 { type => 'scalar' } # non-negative integer
281  
282 =head3 FORMAL SPECIFICATION
283  
284 fix_workflow : Path × seq Issue → ℕ
285  
286 w ≔ LoadFile(file)
287 fixes ≔ apply_fixes(w, issues)
288 fixes > 0 → DumpFile(file, w)
289  
290 result ≔ fixes
291  
292 =cut
293  
294 5 ▶sub fix_workflow($file, $issues) {
Subroutine fix_workflow: called CC=2 SCAR=6.9
Pod documented
295 5 my $workflow = LoadFile($file);
296 5 my $fixes = apply_fixes($workflow, $issues);
297  
298 5 ▶ if ($fixes > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixes > 0) 3 2 5
299 3 DumpFile($file, $workflow);
300 }
301  
302 5 return $fixes;
303 }
304  
305 # Fix implementations
306  
307 11 ▶sub add_caching($workflow) {
Subroutine add_caching: called CC=10 SCAR=23.1
Pod undocumented
308 11 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 11 0 11
309 11 my $modified = 0;
310  
311 11 for my $job (values %$jobs) {
312 11 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 11 0 11
313  
314 # Check if already has caching
315 11 ▶ my $has_cache = grep { $_->{uses} && $_->{uses} =~ /actions\/cache/ } @$steps;
Condition100%3/3
$_->{'uses'} && $_->{'uses'} =~ m[actions/cache]u
!ll&&!rl&&r
15113
MC/DC100%2/2
$_->{'uses'} && $_->{'uses'} =~ m[actions/cache]u
$_->{'uses'} $_->{'uses'} =~ m[actions/cache]u
Truth table100%3/3
A && B
A= $_->{'uses'}B= $_->{'uses'} =~ m[actions/cache]u
ABresult
0X0
100
111
316 11 ▶ next if $has_cache;
Branch: 1 branch
BranchTrueFalseTotal
if $has_cache 3 8 11
317  
318 # Detect project type and add appropriate cache
319 8 my $cache_step = detect_and_create_cache_step($steps);
320 8 ▶ next unless $cache_step;
Branch: 1 branch
BranchTrueFalseTotal
unless $cache_step 2 6 8
321  
322 # Insert cache step after checkout
323 6 my $insert_at = 0;
324 6 for my $i (0 .. $#$steps) {
325 8 ▶ if ($steps->[$i]->{uses} && $steps->[$i]->{uses} =~ /actions\/checkout/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($steps->[$i]{"uses"} and $steps->[$i]{"uses"} =~ m[actions/checkout]u) 5 3 8
Condition66%2/3
$steps->[$i]{"uses"} and $steps->[$i]{"uses"} =~ m[actions/checkout]u
!ll&&!rl&&r
305
MC/DC50%1/2
$steps->[$i]{"uses"} and $steps->[$i]{"uses"} =~ m[actions/checkout]u
$steps->[$i]{"uses"} $steps->[$i]{"uses"} =~ m[actions/checkout]u
Truth table66%2/3
A and B
A= $steps->[$i]{"uses"}B= $steps->[$i]{"uses"} =~ m[actions/checkout]u
ABresult
0X0
100
111
326 5 $insert_at = $i + 1;
327 5 last;
328 }
329 }
330  
331 6 splice @$steps, $insert_at, 0, $cache_step;
332 6 $modified++;
333 }
334  
335 11 return $modified;
336 }
337  
338 17 ▶sub detect_and_create_cache_step($steps) {
Subroutine detect_and_create_cache_step: called CC=13 SCAR=25.6
Pod undocumented
339 # Detect project type from steps
340 17 for my $step (@$steps) {
341 25 ▶ my $run = $step->{run} // '';
Condition100%2/2
$step->{"run"} // ""
l!l
1411
MC/DC100%1/1
$step->{"run"} // ""
$step->{"run"}
Truth table100%2/2
A
A= $step->{"run"}
Aresult
11
00
342  
343 # Node.js
344 25 ▶ if ($run =~ /npm (?:install|ci)/ || ($step->{uses} && $step->{uses} =~ /setup-node/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run =~ /npm (?:install|ci)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-node/u) 8 17 25
Condition100%6/6
$run =~ /npm (?:install|ci)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-node/u
l!l&&r!l&&!r
6217
$step->{"uses"} and $step->{"uses"} =~ /setup-node/u
!ll&&!rl&&r
892
MC/DC100%3/3
$run =~ /npm (?:install|ci)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-node/u
$run =~ /npm (?:install|ci)/u $step->{"uses"} $step->{"uses"} =~ /setup-node/u
Truth table100%4/4
A or B and C
A= $run =~ /npm (?:install|ci)/uB= $step->{"uses"}C= $step->{"uses"} =~ /setup-node/u
ABCresult
1XX1
0111
00X0
0100
345 return {
346 8 name => 'Cache dependencies',
347 uses => 'actions/cache@v5',
348 with => {
349 path => '~/.npm',
350 key => '${{ runner.os }}-node-${{ hashFiles(\'**/package-lock.json\') }}',
351 'restore-keys' => '${{ runner.os }}-node-',
352 },
353 };
354 }
355  
356 # Python
357 17 ▶ if ($run =~ /pip install/ || ($step->{uses} && $step->{uses} =~ /setup-python/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run =~ /pip install/u or $step->{"uses"} and $step->{"uses"} =~ /setup-python/u) 2 15 17
Condition100%6/6
$run =~ /pip install/u or $step->{"uses"} and $step->{"uses"} =~ /setup-python/u
l!l&&r!l&&!r
1115
$step->{"uses"} and $step->{"uses"} =~ /setup-python/u
!ll&&!rl&&r
781
MC/DC100%3/3
$run =~ /pip install/u or $step->{"uses"} and $step->{"uses"} =~ /setup-python/u
$run =~ /pip install/u $step->{"uses"} $step->{"uses"} =~ /setup-python/u
Truth table100%4/4
A or B and C
A= $run =~ /pip install/uB= $step->{"uses"}C= $step->{"uses"} =~ /setup-python/u
ABCresult
1XX1
0111
00X0
0100
358 return {
359 2 name => 'Cache pip packages',
360 uses => 'actions/cache@v5',
361 with => {
362 path => '~/.cache/pip',
363 key => '${{ runner.os }}-pip-${{ hashFiles(\'**/requirements.txt\') }}',
364 'restore-keys' => '${{ runner.os }}-pip-',
365 },
366 };
367 }
368  
369 # Rust
370 15 ▶ if ($run =~ /cargo (?:build|test)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run =~ /cargo (?:build|test)/u) 1 14 15
371 return {
372 1 name => 'Cache cargo',
373 uses => 'actions/cache@v5',
374 with => {
375 path => "~/.cargo/bin/\n~/.cargo/registry/index/\n~/.cargo/registry/cache/\n~/.cargo/git/db/\ntarget/",
376 key => '${{ runner.os }}-cargo-${{ hashFiles(\'**/Cargo.lock\') }}',
377 },
378 };
379 }
380  
381 # Go
382 14 ▶ if ($run =~ /go (?:build|test)/ || ($step->{uses} && $step->{uses} =~ /setup-go/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run =~ /go (?:build|test)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-go/u) 2 12 14
Condition100%6/6
$run =~ /go (?:build|test)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-go/u
l!l&&r!l&&!r
1112
$step->{"uses"} and $step->{"uses"} =~ /setup-go/u
!ll&&!rl&&r
571
MC/DC100%3/3
$run =~ /go (?:build|test)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-go/u
$run =~ /go (?:build|test)/u $step->{"uses"} $step->{"uses"} =~ /setup-go/u
Truth table100%4/4
A or B and C
A= $run =~ /go (?:build|test)/uB= $step->{"uses"}C= $step->{"uses"} =~ /setup-go/u
ABCresult
1XX1
0111
00X0
0100
383 return {
384 2 name => 'Cache Go modules',
385 uses => 'actions/cache@v5',
386 with => {
387 path => '~/go/pkg/mod',
388 key => '${{ runner.os }}-go-${{ hashFiles(\'**/go.sum\') }}',
389 'restore-keys' => '${{ runner.os }}-go-',
390 },
391 };
392 }
393 }
394  
395 4 return undef;
396 }
397  
398 2 ▶sub fix_unpinned_actions($workflow) {
Subroutine fix_unpinned_actions: called CC=7 SCAR=19.7
Pod undocumented
399 2 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 2 0 2
400 2 my $modified = 0;
401  
402 2 for my $job (values %$jobs) {
403 2 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 2 0 2
404 2 for my $step (@$steps) {
405 6 ▶ next unless $step->{uses};
Branch: 1 branch
BranchTrueFalseTotal
unless $step->{"uses"} 0 6 6
406  
407 6 ▶ if ($step->{uses} =~ /^(.+?)\@(?:master|main)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step->{"uses"} =~ /^(.+?)\@(?:master|main)$/u) 4 2 6
408 4 my $action = $1;
409 # Map to appropriate version
410 4 my $version = get_latest_version($action);
411 4 $step->{uses} = "$action\@$version";
412 4 $modified++;
413 }
414 }
415 }
416  
417 2 return $modified;
418 }
419  
420 4 ▶sub add_permissions($workflow) {
Subroutine add_permissions: called CC=2 SCAR=6.9
Pod undocumented
421 4 ▶ return 0 if $workflow->{permissions};
Branch: 1 branch
BranchTrueFalseTotal
if $workflow->{"permissions"} 1 3 4
422  
423 3 $workflow->{permissions} = { contents => 'read' };
424 3 return 1;
425 }
426  
427 4 ▶sub update_actions($workflow) {
Subroutine update_actions: called CC=8 SCAR=20.9
Pod undocumented
428 4 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 4 0 4
429 4 my $modified = 0;
430  
431 # Premise: %ACTION_UPDATES is the canonical version table (defined above).
432 # Conclusion: this function and find_outdated_actions (Analyzer) are always in sync.
433 4 for my $job (values %$jobs) {
434 4 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 4 0 4
435 4 for my $step (@$steps) {
436 17 ▶ next unless $step->{uses};
Branch: 1 branch
BranchTrueFalseTotal
unless $step->{"uses"} 1 16 17
437 16 for my $old (keys %ACTION_UPDATES) {
438 144 ▶ if ($step->{uses} =~ /^\Q$old\E/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step->{"uses"} =~ /^\Q$old\E/u) 13 131 144
439 13 $step->{uses} = $ACTION_UPDATES{$old};
440 13 $modified++;
441 }
442 }
443 }
444 }
445  
446 4 return $modified;
447 }
448  
449 10 ▶sub add_concurrency($workflow) {
Subroutine add_concurrency: called CC=2 SCAR=6.9
Pod undocumented
450 10 ▶ return 0 if $workflow->{concurrency};
Branch: 1 branch
BranchTrueFalseTotal
if $workflow->{"concurrency"} 1 9 10
451  
452 $workflow->{concurrency} = {
453 9 group => '${{ github.workflow }}-${{ github.ref }}',
454 'cancel-in-progress' => 'true',
455 };
456 9 return 1;
457 }
458  
459 9 ▶sub add_trigger_filters($workflow) {
Subroutine add_trigger_filters: called CC=7 SCAR=19.5
Pod undocumented
460 9 ▶ my $on = $workflow->{on} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $on = $workflow->{"on"} or return 0 8 1 9
461 8 my $modified = 0;
462  
463 # If 'on' is just 'push', expand it
464 8 ▶ if (ref $on eq 'ARRAY' && grep { $_ eq 'push' } @$on) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $on eq 'ARRAY' and grep {$_ eq 'push';} @$on) { } 3 5 8
elsif (ref $on eq 'HASH' and $on->{'push'} and ref $on->{'push'} eq '') { } 1 5 6
Condition100%3/3
ref $on eq "ARRAY" and grep {$_ eq "push";} @$on
!ll&&!rl&&r
413
MC/DC100%2/2
ref $on eq "ARRAY" and grep {$_ eq "push";} @$on
ref $on eq "ARRAY" grep {$_ eq "push";} @$on
Truth table100%3/3
A and B
A= ref $on eq "ARRAY"B= grep {$_ eq "push";} @$on
ABresult
0X0
100
111
465 $workflow->{on} = {
466 3 push => {
467 branches => ['main', 'master'],
468 },
469 pull_request => {
470 branches => ['main', 'master'],
471 },
472 };
473 3 $modified++;
474 }
475 ▶ elsif (ref $on eq 'HASH' && $on->{push} && ref $on->{push} eq '') {
Condition83%5/6
ref $on eq "HASH" and $on->{"push"} and ref $on->{"push"} eq ""
!ll&&!rl&&r
131
ref $on eq "HASH" and $on->{"push"}
!ll&&!rl&&r
104
MC/DC66%2/3
ref $on eq "HASH" and $on->{"push"} and ref $on->{"push"} eq ""
ref $on eq "HASH" $on->{"push"} ref $on->{"push"} eq ""
Truth table75%3/4
A and B and C
A= ref $on eq "HASH"B= $on->{"push"}C= ref $on->{"push"} eq ""
ABCresult
0XX0
10X0
1100
1111
476 # 'push' with no filters
477 $on->{push} = {
478 1 branches => ['main', 'master'],
479 };
480 1 $modified++;
481 }
482  
483 8 return $modified;
484 }
485  
486 6 ▶sub add_missing_timeout($workflow) {
Subroutine add_missing_timeout: called CC=4 SCAR=13.9
Pod undocumented
487 6 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 6 0 6
488 6 my $modified = 0;
489  
490 6 for my $job_name (keys %$jobs) {
491 7 my $job = $jobs->{$job_name};
492  
493 # Skip if timeout already exists
494 7 ▶ next if exists $job->{'timeout-minutes'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $job->{"timeout-minutes"} 1 6 7
495  
496 # Insert default timeout
497 6 $job->{'timeout-minutes'} = $DEFAULT_TIMEOUT_MINUTES;
498 6 $modified++;
499 }
500  
501 6 return $modified;
502 }
503  
504 8 ▶sub update_runners($workflow) {
Subroutine update_runners: called CC=5 SCAR=16.1
Pod undocumented
505 8 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 8 0 8
506 8 my $modified = 0;
507  
508 8 my %runner_updates = (
509 'ubuntu-18.04' => 'ubuntu-latest',
510 'ubuntu-16.04' => 'ubuntu-latest',
511 'macos-10.15' => 'macos-latest',
512 'windows-2016' => 'windows-latest',
513 );
514  
515 8 for my $job (values %$jobs) {
516 8 ▶ my $runs_on = $job->{'runs-on'} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $runs_on = $job->{"runs-on"} or next 7 1 8
517  
518 7 ▶ if (exists $runner_updates{$runs_on}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $runner_updates{$runs_on}) 5 2 7
519 5 $job->{'runs-on'} = $runner_updates{$runs_on};
520 5 $modified++;
521 }
522 }
523  
524 8 return $modified;
525 }
526  
527 8 ▶sub get_latest_version($action) {
Subroutine get_latest_version: called CC=2 SCAR=6.9
Pod undocumented
528 8 my %versions = (
529 'actions/checkout' => 'v6',
530 'actions/cache' => 'v5',
531 'actions/setup-node' => 'v4',
532 'actions/setup-python' => 'v5',
533 'actions/setup-go' => 'v5',
534 'actions/upload-artifact' => 'v4',
535 'actions/download-artifact' => 'v4',
536 );
537  
538 8 ▶ return $versions{$action} // 'v4'; # Default fallback
Condition100%2/2
$versions{$action} // "v4"
l!l
53
MC/DC100%1/1
$versions{$action} // "v4"
$versions{$action}
Truth table100%2/2
A
A= $versions{$action}
Aresult
11
00
539 }
540  
541 =head1 AUTHOR
542  
543 Nigel Horne E<lt>njh@nigelhorne.comE<gt>
544  
545 L<https://github.com/nigelhorne>
546  
547 =head1 COPYRIGHT AND LICENSE
548  
549 Copyright 2025-2026 Nigel Horne.
550  
551 Usage is subject to license terms.
552  
553 The license terms of this software are as follows:
554  
555 =cut
556  
557 66 1;
« lib/App/GHGen/Analyzer.pm ↑ Summary lib/App/GHGen/Interactive.pm »