Repository navigation
feat(lavaflow): report pull request delivery in the CLI #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,16 @@ func LavaflowStats(w io.Writer, stats *apiclient.LavaflowStats) { | |
| summary(w, on, "%d issue(s) opened and %d fix pull request(s) opened, %s to %s", | ||
| stats.Totals.IssuesOpened, stats.Totals.PullRequestsOpened, | ||
| stats.WindowStart.Format(time.DateOnly), stats.WindowEnd.Format(time.DateOnly)) | ||
| if delivery := stats.Delivery; delivery != nil { | ||
| kv(w, on, "Runs without an owned PR", "%d of %d (%d finished)", delivery.RunsWithoutOwnedPr, delivery.Runs, delivery.FinishedWithoutOwnedPr) | ||
| kv(w, on, "Issues with PR coverage", "%d of %d", delivery.IssuesWithPrCoverage, delivery.IssuesWithRuns) | ||
| if delivery.MeanTimeToPrSeconds != nil { | ||
| kv(w, on, "Mean time to PR", "%ds (%d samples)", *delivery.MeanTimeToPrSeconds, delivery.TimeToPrSamples) | ||
| } | ||
| if delivery.MeanTimeToCoverageSeconds != nil { | ||
| kv(w, on, "Mean time to coverage", "%ds (%d samples)", *delivery.MeanTimeToCoverageSeconds, delivery.TimeToCoverageSamples) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // LavaflowResources renders every function, frontend and durable function with | ||
|
|
@@ -160,14 +170,40 @@ func LavaflowRuns(w io.Writer, page LavaflowRunsPage) { | |
| for _, run := range page.Runs { | ||
| fmt.Fprintf(w, "%-36s %-31s %-24s %-30s %-16s %s\n", | ||
| run.Id.String(), Truncate(lavaflowRunListStatus(run), 31), Truncate(clean(run.Resource.Name), 24), | ||
| Truncate(clean(stringOr(run.Title, "-")), 30), formatLavaflowTime(run.CreatedAt), lavaflowPullRequestCell(run.PullRequest)) | ||
| Truncate(clean(stringOr(run.Title, "-")), 30), formatLavaflowTime(run.CreatedAt), lavaflowDeliveryCell(run.PullRequest, run.Delivery)) | ||
| } | ||
| summary(w, on, "Showing %d run(s)", len(page.Runs)) | ||
| if page.NextCommand != "" { | ||
| nextPage(w, on, clean(page.NextCommand)) | ||
| } | ||
| } | ||
|
|
||
| func lavaflowDeliveryCell(pr *apiclient.LavaflowPullRequest, delivery *apiclient.LavaflowDelivery) string { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ P3: New delivery rendering has no tests The diff adds Found by claude-opus-5-5 |
||
| if pr != nil || delivery == nil { | ||
| return lavaflowPullRequestCell(pr) | ||
| } | ||
| if cover := delivery.Coverage; cover != nil { | ||
| return fmt.Sprintf("Covered by #%d (%s)", cover.Number, clean(string(cover.State))) | ||
| } | ||
| if status := lavaflowDeliveryStatus(delivery.State); status != "" { | ||
| return status | ||
| } | ||
| return "-" | ||
| } | ||
|
|
||
| func lavaflowDeliveryStatus(state apiclient.LavaflowDeliveryState) string { | ||
| switch state { | ||
| case apiclient.LavaflowDeliveryStateWaitingForPrerequisite: | ||
| return "Waiting" | ||
| case apiclient.LavaflowDeliveryStateTerminalMiss: | ||
| return "Undelivered" | ||
| case apiclient.LavaflowDeliveryStateStopped: | ||
| return "Stopped" | ||
| default: | ||
| return "" | ||
| } | ||
| } | ||
|
|
||
| // LavaflowRunStarted renders a run a person started: its ID and status, and | ||
| // the command that follows it. | ||
| func LavaflowRunStarted(w io.Writer, runID string, status apiclient.LavaflowRunStatus, showCommand string) { | ||
|
|
@@ -463,7 +499,33 @@ func lavaflowHumanReviewPaths(w io.Writer, on bool, policy apiclient.LavaflowMer | |
| // state and where its merge is, or why the run has no pull request. | ||
| func lavaflowFix(w io.Writer, on bool, run *apiclient.LavaflowRun) { | ||
| fmt.Fprintln(w, theme.Dim("Fix:", on)) | ||
| pr := run.PullRequest | ||
| pr, delivery := run.PullRequest, run.Delivery | ||
| if delivery != nil { | ||
| for _, skip := range delivery.PriorSkips { | ||
| fixKV(w, on, "Previous blocker", "%s (%s)", clean(string(skip.Reason)), formatLavaflowTimePtr(skip.RecordedAt, "time unknown")) | ||
| } | ||
| if delivery.NextAction != nil { | ||
| defer fixKV(w, on, "Next action", "%s", clean(*delivery.NextAction)) | ||
| } | ||
| if cover := delivery.Coverage; cover != nil && pr == nil { | ||
| fixKV(w, on, "Covering pull request", "#%d %s", cover.Number, clean(cover.Url)) | ||
| fixKV(w, on, "State", "%s", clean(string(cover.State))) | ||
| if cover.State == apiclient.LavaflowDeliveryCoverageStateMerged { | ||
| fixKV(w, on, "Deployment", "%s", formatLavaflowTimePtr(cover.DeployedAt, "unconfirmed")) | ||
| } | ||
| return | ||
| } | ||
| if state := lavaflowDeliveryStatus(delivery.State); state != "" && pr == nil { | ||
| if delivery.Reason != nil { | ||
| fixKV(w, on, "Delivery", "%s (%s)", state, clean(*delivery.Reason)) | ||
| } else { | ||
| fixKV(w, on, "Delivery", "%s", state) | ||
| } | ||
| if delivery.State == apiclient.LavaflowDeliveryStateWaitingForPrerequisite || run.PullRequestSkipped == nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ P3: A waiting delivery with no next_action shows only a raw skip code For Found by claude-opus-5-5 |
||
| return | ||
| } | ||
| } | ||
| } | ||
| if pr == nil { | ||
| fmt.Fprintf(w, " %s\n", lavaflowNoFix(run)) | ||
| return | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package output | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/Kong/volcano-cli/internal/apiclient" | ||
| ) | ||
|
|
||
| func TestLavaflowDeliveryStatus(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| nextAction := "Check the repository connection." | ||
| reason := "source_unavailable" | ||
| for _, tc := range []struct { | ||
| state apiclient.LavaflowDeliveryState | ||
| label string | ||
| action *string | ||
| }{ | ||
| {apiclient.LavaflowDeliveryStateWaitingForPrerequisite, "Waiting", nil}, | ||
| {apiclient.LavaflowDeliveryStateTerminalMiss, "Undelivered", &nextAction}, | ||
| {apiclient.LavaflowDeliveryStateStopped, "Stopped", &nextAction}, | ||
| } { | ||
| t.Run(string(tc.state), func(t *testing.T) { | ||
| t.Parallel() | ||
| delivery := &apiclient.LavaflowDelivery{State: tc.state, Reason: &reason, NextAction: tc.action} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ P3: Covering-PR and delivery-stat output remain untested The new test covers three delivery states, but no tests populate coverage, prior skips, or stats delivery fields. The covering-PR precedence, deployment output, and nullable latency branches therefore lack regression coverage. Add focused output cases for these paths. Found by gpt-6.1-sol |
||
| run := &apiclient.LavaflowRun{Status: apiclient.LavaflowRunStatusCompleted, Delivery: delivery} | ||
|
|
||
| require.Equal(t, tc.label, lavaflowDeliveryCell(nil, delivery)) | ||
| var out bytes.Buffer | ||
| lavaflowFix(&out, false, run) | ||
| require.Contains(t, out.String(), "Delivery: "+tc.label+" ("+reason+")") | ||
| if tc.action != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ P3: New test skips the coverage, prior-skip, fall-through and stats paths
Found by claude-opus-5-5 |
||
| require.Contains(t, out.String(), "Next action: "+*tc.action) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ P3: Stats print mean latency as raw seconds
Mean time to PRandMean time to coverageprint%ds, so a one-day mean reads as86400s. Other output in this package formats second counts with(time.Duration(n) * time.Second).String()(seedeployments.go:74anddurable.go:418). Formatting these the same way would make them readable and consistent. The companion docs PR would need the same change.Found by claude-opus-5-5