feat: lifecycle inference from the issue timeline (#5)
Fill the board's Steeping / In-review columns (and the calibration actuals) from real gitea timeline events, replacing the three-column-only v0. core (@commitea/core): - inferLifecycle(issue, events, asOf): five-column inference — closed → done; open PR ref → review; commit ref → steeping; any triage signal → triage; else diagnosis. Earliest event of each kind fixes the stage timestamp. - Derives actualWorkingDays (work-start → close) — the estimate-vs-actual the calibration fit (D3) learns from — and steepingDays (first commit → now) for the board age badge. - workingDaysBetween(): whole Mon–Fri days in [start, end), day-granular. - normalizeTimeline() + client.getIssueTimeline(): map gitea's raw timeline (label/milestone → triage, commit_ref → commit, pull_ref → pull, close, reopen), drop the rest. Paginated. app: - reconcile now fetches every issue's timeline and returns it keyed by number; threaded through the bridge → useBacklog → board/focus. - issuesToBoardColumns + scheduleFocus run inferLifecycle: real Steeping/In-review columns, steeping-age `days` badge, focus-card steeping badge. Known refinement: gitea's pull_ref fires on any PR mention, so an issue merely referenced in a PR body can read as In-review; distinguishing closing refs from mentions needs the PR link's state (later). Re-opening multi-segment actuals also deferred. Verified: 63 core tests green (15 lifecycle, incl. workingDaysBetween + the five transitions), desktop typecheck clean, 14 fixture e2e green, live spec asserts the board's Done column is populated from real events. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* get the full set.
|
||||
*/
|
||||
|
||||
import { type LifecycleEvent, type LifecycleEventType } from '../lifecycle/lifecycle-v0.js'
|
||||
import { extractLabelFacts } from '../labels/label-schema.js'
|
||||
import {
|
||||
GiteaApiError,
|
||||
@@ -54,6 +55,33 @@ interface RawMilestoneFull {
|
||||
closed_issues: number
|
||||
}
|
||||
|
||||
/** The subset of a gitea timeline comment we read. */
|
||||
interface RawTimelineComment {
|
||||
type: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** gitea timeline `type` → our lifecycle signal. Unmapped types are dropped. */
|
||||
const TIMELINE_TYPE_MAP: Record<string, LifecycleEventType> = {
|
||||
label: 'triage',
|
||||
milestone: 'triage',
|
||||
assignees: 'triage',
|
||||
commit_ref: 'commit',
|
||||
pull_ref: 'pull',
|
||||
close: 'close',
|
||||
reopen: 'reopen',
|
||||
}
|
||||
|
||||
/** Map a raw gitea timeline to normalized lifecycle events. Pure. */
|
||||
export function normalizeTimeline(raw: RawTimelineComment[]): LifecycleEvent[] {
|
||||
const out: LifecycleEvent[] = []
|
||||
for (const c of raw) {
|
||||
const type = TIMELINE_TYPE_MAP[c.type]
|
||||
if (type && c.created_at) out.push({ type, at: c.created_at })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
export interface ListIssuesOptions {
|
||||
/** @default 'all' */
|
||||
state?: 'open' | 'closed' | 'all'
|
||||
@@ -68,6 +96,8 @@ export interface GiteaClient {
|
||||
listMilestones(): Promise<GiteaMilestone[]>
|
||||
/** The issue indices this issue depends on (its blockers). */
|
||||
getIssueDependencies(index: number): Promise<number[]>
|
||||
/** Normalized lifecycle events for one issue (all pages of its timeline). */
|
||||
getIssueTimeline(index: number): Promise<LifecycleEvent[]>
|
||||
}
|
||||
|
||||
/** Map raw gitea issue JSON to the normalized domain shape. Pure. */
|
||||
@@ -163,5 +193,12 @@ export function createGiteaClient(config: GiteaConfig, fetchImpl: FetchLike): Gi
|
||||
const raw = (await request(`/issues/${index}/dependencies`)) as { number: number }[]
|
||||
return raw.map((d) => d.number)
|
||||
},
|
||||
|
||||
async getIssueTimeline(index) {
|
||||
const raw = await requestAll<RawTimelineComment>(
|
||||
(page) => `/issues/${index}/timeline?page=${page}&limit=${PAGE_LIMIT}`,
|
||||
)
|
||||
return normalizeTimeline(raw)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user