:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(engineering-analytics): show the author's team next to merge times (#102162)
Julian Bezd8e9264f4014
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b25fd255ead8..47a71de955e8 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -7673,17 +7673,17 @@ snapshots:scenes-app-discussions--threads--light:hash: v1.k794b7964.28ac830bf83be5cbb6d7a397d67c9b9c61711904a822de38402b82220b0f7a49.7wENY7hvo1-qAJwq5fcsvKGJsfRAF_vDkpnM8iqFZccscenes-app-engineering-analytics-author--author--dark:- hash: v1.k794b7964.1d3d5ad4384d1455db661057f83f2981deeac486db482f18fda2ffc4831a0d64.KlfXRXFvKylYGb6tLKz5vnU1IPJ2l0AA7rrBFwIYnOE+ hash: v1.k794b7964.d0428d33941e837771eb3d1b44841bb41f371c43decd9ab13a326c7fc712b793.iZacBzGTNGba7RGCEGIp_xPVAW7t5OfT3Qhy0yejBPEscenes-app-engineering-analytics-author--author--light:- hash: v1.k794b7964.11b4fa1297a2fe26ca31fcbfd078f2eb026dc52d8b9feae8e4b01dd5b5e344d3.ZossZ7M9N-OOLyssbqwNNj6wNb_3-TKgEcxgAIPk0TM+ hash: v1.k794b7964.70bc536f5d20b49a5605153490f196bd550acf1aad10436e947598e944eb1e6d.akNGuw454xg0X61A8dEKrcyxiP-P8c-wXK-eEKmOKN4scenes-app-engineering-analytics-author--author-narrow--dark:- hash: v1.k794b7964.61586233f0d99a295503bc466f739ed4b76043ab9bbf39a8c40c643aff3f5eb4.hAIwpK76FMPr3nZ4p2ZN65DyJYuPpaOMSBt7raTwUVU+ hash: v1.k794b7964.5581a2e4305fb9b3c44efebf1bdac5b4cab4913f94f00410aa1c8acd16447604.JM-8_Knn5Xp7DUg7A3_KqSmTXhLsMm96dsnGyZN0Zq8scenes-app-engineering-analytics-author--author-narrow--light:- hash: v1.k794b7964.3d7a289e93726190975964c1a0c13b3aff934688510a92d41c36a61c38e28de0.zbZRiTmhxMUFC_68LYnMHJZ6hn8gOtdJWHLWzTh09yM+ hash: v1.k794b7964.e53b45c0aab436d0112b5b5333ca74aae55580b0d261affcfc698353e8848734.KBhwiCIKN3xYXeNuRpGOLrV6fesQPd7_dCb44FsQJ-Yscenes-app-engineering-analytics-author--author-without-reviews-or-deploys--dark:- hash: v1.k794b7964.079499fddb5d88126b2fc93501d215aad1e361fd0622ec9e06aae82b0f81b1b3.X1gQOWOwe8W2YokDSb50W_fa0YC5LU0KyhI3S0wnsxs+ hash: v1.k794b7964.34de3a48d43e9f1e984874a7b9dd29c3b7e8bda0d7916cb4418d6514012b2966.EGGY6Wo9xAPuqnyaCAUuadpLPfffz0UyJUTpbfzqdF4scenes-app-engineering-analytics-author--author-without-reviews-or-deploys--light:- hash: v1.k794b7964.bea96d256929e856604648b09c72202d92938002ccd8042ceaa02a252172612d.x7UvuyHwU-uYlZiQXM5X2WYPiCte2j2OGUFfQeQ130A+ hash: v1.k794b7964.fbbb7ddbb2228ad89332ecbccd97dab656fe03a72e16f5c707284bd22ee92c4a.jQZjSLx-D9tq_nRzT8Qxypg7QgGX4hfGqUDOjHoupesscenes-app-engineering-analytics-delivery-pipeline--all-stages--dark:hash: v1.k794b7964.e6fc5778d62714ed6fd4174b65c767a850d116b902223aa6f2086ce967edcaed.HoZOw65AQI9tW_L6CG_9JN6y7lmyhzy_Q1PQL__zCskscenes-app-engineering-analytics-delivery-pipeline--all-stages--light:@@ -7721,13 +7721,13 @@ snapshots:scenes-app-engineering-analytics-lead-time-box-plot--horizontal-log-scale--light:hash: v1.k794b7964.bc3a9455717626ef2f9541e03740bd0027c89139cd54ba4eb57a883d0e222667.OlAdmRvrHHSpGH8a2jHqV60Z957X8hIrNlcY9Duvv9Ascenes-app-engineering-analytics-pull-request--merged--dark:- hash: v1.k794b7964.80a2b728c5e0678bea85d723674691f871ef76948e3b6337b3483f14c883c139.eMeYeAcy8Hnc3_sf3F4zLyiktYufQrJL1CWlIr2HI-Y+ hash: v1.k794b7964.dbb2f22e3a1ec8dce071c7900199afec5c337766c3aeb2535d9848e6971596e3.GPFOe8jqc-PMF5uYBemiRSF20PT9l4S_79RtlxbKeVcscenes-app-engineering-analytics-pull-request--merged--light:- hash: v1.k794b7964.3defacb7f88f122971276608b2e5b6e3dc4e93a0d37d8a215fb790e9e9bb3694.S2THK6gGwY8V7wCKjc3xyQRz76khLRw7zXUwsybiaNQ+ hash: v1.k794b7964.3e0b817b32bfc1caed0ae893b36b9222a0143c492c64dc32c56204d159a5b5b9.rzKobY8gpb_2i9jJU3w3pyvtcatmW8FF75bxFsRNzvQscenes-app-engineering-analytics-pull-request--out-of-the-merge-queue--dark:- hash: v1.k794b7964.b926894fba6585b7a88815232f7571095c49f7703c904c79aa772c98c500ed0e.PfbMVTD7emKKRe5TnvI1fvMqlmABOMZVCTqw-6j1hBA+ hash: v1.k794b7964.bef18c2700ce93e8a28cb7a4871af8feeab4ff4f3e4784c4a1d064a74d242496.zZ_wftKLSMvrUpOczRzk8zoq3Q9-phnA_6862tU0PWwscenes-app-engineering-analytics-pull-request--out-of-the-merge-queue--light:- hash: v1.k794b7964.344b2260c74f8fc6c56d783086a4864638fbaabd9f7173a0e223531ae1c573d6.PcDGFYzOXeeR91tJZQQDUBnivX-Tk8pXQ5_jhILqQ4M+ hash: v1.k794b7964.9822550d77266ce69ecde7738f580a3d18c6537ce386f1f57d42ce5119038b1f.vxcYv5zCHX2lBZem4rKymrSVk7QLCZ7pQ3673cMsV6Uscenes-app-engineering-analytics-repo-overview--repo-overview--dark:hash: v1.k794b7964.1a470083e7a94ff46652f4368277eae5d35c927d65b58685e43ce34881e1e728.SEm3E8XvqrTHtJNRhVGX-9aaaw6xdWyzTNb_mw6c380scenes-app-engineering-analytics-repo-overview--repo-overview--light:diff --git a/products/engineering_analytics/frontend/components/ComparisonBarRow.tsx b/products/engineering_analytics/frontend/components/ComparisonBarRow.tsxindex 34abbdcfb048..b55f5542486c 100644--- a/products/engineering_analytics/frontend/components/ComparisonBarRow.tsx+++ b/products/engineering_analytics/frontend/components/ComparisonBarRow.tsx@@ -20,6 +20,7 @@ function fillClassName(muted: boolean, hasSegments: boolean): string {export function ComparisonBarRow({label,+ labelTooltip,value,fraction,muted = false,@@ -27,6 +28,8 @@ export function ComparisonBarRow({children,}: {label: string+ /** Shown on hover over the label, e.g. the full name a narrow label truncates. */+ labelTooltip?: stringvalue: string/** Bar length as a share of the track, 0–1. */fraction: number@@ -38,7 +41,9 @@ export function ComparisonBarRow({}): JSX.Element {return (<div className="flex items-center gap-2">- <span className="w-24 shrink-0 truncate text-[11px] text-tertiary">{label}</span>+ <Tooltip title={labelTooltip}>+ <span className="w-24 shrink-0 truncate text-[11px] text-tertiary">{label}</span>+ </Tooltip><div className="relative h-2.5 flex-1"><divclassName={cn('h-full overflow-hidden rounded-sm', fillClassName(muted, children != null))}diff --git a/products/engineering_analytics/frontend/components/PullRequestComparisonCard.tsx b/products/engineering_analytics/frontend/components/PullRequestComparisonCard.tsxnew file mode 100644index 000000000000..7cb79a275cec--- /dev/null+++ b/products/engineering_analytics/frontend/components/PullRequestComparisonCard.tsx@@ -0,0 +1,76 @@+// One pull request's ready-to-merged time next to the medians of the pull requests merged in the 30 days+// before it: its author's, the author's own team's, and the repository's.++import { useValues } from 'kea'++import { dayjs } from 'lib/dayjs'++import type { DeliveryComparisonApi, PRTimelineApi } from '../generated/api.schemas'+import { timeInStates } from '../lib/pullRequestTimeline'+import { ReadyToMergeRow, mediansRow, missingTeamText, teamRows } from '../lib/readyToMergeRows'+import { deliveryComparisonLogic } from '../scenes/deliveryComparisonLogic'+import { ReadyToMergeCard } from './ReadyToMergeCard'++const WINDOW_DAYS = 30++function pullRequestRow(pr: PRTimelineApi, comparison: DeliveryComparisonApi): ReadyToMergeRow {+ const split = comparison.pull_request+ return {+ label: pr.merged_at ? 'This PR' : 'This PR so far',+ shortLabel: 'this PR',+ // An open pull request's timeline starts at its last ready for review, the medians' measure so far.+ // A merged one keeps the read's own measure, which is null when its ready time was not observed.+ seconds: pr.merged_at ? (split?.ready_to_merge_seconds ?? null) : timeInStates(pr).wholeSeconds,+ p90Seconds: null,+ beforeShare: split?.before_first_approval_share ?? null,+ beforeApprovalSeconds: split?.ready_to_first_approval_seconds ?? null,+ afterApprovalSeconds: split?.first_approval_to_merge_seconds ?? null,+ }+}++export function PullRequestComparisonCard({+ pr,+ sourceId,+}: {+ pr: PRTimelineApi+ sourceId: string | null+}): JSX.Element {+ const dateWindow = pr.merged_at+ ? { dateFrom: dayjs(pr.merged_at).subtract(WINDOW_DAYS, 'day').toISOString(), dateTo: pr.merged_at }+ : { dateFrom: `-${WINDOW_DAYS}d`, dateTo: null }+ const { comparison, comparisonLoading, comparisonFailed } = useValues(+ deliveryComparisonLogic({+ author: pr.author.handle,+ sourceId,+ prNumber: pr.number,+ repo: `${pr.repo.owner}/${pr.repo.name}`,+ window: dateWindow,+ })+ )+ const handle = pr.author.handle+ const rows = comparison+ ? [+ pullRequestRow(pr, comparison),+ mediansRow(handle, handle, comparison.author_medians),+ ...teamRows(comparison),+ mediansRow('Repo', 'repo', comparison.repo_medians),+ ]+ : []++ return (+ <ReadyToMergeCard+ title="Compared with recent pull requests"+ tooltip={`This pull request's time from ready for review to merged, next to the medians over pull requests merged in the ${WINDOW_DAYS} days before it: its author's, the author's own team's, and the whole repository's. Each bar is split at the first approval by the share of hours on each side.`}+ rows={rows}+ reviewsSynced={!!comparison?.review_data_available}+ loading={comparisonLoading && !comparison}+ emptyText={+ comparisonFailed+ ? "Couldn't load the comparison. Reload the page to try again."+ : "This pull request's ready for review time isn't known, so there is nothing to compare."+ }+ footnote={missingTeamText(comparison, false)}+ dataAttr="engineering-analytics-pr-comparison"+ />+ )+}diff --git a/products/engineering_analytics/frontend/components/ReadyToMergeCard.tsx b/products/engineering_analytics/frontend/components/ReadyToMergeCard.tsxindex c01742f1a7ce..f4220e394599 100644--- a/products/engineering_analytics/frontend/components/ReadyToMergeCard.tsx+++ b/products/engineering_analytics/frontend/components/ReadyToMergeCard.tsx@@ -4,14 +4,15 @@import { LemonCard, LemonSkeleton, Tooltip } from '@posthog/lemon-ui'-import type { DeliverySummaryApi } from '../generated/api.schemas'import { compactAgeLabel, percent } from '../lib/format'+import { ReadyToMergeRow } from '../lib/readyToMergeRows'import { ComparisonBarRow } from './ComparisonBarRow'const BEFORE_APPROVAL_COLOR = 'var(--data-color-3)'const AFTER_APPROVAL_COLOR = 'var(--data-color-1)'function ApprovalSplit({ beforeShare }: { beforeShare: number | null }): JSX.Element {+ // A plain data color would read as one side of the approval split, so an unsplit bar stays grey.if (beforeShare == null) {return <div className="h-full bg-[var(--muted)]" />}@@ -33,131 +34,115 @@ function ApprovalSplit({ beforeShare }: { beforeShare: number | null }): JSX.Ele)}-function SplitRow({- label,- value,- p90,- beforeShare,- max,- isScope,-}: {- label: string- value: number- p90: number | null- beforeShare: number | null- max: number- isScope: boolean-}): JSX.Element {- return (- <ComparisonBarRow- label={label}- value={compactAgeLabel(value)}- fraction={value / max}- muted={!isScope}- marker={p90 != null ? { fraction: p90 / max, tooltip: `90th percentile ${compactAgeLabel(p90)}` } : null}- >- <ApprovalSplit beforeShare={beforeShare} />- </ComparisonBarRow>- )+function baselineText(rows: ReadyToMergeRow[], seconds: (row: ReadyToMergeRow) => number | null): string {+ return rows+ .filter((row) => seconds(row) != null)+ .map((row) => `${row.shortLabel} ${compactAgeLabel(seconds(row))}`)+ .join(' · ')}function LegRow({color,label,- scope,- repo,+ value,+ baselines,}: {color: stringlabel: string- scope: number | null- repo: number | null+ value: number | null+ baselines: string}): JSX.Element {return (- <div className="grid grid-cols-[minmax(0,1fr)_auto_5rem] items-baseline gap-2 border-t border-primary py-1 text-xs text-secondary">+ <div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,auto)] items-baseline gap-2 border-t border-primary py-1 text-xs text-secondary"><span className="flex min-w-0 items-center gap-1.5"><span className="size-2 shrink-0 rounded-sm" style={{ backgroundColor: color }} /><span className="truncate">{label}</span></span>- <span className="font-semibold tabular-nums text-primary">{compactAgeLabel(scope)}</span>- <span className="text-right tabular-nums text-tertiary">repo {compactAgeLabel(repo)}</span>+ <span className="font-semibold tabular-nums text-primary">{compactAgeLabel(value)}</span>+ <span className="truncate text-right tabular-nums text-tertiary">{baselines}</span></div>)}export function ReadyToMergeCard({- summary,- scopeLabel,+ rows,+ reviewsSynced,loading,+ emptyText,+ title = 'Ready for review to merged',+ tooltip = 'Median calendar time from the last ready for review to the merge, over pull requests merged in the window. The bar length is that median. Its split is the share of all those hours spent before and after the first approval, so long pull requests weigh more. The two medians below are separate medians and do not add up to the total.',+ footnote,+ dataAttr = 'engineering-analytics-delivery-ready',}: {- summary: DeliverySummaryApi | null- /** The row label for the scope's bar, e.g. "This author" or "This team". */- scopeLabel: string+ /** The row being compared first, then its baselines, drawn muted. */+ rows: ReadyToMergeRow[]+ reviewsSynced: booleanloading: boolean+ emptyText: string+ title?: string+ tooltip?: string+ footnote?: string | null+ dataAttr?: string}): JSX.Element {- const median = summary?.median_ready_to_merge_seconds- const p90 = summary?.p90_ready_to_merge_seconds- const share = summary?.before_first_approval_share- const reviewsSynced = !!summary?.review_data_available- const max = Math.max(...[median?.scope, median?.repo, p90?.scope, p90?.repo].map((value) => value ?? 0))+ const [focus, ...baselines] = rows+ const shown = rows.filter((row) => row.seconds != null)+ const max = Math.max(...shown.flatMap((row) => [row.seconds ?? 0, row.p90Seconds ?? 0]))return (- <LemonCard- hoverEffect={false}- className="flex h-full flex-col p-4"- data-attr="engineering-analytics-delivery-ready"- >+ <LemonCard hoverEffect={false} className="flex h-full flex-col p-4" data-attr={dataAttr}><h3 className="mb-1 text-xs font-semibold text-secondary">- <Tooltip title="Median calendar time from the last ready for review to the merge, over pull requests merged in the window. The bar length is that median. Its split is the share of all those hours spent before and after the first approval, so long pull requests weigh more. The two medians below are separate medians and do not add up to the total.">- <span className="cursor-default">Ready for review to merged</span>+ <Tooltip title={tooltip}>+ <span className="cursor-default">{title}</span></Tooltip></h3>{loading ? (<LemonSkeleton className="h-24 w-full" />- ) : median?.scope != null ? (+ ) : focus?.seconds != null ? (<><div className="mb-3 flex flex-wrap items-baseline gap-2"><span className="text-2xl font-semibold leading-none tabular-nums">- {compactAgeLabel(median.scope)}+ {compactAgeLabel(focus.seconds)}+ </span>+ <span className="text-xs tabular-nums text-tertiary">+ {baselineText(baselines, (row) => row.seconds)}</span>- {median.repo != null && (- <span className="text-xs tabular-nums text-tertiary">- repo {compactAgeLabel(median.repo)}- </span>- )}</div><div className="flex flex-col gap-1.5">- <SplitRow- label={scopeLabel}- value={median.scope}- p90={p90?.scope ?? null}- beforeShare={reviewsSynced ? (share?.scope ?? null) : null}- max={max}- isScope- />- {median.repo != null && (- <SplitRow- label="Repo"- value={median.repo}- p90={p90?.repo ?? null}- beforeShare={reviewsSynced ? (share?.repo ?? null) : null}- max={max}- isScope={false}- />- )}+ {shown.map((row, index) => (+ <ComparisonBarRow+ // A handle can equal a team slug, so the label alone is no unique key.+ key={`${index}:${row.label}`}+ label={row.label}+ labelTooltip={row.labelTooltip}+ value={compactAgeLabel(row.seconds)}+ fraction={(row.seconds ?? 0) / max}+ muted={row !== focus}+ marker={+ row.p90Seconds != null+ ? {+ fraction: row.p90Seconds / max,+ tooltip: `90th percentile ${compactAgeLabel(row.p90Seconds)}`,+ }+ : null+ }+ >+ <ApprovalSplit beforeShare={reviewsSynced ? row.beforeShare : null} />+ </ComparisonBarRow>+ ))}</div>{reviewsSynced ? (<div className="mt-3 flex flex-col"><LegRowcolor={BEFORE_APPROVAL_COLOR}- label="Ready to first approval, median"- scope={summary?.median_ready_to_first_approval_seconds.scope ?? null}- repo={summary?.median_ready_to_first_approval_seconds.repo ?? null}+ label="Ready to first approval"+ value={focus.beforeApprovalSeconds}+ baselines={baselineText(baselines, (row) => row.beforeApprovalSeconds)}/><LegRowcolor={AFTER_APPROVAL_COLOR}- label="First approval to merged, median"- scope={summary?.median_first_approval_to_merge_seconds.scope ?? null}- repo={summary?.median_first_approval_to_merge_seconds.repo ?? null}+ label="First approval to merged"+ value={focus.afterApprovalSeconds}+ baselines={baselineText(baselines, (row) => row.afterApprovalSeconds)}/></div>) : (@@ -165,13 +150,10 @@ export function ReadyToMergeCard({Sync the reviews table on this GitHub source to split the wait at the first approval.</div>)}+ {footnote && <div className="mt-2 text-[11px] text-tertiary">{footnote}</div>}</>) : (- <div className="flex h-20 items-center text-xs text-secondary">- {summary && !summary.ready_data_available- ? 'Ready time appears once the issue events table on this GitHub source is synced.'- : 'No merged pull requests with a known ready time in the window.'}- </div>+ <div className="flex h-20 items-center text-xs text-secondary">{emptyText}</div>)}</LemonCard>)diff --git a/products/engineering_analytics/frontend/lib/readyToMergeRows.ts b/products/engineering_analytics/frontend/lib/readyToMergeRows.tsnew file mode 100644index 000000000000..fd9802c7815b--- /dev/null+++ b/products/engineering_analytics/frontend/lib/readyToMergeRows.ts@@ -0,0 +1,89 @@+import type { DeliveryComparisonApi, DeliverySummaryApi, ReadyToMergeMediansApi } from '../generated/api.schemas'++export interface ReadyToMergeRow {+ label: string+ /** The row's name in the baseline text under the bars, e.g. "repo". */+ shortLabel: string+ labelTooltip?: string+ seconds: number | null+ p90Seconds: number | null+ beforeShare: number | null+ beforeApprovalSeconds: number | null+ afterApprovalSeconds: number | null+}++export function mediansRow(+ label: string,+ shortLabel: string,+ medians: ReadyToMergeMediansApi,+ labelTooltip?: string+): ReadyToMergeRow {+ return {+ label,+ shortLabel,+ labelTooltip,+ seconds: medians.ready_to_merge_seconds,+ p90Seconds: medians.p90_ready_to_merge_seconds,+ beforeShare: medians.before_first_approval_share,+ beforeApprovalSeconds: medians.ready_to_first_approval_seconds,+ afterApprovalSeconds: medians.first_approval_to_merge_seconds,+ }+}++export function summaryRows(+ summary: DeliverySummaryApi,+ scopeLabel: string,+ teamRows: ReadyToMergeRow[] = []+): ReadyToMergeRow[] {+ const row = (pick: 'scope' | 'repo', label: string, shortLabel: string): ReadyToMergeRow => ({+ label,+ shortLabel,+ seconds: summary.median_ready_to_merge_seconds[pick],+ p90Seconds: summary.p90_ready_to_merge_seconds[pick],+ beforeShare: summary.before_first_approval_share[pick],+ beforeApprovalSeconds: summary.median_ready_to_first_approval_seconds[pick],+ afterApprovalSeconds: summary.median_first_approval_to_merge_seconds[pick],+ })+ return [row('scope', scopeLabel, scopeLabel.toLowerCase()), ...teamRows, row('repo', 'Repo', 'repo')]+}++function teamTooltip(comparison: DeliveryComparisonApi, team: string): string {+ const author = comparison.author+ switch (comparison.team_basis) {+ case 'pull_request':+ return `${team}: this pull request asked the team to review.`+ case 'review_requests':+ return `${team}: the team ${author}'s pull requests asked to review most often.`+ case 'only_team':+ return `${team}: ${author}'s team.`+ default:+ return `${team}: one of ${author}'s teams. No review request points at one of them.`+ }+}++export function teamRows(comparison: DeliveryComparisonApi | null): ReadyToMergeRow[] {+ if (!comparison) {+ return []+ }+ return comparison.teams.flatMap(({ github_team, medians }) =>+ medians ? [mediansRow(github_team, github_team, medians, teamTooltip(comparison, github_team))] : []+ )+}++export function missingTeamText(comparison: DeliveryComparisonApi | null, failed: boolean): string | null {+ if (failed) {+ return "Couldn't load the team comparison. Reload the page to try again."+ }+ if (!comparison) {+ return null+ }+ if (comparison.teams.length === 0) {+ return comparison.has_membership_data+ ? `No team row: ${comparison.author} isn't in a team that owns code.`+ : "Sync the team members table on this GitHub source to compare with the author's team."+ }+ const hidden = comparison.teams.filter((team) => !team.medians).map((team) => team.github_team)+ return hidden.length+ ? `No row for ${hidden.join(', ')}: fewer than three other authors merged there in the window, so a median would show a teammate's time.`+ : null+}diff --git a/products/engineering_analytics/frontend/scenes/DeliverySections.tsx b/products/engineering_analytics/frontend/scenes/DeliverySections.tsxindex 3c4d26f7b330..cd4b64dbca04 100644--- a/products/engineering_analytics/frontend/scenes/DeliverySections.tsx+++ b/products/engineering_analytics/frontend/scenes/DeliverySections.tsx@@ -8,8 +8,10 @@ import { PullRequestCountsCard } from '../components/PullRequestCountsCard'import { ReadyToMergeCard } from '../components/ReadyToMergeCard'import { ScopeComparisonCard } from '../components/ScopeComparisonCard'import { Section } from '../components/Section'+import type { DeliveryComparisonApi } from '../generated/api.schemas'import { DeliveryScope } from '../lib/deliveryScope'import { compactMinutes, compactUsd, percent } from '../lib/format'+import { missingTeamText, summaryRows, teamRows } from '../lib/readyToMergeRows'import { deliverySummaryLogic } from './deliverySummaryLogic'const formatRatio = (value: number): string => value.toFixed(1)@@ -18,12 +20,17 @@ export function DeliverySections({scope,scopeLabel,sourceId,+ comparison = null,+ comparisonFailed = false,}: {/** An author or a GitHub team; the summary endpoint rejects a single pull request. */scope: DeliveryScope/** The row label for the scope's bars, e.g. "This author" or "This team". */scopeLabel: stringsourceId: string | null+ /** An author's comparison with their own team, which adds the team's row to the ready-to-merge card. */+ comparison?: DeliveryComparisonApi | null+ comparisonFailed?: boolean}): JSX.Element {const summaryLogic = deliverySummaryLogic({ scope, sourceId })const { summary, summaryLoading, summaryFailed } = useValues(summaryLogic)@@ -95,7 +102,25 @@ export function DeliverySections({<div className="@container"><div className="grid grid-cols-1 gap-2 @min-[36rem]:grid-cols-2 @min-[64rem]:grid-cols-4"><div className="@min-[36rem]:col-span-2">- <ReadyToMergeCard summary={summary} scopeLabel={scopeLabel} loading={summaryPending} />+ <ReadyToMergeCard+ rows={+ summary+ ? summaryRows(+ summary,+ scopeLabel,+ teamRows(comparisonFailed ? null : comparison)+ )+ : []+ }+ reviewsSynced={!!summary?.review_data_available}+ loading={summaryPending}+ emptyText={+ summary && !summary.ready_data_available+ ? 'Ready time appears once the issue events table on this GitHub source is synced.'+ : 'No merged pull requests with a known ready time in the window.'+ }+ footnote={missingTeamText(comparison, comparisonFailed)}+ /></div><ScopeComparisonCardtitle="Pushes after approval"diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsxindex 47065c6b9ab2..834f5fb1285e 100644--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsx+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsx@@ -7,10 +7,12 @@ import { urls } from 'scenes/urls'import { mswDecorator } from '~/mocks/browser'import type {+ DeliveryComparisonApi,DeliverySummaryApi,DurationDistributionApi,PRTimelineApi,PullRequestTimelinesApi,+ ReadyToMergeMediansApi,WorkflowCostApi,} from '../generated/api.schemas'@@ -205,6 +207,39 @@ const WORKFLOW_COSTS: WorkflowCostApi[] = [},]+function medians(+ count: number,+ hours: { ready: number; p90: number; beforeApproval: number; afterApproval: number },+ beforeShare: number+): ReadyToMergeMediansApi {+ return {+ merged_pr_count: count,+ ready_to_merge_seconds: hours.ready * HOUR,+ p90_ready_to_merge_seconds: hours.p90 * HOUR,+ ready_to_first_approval_seconds: hours.beforeApproval * HOUR,+ first_approval_to_merge_seconds: hours.afterApproval * HOUR,+ before_first_approval_share: beforeShare,+ }+}++// The author page reads only the team rows; the author and repo rows come from the summary.+const COMPARISON: DeliveryComparisonApi = {+ author: 'jane-dev',+ has_membership_data: true,+ review_data_available: true,+ ready_data_available: true,+ team_basis: 'review_requests',+ author_medians: medians(23, { ready: 18, p90: 98, beforeApproval: 2.1, afterApproval: 11 }, 0.38),+ teams: [+ {+ github_team: 'team-replay',+ medians: medians(84, { ready: 13, p90: 82, beforeApproval: 3.2, afterApproval: 5.5 }, 0.46),+ },+ ],+ repo_medians: medians(1380, { ready: 9, p90: 77, beforeApproval: 2.6, afterApproval: 3.4 }, 0.52),+ pull_request: null,+}+const meta: Meta = {component: App,title: 'Scenes-App/Engineering Analytics/Author',@@ -222,6 +257,7 @@ const meta: Meta = {mswDecorator({get: {'api/projects/:team_id/engineering_analytics/delivery_summary/': SUMMARY,+ 'api/projects/:team_id/engineering_analytics/delivery_comparison/': COMPARISON,'api/projects/:team_id/engineering_analytics/pull_request_timelines/': TIMELINES,'api/projects/:team_id/engineering_analytics/author_workflow_costs/': WORKFLOW_COSTS,},@@ -243,6 +279,7 @@ export const AuthorNarrow: Story = {parameters: { testOptions: { viewport: { width: 900, height: 1800 } } },}+// Without the members table the ready card has no team row and says how to get one.export const AuthorWithoutReviewsOrDeploys: Story = {render: () => <App />,decorators: [@@ -253,6 +290,13 @@ export const AuthorWithoutReviewsOrDeploys: Story = {review_data_available: false,lead_time: { ...SUMMARY.lead_time, deploy_data_available: false, environment_scope: '' },},+ 'api/projects/:team_id/engineering_analytics/delivery_comparison/': {+ ...COMPARISON,+ has_membership_data: false,+ review_data_available: false,+ team_basis: 'no_team',+ teams: [],+ },'api/projects/:team_id/engineering_analytics/pull_request_timelines/': {...TIMELINES,review_data_available: false,diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsxindex e089d545968e..0a5f3c807605 100644--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsx+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsx@@ -22,6 +22,7 @@ import { ScopePanel } from '../components/ScopePanel'import { Section } from '../components/Section'import { ShareRow } from '../components/ShareRow'import { AuthorLogicProps, authorLogic } from './authorLogic'+import { deliveryComparisonLogic } from './deliveryComparisonLogic'import { DeliverySections } from './DeliverySections'import { deliverySummaryLogic } from './deliverySummaryLogic'import { pullRequestTimelinesLogic } from './pullRequestTimelinesLogic'@@ -38,6 +39,9 @@ export const scene: SceneExport<AuthorLogicProps> = {export function EngineeringAnalyticsAuthorScene(): JSX.Element {const { handle, sourceId, deliveryScope, workflowCosts, workflowCostsLoading } = useValues(authorLogic)const { summary, summaryLoading } = useValues(deliverySummaryLogic({ scope: deliveryScope, sourceId }))+ const { comparison, comparisonLoading, comparisonFailed } = useValues(+ deliveryComparisonLogic({ author: handle, sourceId })+ )const timelinesLogic = pullRequestTimelinesLogic({ scope: deliveryScope, sourceId })const {timelines,@@ -94,13 +98,20 @@ export function EngineeringAnalyticsAuthorScene(): JSX.Element {) : undefined}/>- {/* The page explains one author's own friction against the repository. It never compares- authors with each other (SPEC §2). */}+ {/* The page explains one author's own friction against the repository and the author's own team. It+ never compares authors with each other (SPEC §2). */}<ScopePanel- busy={summaryLoading || timelinesLoading || workflowCostsLoading}+ busy={summaryLoading || comparisonLoading || timelinesLoading || workflowCostsLoading}controls={<ScopeDateFilter dateOptions={DELIVERY_DATE_OPTIONS} />}>- <DeliverySections scope={deliveryScope} scopeLabel="This author" sourceId={sourceId} />+ <DeliverySections+ scope={deliveryScope}+ scopeLabel="This author"+ sourceId={sourceId}+ // Both reads keep their previous window while they reload, so the team rows wait for both.+ comparison={comparisonLoading || summaryLoading ? null : comparison}+ comparisonFailed={comparisonFailed}+ /><Section id="delivery-pull-requests" title="Pull requests">{timelinesFailed ? (diff --git a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsx b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsxindex 39cc2e032ab5..0962cd9f24df 100644--- a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsx+++ b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsx@@ -8,15 +8,18 @@ import { mswDecorator } from '~/mocks/browser'import type {CIFailureLogsApi,+ DeliveryComparisonApi,PRCostSummaryApi,PRLifecycleApi,PRTimelineApi,PullRequestTimelinesApi,+ ReadyToMergeMediansApi,WorkflowJobApi,WorkflowRunDetailApi,} from '../generated/api.schemas'const HOUR = 3600 * 1000+const HOUR_SECONDS = 3600const REPO = { provider: 'github', owner: 'PostHog', name: 'posthog' } as constconst AUTHOR = { handle: 'jane-dev', display_name: 'jane-dev', avatar_url: '', is_bot: false }@@ -214,6 +217,40 @@ const NO_FAILURE_LOGS: CIFailureLogsApi = {truncated: false,}+function medians(count: number, readyHours: number, beforeHours: number, afterHours: number): ReadyToMergeMediansApi {+ return {+ merged_pr_count: count,+ ready_to_merge_seconds: readyHours * HOUR_SECONDS,+ p90_ready_to_merge_seconds: 2.5 * readyHours * HOUR_SECONDS,+ ready_to_first_approval_seconds: beforeHours * HOUR_SECONDS,+ first_approval_to_merge_seconds: afterHours * HOUR_SECONDS,+ before_first_approval_share: beforeHours / (beforeHours + afterHours),+ }+}++// Jane is in two teams that own code; this pull request asked team-replay to review.+function comparison(pullRequest: DeliveryComparisonApi['pull_request']): DeliveryComparisonApi {+ return {+ author: AUTHOR.handle,+ has_membership_data: true,+ review_data_available: true,+ ready_data_available: true,+ team_basis: 'pull_request',+ author_medians: medians(21, 16, 5, 6),+ teams: [{ github_team: 'team-replay', medians: medians(88, 12, 4, 4.5) }],+ repo_medians: medians(1380, 9, 2.6, 3.4),+ pull_request: pullRequest,+ }+}++const MERGED_COMPARISON = comparison({+ number: 4721,+ ready_to_merge_seconds: 31.4 * HOUR_SECONDS,+ ready_to_first_approval_seconds: 29 * HOUR_SECONDS,+ first_approval_to_merge_seconds: 2.4 * HOUR_SECONDS,+ before_first_approval_share: 29 / 31.4,+})+const meta: Meta = {component: App,title: 'Scenes-App/Engineering Analytics/Pull Request',@@ -235,6 +272,7 @@ const meta: Meta = {'api/projects/:team_id/engineering_analytics/pr_cost/': PR_COST,'api/projects/:team_id/engineering_analytics/ci_failure_logs/': NO_FAILURE_LOGS,'api/projects/:team_id/engineering_analytics/pull_request_timelines/': timelines(MERGED),+ 'api/projects/:team_id/engineering_analytics/delivery_comparison/': MERGED_COMPARISON,},}),],@@ -259,6 +297,15 @@ export const OutOfTheMergeQueue: Story = {'api/projects/:team_id/engineering_analytics/pr_runs/': KICKED_RUNS,'api/projects/:team_id/engineering_analytics/pull_request_timelines/': timelines(KICKED),'api/projects/:team_id/engineering_analytics/workflow_jobs/': FAILED_GATE_JOBS,+ // Jane's two teams tie, and the smaller one has too few other authors to show a median.+ 'api/projects/:team_id/engineering_analytics/delivery_comparison/': {+ ...comparison(null),+ team_basis: 'review_requests',+ teams: [+ { github_team: 'team-replay', medians: medians(88, 12, 4, 4.5) },+ { github_team: 'team-web-analytics', medians: null },+ ],+ },},}),],diff --git a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsx b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsxindex b88dc66cdca0..a575993de2d6 100644--- a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsx+++ b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsx@@ -26,6 +26,7 @@ import { EntityHeader, VerdictPill } from '../components/EntityHeader'import { FailureLogGroups } from '../components/FailureLogs'import { GroupedJobsTable } from '../components/GroupedJobsTable'import { MetricTile } from '../components/MetricTile'+import { PullRequestComparisonCard } from '../components/PullRequestComparisonCard'import { PullRequestDeliveryTimeline } from '../components/PullRequestDeliveryTimeline'import { PullRequestStateTag } from '../components/PullRequestStateTag'import { RunConclusionTag } from '../components/runTables'@@ -609,7 +610,18 @@ export function PullRequestDetailScene(): JSX.Element {) : !timelines ? (<LemonSkeleton className="h-40 w-full" />) : timeline ? (- <PullRequestDeliveryTimeline pr={timeline} />+ <div className="flex flex-col gap-2">+ <PullRequestDeliveryTimeline pr={timeline} />+ {/* Only a merged or ready pull request has a ready-to-merge time. A bot, or a deleted account+ with no handle, has no pace to compare. */}+ {!!timeline.author.handle &&+ !timeline.author.is_bot &&+ (timeline.merged_at || (timeline.state === 'open' && !timeline.is_draft)) && (+ <div className="max-w-3xl">+ <PullRequestComparisonCard pr={timeline} sourceId={sourceId} />+ </div>+ )}+ </div>) : (<div className="text-sm text-secondary">No timeline for this pull request yet. If it stays empty, check the GitHub source's sync status.diff --git a/products/engineering_analytics/frontend/scenes/deliveryComparisonLogic.ts b/products/engineering_analytics/frontend/scenes/deliveryComparisonLogic.tsnew file mode 100644index 000000000000..fbb8ac4e9cb5--- /dev/null+++ b/products/engineering_analytics/frontend/scenes/deliveryComparisonLogic.ts@@ -0,0 +1,110 @@+import { MakeLogicType, afterMount, connect, kea, key, listeners, path, props, reducers } from 'kea'+import { loaders } from 'kea-loaders'++import { ApiConfig } from 'lib/api'++import { engineeringAnalyticsDeliveryComparison } from '../generated/api'+import type { DeliveryComparisonApi } from '../generated/api.schemas'+import { engineeringAnalyticsFiltersLogic } from './engineeringAnalyticsFiltersLogic'++export interface DeliveryComparisonLogicProps {+ author: string+ sourceId: string | null+ /** A pull request by the author: a team it asked to review is the team to compare with. */+ prNumber?: number+ repo?: string+ /** A fixed window. Without it the comparison follows the page's date filter. */+ window?: { dateFrom: string; dateTo: string | null }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface deliveryComparisonLogicValues {+ dateFrom: string | null // engineeringAnalyticsFiltersLogic+ dateTo: string | null // engineeringAnalyticsFiltersLogic+ comparison: DeliveryComparisonApi | null+ comparisonFailed: boolean+ comparisonLoading: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface deliveryComparisonLogicActions {+ loadComparison: () => any+ loadComparisonFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadComparisonSuccess: (+ comparison: DeliveryComparisonApi,+ payload?: any+ ) => {+ comparison: DeliveryComparisonApi+ payload?: any+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface deliveryComparisonLogicMeta {+ key: string+}++export type deliveryComparisonLogicType = MakeLogicType<+ deliveryComparisonLogicValues,+ deliveryComparisonLogicActions,+ DeliveryComparisonLogicProps,+ deliveryComparisonLogicMeta+>++export const deliveryComparisonLogic = kea<deliveryComparisonLogicType>([+ path(['products', 'engineering_analytics', 'frontend', 'scenes', 'deliveryComparisonLogic']),+ props({} as DeliveryComparisonLogicProps),+ key((props) =>+ [+ props.author,+ props.sourceId ?? '',+ props.repo ?? '',+ props.prNumber ?? '',+ props.window?.dateFrom ?? '',+ props.window?.dateTo ?? '',+ ].join('@')+ ),++ connect(() => ({+ values: [engineeringAnalyticsFiltersLogic, ['dateFrom', 'dateTo']],+ })),++ loaders(({ props, values }) => ({+ comparison: [+ null as DeliveryComparisonApi | null,+ {+ loadComparison: async () =>+ await engineeringAnalyticsDeliveryComparison(String(ApiConfig.getCurrentProjectId()), {+ author: props.author,+ pr_number: props.prNumber,+ repo: props.repo,+ date_from: (props.window ? props.window.dateFrom : values.dateFrom) ?? undefined,+ date_to: (props.window ? props.window.dateTo : values.dateTo) ?? undefined,+ source_id: props.sourceId ?? undefined,+ }),+ },+ ],+ })),++ reducers({+ comparisonFailed: [false, { loadComparison: () => false, loadComparisonFailure: () => true }],+ }),++ listeners(({ actions, props }) => ({+ [engineeringAnalyticsFiltersLogic.actionTypes.setDateRange]: () => {+ if (!props.window) {+ actions.loadComparison()+ }+ },+ })),++ afterMount(({ actions }) => {+ actions.loadComparison()+ }),+])