Skip to content

Commit defd960

Browse files
committed
callouts and other improvements
1 parent 25d0a5a commit defd960

File tree

10 files changed

+884
-421
lines changed

10 files changed

+884
-421
lines changed

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ linters:
122122
struct-method: false
123123

124124
gocognit:
125-
min-complexity: 55
125+
min-complexity: 65
126126

127127
gocritic:
128128
enable-all: true
@@ -146,7 +146,7 @@ linters:
146146
maintidx:
147147
# Maintainability Index threshold (default: 20)
148148
# ExtrapolateFromSamples is a straightforward calculation with clear linear logic
149-
under: 18
149+
under: 16
150150

151151
godot:
152152
scope: toplevel
@@ -182,7 +182,7 @@ linters:
182182
- name: cyclomatic
183183
disabled: true # prefer maintidx
184184
- name: function-length
185-
arguments: [150, 250]
185+
arguments: [150, 300]
186186
- name: line-length-limit
187187
arguments: [150]
188188
- name: nested-structs

cmd/prcost/main.go

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log/slog"
1212
"os"
1313
"os/exec"
14+
"strconv"
1415
"strings"
1516
"time"
1617

@@ -101,12 +102,10 @@ func main() {
101102
"salary", cfg.AnnualSalary,
102103
"benefits_multiplier", cfg.BenefitsMultiplier,
103104
"event_minutes", *eventMinutes,
104-
"delivery_delay_factor", cfg.DeliveryDelayFactor,
105-
"coordination_factor", cfg.CoordinationFactor)
105+
"delivery_delay_factor", cfg.DeliveryDelayFactor)
106106

107107
// Retrieve GitHub token from gh CLI
108108
ctx := context.Background()
109-
slog.Info("Retrieving GitHub authentication token")
110109
token, err := authToken(ctx)
111110
if err != nil {
112111
slog.Error("Failed to get GitHub token", "error", err)
@@ -119,11 +118,6 @@ func main() {
119118
// Org/Repo sampling mode
120119
if *repo != "" {
121120
// Single repository mode
122-
slog.Info("Starting repository analysis",
123-
"org", *org,
124-
"repo", *repo,
125-
"samples", *samples,
126-
"days", *days)
127121

128122
err := analyzeRepository(ctx, *org, *repo, *samples, *days, cfg, token, *dataSource)
129123
if err != nil {
@@ -334,19 +328,16 @@ func printDelayCosts(breakdown *cost.Breakdown, formatCurrency func(float64) str
334328
cappedSuffix)
335329
}
336330

337-
if breakdown.DelayCostDetail.CoordinationHours > 0 {
338-
cappedSuffix := ""
339-
if breakdown.DelayCapped {
340-
cappedSuffix = " (capped)"
341-
}
342-
fmt.Printf(" Coordination %12s %s%s\n",
343-
formatCurrency(breakdown.DelayCostDetail.CoordinationCost),
344-
formatTimeUnit(breakdown.DelayCostDetail.CoordinationHours),
345-
cappedSuffix)
346-
}
331+
// Calculate merge delay subtotal (all non-future delay costs)
332+
mergeDelayCost := breakdown.DelayCostDetail.DeliveryDelayCost +
333+
breakdown.DelayCostDetail.CodeChurnCost +
334+
breakdown.DelayCostDetail.AutomatedUpdatesCost +
335+
breakdown.DelayCostDetail.PRTrackingCost
336+
mergeDelayHours := breakdown.DelayCostDetail.DeliveryDelayHours +
337+
breakdown.DelayCostDetail.CodeChurnHours +
338+
breakdown.DelayCostDetail.AutomatedUpdatesHours +
339+
breakdown.DelayCostDetail.PRTrackingHours
347340

348-
mergeDelayCost := breakdown.DelayCostDetail.DeliveryDelayCost + breakdown.DelayCostDetail.CoordinationCost
349-
mergeDelayHours := breakdown.DelayCostDetail.DeliveryDelayHours + breakdown.DelayCostDetail.CoordinationHours
350341
fmt.Println(" ────────────")
351342
pct := (mergeDelayCost / breakdown.TotalCost) * 100
352343
fmt.Printf(" Subtotal %12s %s (%.1f%%)\n",
@@ -435,6 +426,43 @@ func formatWithCommas(amount float64) string {
435426
return string(result) + "." + decPart
436427
}
437428

429+
// formatLOC formats lines of code in kilo format with appropriate precision and commas for large values.
430+
func formatLOC(kloc float64) string {
431+
// For values >= 100k, add commas (e.g., "1,517k" instead of "1517k")
432+
if kloc >= 100.0 {
433+
intPart := int(kloc)
434+
fracPart := kloc - float64(intPart)
435+
436+
// Format integer part with commas
437+
intStr := strconv.Itoa(intPart)
438+
var result []rune
439+
for i, r := range intStr {
440+
if i > 0 && (len(intStr)-i)%3 == 0 {
441+
result = append(result, ',')
442+
}
443+
result = append(result, r)
444+
}
445+
446+
// Add fractional part if significant
447+
if kloc < 1000.0 && fracPart >= 0.05 {
448+
return fmt.Sprintf("%s.%dk", string(result), int(fracPart*10))
449+
}
450+
return string(result) + "k"
451+
}
452+
453+
// For values < 100k, use existing precision logic
454+
if kloc < 0.1 && kloc > 0 {
455+
return fmt.Sprintf("%.2fk", kloc)
456+
}
457+
if kloc < 1.0 {
458+
return fmt.Sprintf("%.1fk", kloc)
459+
}
460+
if kloc < 10.0 {
461+
return fmt.Sprintf("%.1fk", kloc)
462+
}
463+
return fmt.Sprintf("%.0fk", kloc)
464+
}
465+
438466
// efficiencyGrade returns a letter grade and message based on efficiency percentage (MIT scale).
439467
func efficiencyGrade(efficiencyPct float64) (grade, message string) {
440468
switch {
@@ -486,13 +514,15 @@ func mergeVelocityGrade(avgOpenDays float64) (grade, message string) {
486514

487515
// printEfficiency prints the workflow efficiency section for a single PR.
488516
func printEfficiency(breakdown *cost.Breakdown) {
489-
// Calculate preventable waste: Code Churn + All Delay Costs
517+
// Calculate preventable waste: Code Churn + All Delay Costs + Automated Updates + PR Tracking
490518
preventableHours := breakdown.DelayCostDetail.CodeChurnHours +
491519
breakdown.DelayCostDetail.DeliveryDelayHours +
492-
breakdown.DelayCostDetail.CoordinationHours
520+
breakdown.DelayCostDetail.AutomatedUpdatesHours +
521+
breakdown.DelayCostDetail.PRTrackingHours
493522
preventableCost := breakdown.DelayCostDetail.CodeChurnCost +
494523
breakdown.DelayCostDetail.DeliveryDelayCost +
495-
breakdown.DelayCostDetail.CoordinationCost
524+
breakdown.DelayCostDetail.AutomatedUpdatesCost +
525+
breakdown.DelayCostDetail.PRTrackingCost
496526

497527
// Calculate total hours
498528
totalHours := breakdown.Author.TotalHours + breakdown.DelayCostDetail.TotalDelayHours

0 commit comments

Comments
 (0)