bin/ghgen

filter: Statementstmt 39.1% 108 / 276 Branchbran 29.4% 30 / 102 Conditioncond 10.3% 6 / 58 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 84.6% 22 / 26 Podpod n/a totaltotal 33.6% 166 / 493 CC 76 SCAR 57.8
CC
76
Cov
33%
cmd_analyze
805.2
auto_detect_with_prompt
156.0
cmd_generate
153.6
CRAP 324.6
↑ Summary lib/App/GHGen/PerlCustomizer.pm »
1 #!/usr/bin/env perl
2  
3 56 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 56 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 56 ▶use FindBin qw($RealBin);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 56 ▶use lib "$RealBin/../lib"; # prefer local lib/ over any installed version
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 56 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 56 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 56 ▶use Term::ANSIColor qw(colored);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 56 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 56 ▶use YAML::XS qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 56 ▶use App::GHGen;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 56 ▶use App::GHGen::Generator qw(generate_workflow list_workflow_types parse_os_list parse_version_list);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 56 ▶use App::GHGen::Analyzer qw(analyze_workflow find_workflows);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 56 ▶use App::GHGen::Detector qw(detect_project_type get_project_indicators);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 56 ▶use App::GHGen::Interactive qw(customize_workflow);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 56 ▶use App::GHGen::PerlCustomizer qw(generate_custom_perl_workflow);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 56 ▶use App::GHGen::Fixer qw(fix_workflow can_auto_fix);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 56 ▶use App::GHGen::CostEstimator qw(estimate_current_usage estimate_savings);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # One source of truth: App::GHGen carries the release version
28 56 our $VERSION = $App::GHGen::VERSION;
29  
30 56 my %opts = (
31 help => 0,
32 version => 0,
33 list => 0,
34 timeout => undef,
35 );
36  
37 GetOptions(
38 'help|h' => \$opts{help},
39 'version|v' => \$opts{version},
40 'type|t=s' => \$opts{type},
41 'output|o=s' => \$opts{output},
42 'list|l' => \$opts{list},
43 'interactive|i' => \$opts{interactive},
44 'auto|a' => \$opts{auto},
45 'customize|c' => \$opts{customize},
46 'fix|f' => \$opts{fix},
47 'estimate|e' => \$opts{estimate},
48 'timeout=i' => \$opts{timeout},
49 'os=s' => \$opts{os},
50 'versions=s' => \$opts{versions},
51 56 ▶) or pod2usage(2);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", \$opts{"help"}, "version|v", \$opts{"version"}, "type|t=s", \$opts{"type"}, "output|o=s", \$opts{"output"}, "list|l", \$opts{"list"}, "interactive|i", \$opts{"interactive"}, "auto|a", \$opts{"auto"}, "customize|c", \$opts{"customize"}, "fix|f", \$opts{"fix"}, "estimate|e", \$opts{"estimate"}, "timeout=i", \$opts{"timeout"}, "os=s", \$opts{"os"}, "versions=s", \$opts{"versions"}) or pod2usage(2) 56 0 56
52  
53 # Turn --os and --versions into validated lists. The parsers croak on bad
54 # input, so report that as a one-line error rather than a stack trace.
55 56 my ($os_list, $version_list);
56 56 ▶eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $os_list = parse_os_list($opts{"os"}) if defined $opts{"os"}; $version_list = parse_version_list($opts{"versions"}) if defined $opts{"versions"}; 1 } } or fail($@) 48 8 56
57 56 ▶ $os_list = parse_os_list($opts{os}) if defined $opts{os};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"os"} 13 43 56
58 51 ▶ $version_list = parse_version_list($opts{versions}) if defined $opts{versions};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"versions"} 27 24 51
59 48 1;
60 } or fail($@);
61  
62 48 ▶pod2usage(1) if $opts{help};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"help"} 0 48 48
63  
64 48 ▶if ($opts{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"version"}) 0 48 48
65 0 say "ghgen version $VERSION";
66 0 exit 0;
67 }
68  
69 48 ▶my $command = shift @ARGV // '';
Condition50%1/2
shift @ARGV // ""
l!l
480
MC/DC0%0/1
shift @ARGV // ""
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
70  
71 48 ▶if ($command eq 'generate') {
Branch: 2 branches
BranchTrueFalseTotal
if ($command eq 'generate') { } 47 1 48
elsif ($command eq 'analyze') { } 1 0 1
72 47 cmd_generate();
73 } elsif ($command eq 'analyze') {
74 1 cmd_analyze();
75 } else {
76 0 pod2usage(-message => "Unknown command: $command", -exitval => 1);
77 }
78  
79 # Print a croaked message as a coloured one-line error and exit non-zero.
80 8 ▶sub fail($error) {
Subroutine fail: called CC=1 SCAR=0.0
81 # Drop Carp's " at FILE line N." suffix; it means nothing to a CLI user
82 8 $error =~ s/\s+at \S+ line \d+\.?\s*\z//;
83 8 die colored(['red'], 'Error: '), "$error\n";
84 }
85  
86 47 ▶sub cmd_generate() {
Subroutine cmd_generate: called CC=27 SCAR=50.3
87 47 ▶ if ($opts{list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"list"}) 0 47 47
88 0 list_types();
89 0 return;
90 }
91  
92 47 my $type = $opts{type};
93 47 my $config;
94  
95 # Auto-detect if requested
96 47 ▶ if ($opts{auto} || (!$type && !$opts{interactive} && !$opts{customize})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"auto"} or not $type || $opts{"interactive"} || $opts{"customize"}) 0 47 47
Condition33%3/9
$opts{"auto"} or not $type || $opts{"interactive"} || $opts{"customize"}
l!l&&r!l&&!r
0047
$type || $opts{'interactive'} || $opts{'customize'}
l!l&&r!l&&!r
4700
$type or $opts{"interactive"}
l!l&&r!l&&!r
4700
MC/DC0%0/4
$opts{"auto"} or not $type || $opts{"interactive"} || $opts{"customize"}
$opts{"auto"} $type $opts{"interactive"} $opts{'customize'}
Truth table20%1/5
A or not(B or C || D)
A= $opts{"auto"}B= $typeC= $opts{"interactive"}D= $opts{'customize'}
ABCDresult
1XXX1
00001
01XX0
001X0
00010
97 0 $type = auto_detect_with_prompt();
98 0 ▶ return unless $type; # User cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
99 }
100  
101 # Interactive mode
102 47 ▶ if ($opts{interactive} && !$type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"interactive"} and not $type) 0 47 47
Condition33%1/3
$opts{"interactive"} and not $type
!ll&&!rl&&r
4700
MC/DC0%0/2
$opts{"interactive"} and not $type
$opts{"interactive"} not $type
Truth table33%1/3
A and not(B)
A= $opts{"interactive"}B= not $type
ABresult
0X0
100
111
103 0 $type = interactive_select_type();
104 }
105  
106 47 ▶ unless ($type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 0 47 47
107 0 die colored(['red'], "Error: ") .
108 'Please specify --type, use --auto, or use --interactive';
109 }
110  
111 # Customization mode
112 47 ▶ if ($opts{customize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"customize"}) 0 47 47
113 0 $config = customize_workflow($type);
114 }
115  
116 # Generate workflow with optional customization
117 47 my $yaml;
118 47 ▶ if ($config && $type eq 'perl') {
Branch: 2 branches
BranchTrueFalseTotal
if ($config and $type eq 'perl') { } 0 47 47
elsif ($type eq 'perl') { } 16 31 47
Condition33%1/3
$config and $type eq "perl"
!ll&&!rl&&r
4700
MC/DC0%0/2
$config and $type eq "perl"
$config $type eq "perl"
Truth table33%1/3
A and B
A= $configB= $type eq "perl"
ABresult
0X0
100
111
119 # Use customized Perl workflow
120 0 ▶ my @perl_versions = @{$config->{perl_versions} // ['5.40', '5.38', '5.36']};
Condition0%0/2
$config->{"perl_versions"} // ["5.40", "5.38", "5.36"]
l!l
00
MC/DC0%0/1
$config->{"perl_versions"} // ["5.40", "5.38", "5.36"]
$config->{"perl_versions"}
Truth table0%0/2
A
A= $config->{"perl_versions"}
Aresult
11
00
121 $yaml = generate_custom_perl_workflow({
122 min_perl_version => $perl_versions[0],
123 max_perl_version => $perl_versions[-1],
124 perl_versions => $version_list // \@perl_versions,
125 os => $os_list // $config->{os} // ['ubuntu-latest', 'macos-latest', 'windows-latest'],
126 enable_linter => $config->{enable_linter} // 1,
127 enable_linter_unused => $config->{enable_linter_unused} // 1,
128 enable_critic => $config->{enable_critic} // 1,
129 enable_coverage => $config->{enable_coverage} // 1,
130 timeout => $opts{timeout},
131 0 ▶ });
Condition0%0/15
$version_list // \@perl_versions
l!l
00
($os_list // $config->{"os"}) // ["ubuntu-latest", "macos-latest", "windows-latest"]
l!l
00
$os_list // $config->{"os"}
l!l&&r!l&&!r
000
$config->{"enable_linter"} // 1
l!l
00
$config->{"enable_linter_unused"} // 1
l!l
00
$config->{"enable_critic"} // 1
l!l
00
$config->{"enable_coverage"} // 1
l!l
00
MC/DC0%0/1
$version_list // \@perl_versions
$version_list
MC/DC0%0/2
($os_list // $config->{"os"}) // ["ubuntu-latest", "macos-latest", "windows-latest"]
$os_list $config->{"os"}
MC/DC0%0/1
$config->{"enable_linter"} // 1
$config->{"enable_linter"}
MC/DC0%0/1
$config->{"enable_linter_unused"} // 1
$config->{"enable_linter_unused"}
MC/DC0%0/1
$config->{"enable_critic"} // 1
$config->{"enable_critic"}
MC/DC0%0/1
$config->{"enable_coverage"} // 1
$config->{"enable_coverage"}
Truth table0%0/2
A
A= $version_list
Aresult
11
00
Truth table0%0/3
A // B
A= $os_listB= $config->{"os"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $config->{"enable_linter"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_linter_unused"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_critic"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_coverage"}
Aresult
11
00
132 } elsif ($type eq 'perl') {
133 $yaml = generate_custom_perl_workflow({
134 timeout => $opts{timeout},
135 16 ▶ ($os_list ? (os => $os_list) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$os_list ? : 8 8 16
$version_list ? : 3 13 16
136 ($version_list ? (perl_versions => $version_list) : ()),
137 });
138 } else {
139 31 $yaml = generate_workflow($type, { versions => $version_list });
140 }
141  
142 47 ▶ unless ($yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($yaml) 0 47 47
143 0 die colored(['red'], 'Error: '), "Unknown project type '$type'. Use --list to see options.";
144 }
145  
146 # Determine output file
147 47 my $output_file = $opts{output};
148 47 ▶ unless ($output_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output_file) 0 47 47
149 0 my $workflows_dir = path('.github/workflows');
150 0 ▶ $workflows_dir->mkpath unless $workflows_dir->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $workflows_dir->exists 0 0 0
151 0 $output_file = $workflows_dir->child("$type-ci.yml");
152 }
153  
154 # Write the workflow
155 47 path($output_file)->spew_utf8($yaml);
156  
157 44 say colored(['green'], "✓ ") . 'Generated workflow: ' . colored(['bold'], $output_file);
158 44 say '';
159 44 say colored(['cyan'], "Next steps:");
160 44 say " 1. Review the generated workflow";
161 44 say " 2. Customize it for your project";
162 44 say " 3. Commit and push to trigger the workflow";
163 44 say '';
164 44 say colored(['yellow'], "💡 Tip: ") . "Run 'ghgen analyze' to check for optimizations";
165 }
166  
167 1 ▶sub cmd_analyze() {
Subroutine cmd_analyze: called CC=33 SCAR=66.9
168 1 my @workflow_files = find_workflows();
169  
170 1 ▶ unless (@workflow_files) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@workflow_files) 0 1 1
171 0 die colored(['red'], 'Error: ') .
172 "No .github/workflows directory found\n" .
173 'Run this from the root of a repository with GitHub Actions.';
174 }
175  
176 1 say colored(['bold cyan'], "GitHub Actions Workflow Analyzer");
177 1 ▶ if ($opts{fix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fix"}) 0 1 1
178 0 say colored(['yellow'], '(Auto-fix mode enabled)');
179 }
180 1 ▶ if ($opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"estimate"}) 1 0 1
181 1 say colored(['cyan'], "(Cost estimation mode)");
182 }
183 1 say colored(['cyan'], "=" x 50);
184 1 say '';
185  
186 # Get cost estimate first if requested
187 1 my $current_usage;
188 1 ▶ if ($opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"estimate"}) 1 0 1
189 1 say colored(['bold'], "📊 Estimating current CI usage...");
190 1 say '';
191 1 $current_usage = estimate_current_usage(\@workflow_files);
192  
193 0 say colored(['bold'], "Current Monthly Usage:");
194 0 say " Total CI minutes: " . colored(['yellow'], $current_usage->{total_minutes});
195 0 say " Billable minutes: " . colored(['yellow'], $current_usage->{billable_minutes}) .
196 " (after 2,000 free tier)";
197 0 say " Estimated cost: " . colored(['yellow'], sprintf("\$%.2f", $current_usage->{monthly_cost}));
198 0 say '';
199  
200 0 ▶ if (@{$current_usage->{workflows}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$current_usage->{"workflows"};} > 1) 0 0 0
201 0 say colored(['bold'], "Per-Workflow Breakdown:");
202 0 for my $wf (sort { $b->{minutes_per_month} <=> $a->{minutes_per_month} }
203 0 @{$current_usage->{workflows}}) {
204 say sprintf(" %-40s %4d min/month (%3d runs × %4.1f min/run)",
205 $wf->{name},
206 $wf->{minutes_per_month},
207 $wf->{runs_per_month},
208 0 $wf->{minutes_per_run});
209 }
210 0 say '';
211 }
212 }
213  
214 0 my @all_issues;
215 0 my $total_workflows = 0;
216 0 my $total_fixes = 0;
217  
218 # Analyze each workflow file
219 0 for my $file (@workflow_files) {
220 0 $total_workflows++;
221 0 say colored(['bold'], "📄 Analyzing: ") . $file->basename;
222  
223 0 my $workflow;
224 0 eval { $workflow = LoadFile($file) };
225 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
226 0 say colored(['red'], " ✗ Failed to parse YAML: $@");
227 0 next;
228 }
229  
230 0 my @issues = analyze_workflow($workflow, $file->basename);
231  
232 0 ▶ if (@issues) {
Branch: 1 branch
BranchTrueFalseTotal
if (@issues) { } 0 0 0
233 # Filter to auto-fixable issues if in fix mode
234 0 ▶ my @fixable = $opts{fix} ? grep { can_auto_fix($_) } @issues : @issues;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'fix'} ? : 0 0 0
235  
236 0 ▶ if ($opts{fix} && @fixable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'fix'} and @fixable) { } 0 0 0
Condition0%0/3
$opts{"fix"} and @fixable
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"fix"} and @fixable
$opts{"fix"} @fixable
Truth table0%0/3
A and B
A= $opts{"fix"}B= @fixable
ABresult
0X0
100
111
237 0 say " " . colored(['yellow'], "âš™ ") . "Applying " . scalar(@fixable) . " fix(es)...";
238  
239 0 my $fixes = fix_workflow($file, \@fixable);
240 0 $total_fixes += $fixes;
241  
242 0 ▶ if ($fixes > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixes > 0) { } 0 0 0
243 0 say " " . colored(['green'], "✓ ") . "Applied $fixes fix(es)";
244 } else {
245 0 say " " . colored(['yellow'], "âš  ") . "Could not apply some fixes automatically";
246 }
247 } else {
248 # Just report issues
249 0 for my $issue (@issues) {
250 0 ▶ my $icon = can_auto_fix($issue) ? "âš " : "ℹ";
Branch: 1 branch
BranchTrueFalseTotal
can_auto_fix($issue) ? : 0 0 0
251 0 say " " . colored(['yellow'], "$icon ") . $issue->{message};
252 0 ▶ if ($issue->{fix} && !$opts{fix} && !$opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue->{"fix"} and not $opts{"fix"} and not $opts{"estimate"}) 0 0 0
Condition0%0/6
$issue->{"fix"} and not $opts{"fix"} and not $opts{"estimate"}
!ll&&!rl&&r
000
$issue->{"fix"} and not $opts{"fix"}
!ll&&!rl&&r
000
MC/DC0%0/3
$issue->{"fix"} and not $opts{"fix"} and not $opts{"estimate"}
$issue->{"fix"} not $opts{"fix"} not $opts{"estimate"}
Truth table0%0/4
A and not(B) and not(C)
A= $issue->{"fix"}B= not $opts{"fix"}C= not $opts{"estimate"}
ABCresult
0XX0
10X0
1100
1111
253 0 say colored(['cyan'], " 💡 Fix:");
254 0 for my $line (split /\n/, $issue->{fix}) {
255 0 say " " . $line;
256 }
257 }
258 }
259 }
260  
261 0 push @all_issues, map { { file => $file->basename, %$_ } } @issues;
262 } else {
263 0 say " " . colored(['green'], "✓ No issues found");
264 }
265 0 say '';
266 }
267  
268 # Summary
269 0 say colored(['bold cyan'], "=" x 50);
270 0 say colored(['bold'], "Summary:");
271 0 say " Workflows analyzed: $total_workflows";
272 0 say " Total issues found: " . scalar(@all_issues);
273  
274 0 ▶ if ($opts{fix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fix"}) 0 0 0
275 0 say " Fixes applied: " . colored(['green'], $total_fixes);
276 }
277  
278 # Cost savings estimate
279 0 ▶ if ($opts{estimate} && @all_issues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"estimate"} and @all_issues) 0 0 0
Condition0%0/3
$opts{"estimate"} and @all_issues
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"estimate"} and @all_issues
$opts{"estimate"} @all_issues
Truth table0%0/3
A and B
A= $opts{"estimate"}B= @all_issues
ABresult
0X0
100
111
280 0 say '';
281 0 my $savings = estimate_savings(\@all_issues, \@workflow_files);
282  
283 0 ▶ if ($savings->{minutes} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($savings->{"minutes"} > 0) 0 0 0
284 0 say colored(['bold'], "💰 Potential Savings:");
285 0 say ' With recommended changes: ' . colored(['green'], ($current_usage->{total_minutes} - $savings->{minutes})) .
286 " CI minutes/month";
287 0 say " Reduction: " . colored(['green'], "-$savings->{minutes} minutes") .
288 " (" . colored(['green'], "$savings->{percentage}%") . ")";
289 0 say " Cost savings: " . colored(['green'], "\$$savings->{cost}/month") .
290 " (for private repos)";
291  
292 0 ▶ if (@{$savings->{details}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$savings->{"details"};}) 0 0 0
293 0 say '';
294 0 say " Breakdown:";
295 0 for my $detail (@{$savings->{details}}) {
296 0 say " • $detail->{description}: ~$detail->{minutes} min/month";
297 }
298 }
299 }
300 }
301  
302 0 ▶ if (@all_issues && !$opts{fix}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@all_issues and not $opts{"fix"}) 0 0 0
Condition0%0/3
@all_issues and not $opts{"fix"}
!ll&&!rl&&r
000
MC/DC0%0/2
@all_issues and not $opts{"fix"}
@all_issues not $opts{"fix"}
Truth table0%0/3
A and not(B)
A= @all_issuesB= not $opts{"fix"}
ABresult
0X0
100
111
303 0 say '';
304 0 say colored(['bold yellow'], "Recommendations:");
305 0 my %by_type;
306 0 push @{$by_type{$_->{type}}}, $_ for @all_issues;
307  
308 0 for my $type (sort keys %by_type) {
309 0 my $count = scalar @{$by_type{$type}};
310 0 my $fixable = grep { can_auto_fix($_) } @{$by_type{$type}};
311 0 ▶ my $suffix = $fixable > 0 ? " ($fixable auto-fixable)" : '';
Branch: 1 branch
BranchTrueFalseTotal
$fixable > 0 ? : 0 0 0
312 0 say " • " . colored(['yellow'], "$type") . ": $count workflow(s) affected$suffix";
313 }
314  
315 0 say '';
316 0 say colored(['cyan'], "💡 Tip: ") . "Run " . colored(['bold'], "ghgen analyze --fix") .
317 " to automatically apply fixes";
318  
319 0 ▶ if (!$opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"estimate"}) 0 0 0
320 0 say colored(['cyan'], "💡 Tip: ") . "Run " . colored(['bold'], "ghgen analyze --estimate") .
321 " to see potential cost savings";
322 }
323 }
324  
325 0 ▶ exit(@all_issues ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
@all_issues ? : 0 0 0
326 }
327  
328 0 ▶sub list_types() {
Subroutine list_types: not called CC=2 SCAR=17.9
329 0 say colored(['bold cyan'], "Available workflow templates:");
330 0 say '';
331  
332 0 my %types = list_workflow_types();
333  
334 0 for my $type (sort keys %types) {
335 0 say " " . colored(['green'], sprintf("%-10s", $type)) . " - $types{$type}";
336 }
337  
338 0 say '';
339 0 say "Usage: ghgen generate --type=<type> [--output=<file>]";
340 0 say " or: ghgen generate --interactive";
341 }
342  
343 0 ▶sub interactive_select_type() {
Subroutine interactive_select_type: not called CC=5 SCAR=34.0
344 0 say colored(['bold cyan'], "GitHub Actions Workflow Generator");
345 0 say colored(['cyan'], "=" x 50);
346 0 say '';
347 0 say "Select a project type:";
348 0 say '';
349  
350 0 my @types = qw(node python rust go ruby perl java cpp php docker static);
351 0 my %descriptions = (
352 node => 'Node.js/npm',
353 python => 'Python',
354 rust => 'Rust',
355 go => 'Go',
356 ruby => 'Ruby',
357 perl => 'Perl',
358 java => 'Java (Maven/Gradle)',
359 cpp => 'C++ (CMake)',
360 php => 'PHP (Composer)',
361 docker => 'Docker',
362 static => 'Static site (GitHub Pages)',
363 );
364  
365 0 for my $i (0..$#types) {
366 0 say " " . colored(['green'], $i + 1) . ". $descriptions{$types[$i]}";
367 }
368  
369 0 say '';
370 0 print "Enter number (1-" . scalar(@types) . "): ";
371 0 chomp(my $choice = <STDIN>);
372  
373 0 ▶ if ($choice =~ /^\d+$/ && $choice >= 1 && $choice <= @types) {
Branch: 1 branch
BranchTrueFalseTotal
if ($choice =~ /^\d+$/u and $choice >= 1 and $choice <= @types) 0 0 0
Condition0%0/6
$choice =~ /^\d+$/u and $choice >= 1 and $choice <= @types
!ll&&!rl&&r
000
$choice =~ /^\d+$/u and $choice >= 1
!ll&&!rl&&r
000
MC/DC0%0/3
$choice =~ /^\d+$/u and $choice >= 1 and $choice <= @types
$choice =~ /^\d+$/u $choice >= 1 $choice <= @types
Truth table0%0/4
A and B and C
A= $choice =~ /^\d+$/uB= $choice >= 1C= $choice <= @types
ABCresult
0XX0
10X0
1100
1111
374 0 return $types[$choice - 1];
375 }
376  
377 0 die colored(['red'], 'Invalid choice');
378 }
379  
380 0 ▶sub auto_detect_with_prompt() {
Subroutine auto_detect_with_prompt: not called CC=12 SCAR=50.5
381 0 say colored(['bold cyan'], "Auto-detecting project type...");
382 0 say '';
383  
384 0 my @detections = detect_project_type();
385  
386 0 ▶ unless (@detections) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@detections) 0 0 0
387 0 say colored(['yellow'], "âš  ") . "Could not auto-detect project type.";
388 0 say '';
389 0 say "Try one of these options:";
390 0 say " • " . colored(['cyan'], "ghgen generate --list") . " - see all available types";
391 0 say " • " . colored(['cyan'], "ghgen generate --interactive") . " - choose interactively";
392 0 say " • " . colored(['cyan'], "ghgen generate --type=<type>") . " - specify type directly";
393 0 return undef;
394 }
395  
396 # Show top detection
397 0 my $top = $detections[0];
398 0 ▶ if(!defined($top->{type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $top->{"type"}) 0 0 0
399 0 die "Cound't autodetect the project type";
400 }
401  
402 0 say colored(['green'], "✓ ") . 'Detected project type: ' . colored(['bold'], uc($top->{type}));
403  
404 # Show evidence
405 0 my $indicators = get_project_indicators($top->{type});
406 0 my @found_indicators;
407 0 for my $indicator (@$indicators) {
408 # Simple file check (not glob patterns)
409 0 ▶ if ($indicator !~ /[\*\?]/ && path($indicator)->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $indicator =~ /[\*\?]/u and path($indicator)->exists) 0 0 0
Condition0%0/3
not $indicator =~ /[\*\?]/u and path($indicator)->exists
!ll&&!rl&&r
000
MC/DC0%0/2
not $indicator =~ /[\*\?]/u and path($indicator)->exists
not $indicator =~ /[\*\?]/u path($indicator)->exists
Truth table0%0/3
not(A) and B
A= not $indicator =~ /[\*\?]/uB= path($indicator)->exists
ABresult
0X0
100
111
410 0 push @found_indicators, $indicator;
411 0 ▶ last if @found_indicators >= 3; # Show max 3
Branch: 1 branch
BranchTrueFalseTotal
if @found_indicators >= 3 0 0 0
412 }
413 }
414  
415 0 ▶ if (@found_indicators) {
Branch: 1 branch
BranchTrueFalseTotal
if (@found_indicators) 0 0 0
416 0 say colored(['cyan'], " Evidence: ") . join(', ', @found_indicators);
417 }
418 0 say '';
419  
420 # Show alternatives if any
421 0 ▶ if (@detections > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@detections > 1) 0 0 0
422 0 say colored(['yellow'], "Other possibilities:");
423 0 for my $i (1 .. min(2, $#detections)) {
424 0 say " • $detections[$i]->{type} (confidence: " . int($detections[$i]->{score} / $top->{score} * 100) . "%)";
425 }
426 0 say '';
427 }
428  
429 # Prompt for confirmation
430 0 print "Generate " . colored(['bold'], uc($top->{type})) . " workflow? [Y/n]: ";
431 0 chomp(my $response = <STDIN>);
432  
433 0 ▶ if ($response =~ /^(?:y(?:es)?)?$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response =~ /^(?:y(?:es)?)?$/iu) { } 0 0 0
elsif ($response =~ /^n(?:o)?$/iu) { } 0 0 0
434 0 return $top->{type};
435 } elsif ($response =~ /^n(?:o)?$/i) {
436 0 say '';
437 0 say "Cancelled. Use " . colored(['cyan'], "--interactive") . " to choose manually.";
438 0 return undef;
439 } else {
440 0 say colored(['red'], "Invalid response. Cancelled.");
441 0 return undef;
442 }
443 }
444  
445 0 ▶sub min($a, $b) {
Subroutine min: not called CC=2 SCAR=17.9
446 0 ▶ return $a < $b ? $a : $b;
Branch: 1 branch
BranchTrueFalseTotal
$a < $b ? : 0 0 0
447 }
448  
449 __END__
↑ Summary lib/App/GHGen/PerlCustomizer.pm »