Open History to see the last commit
1/**
2 * Shared types for the maintainer toolset (sweep + scorecard).
3 *
4 * The data layer (collect.ts) normalizes GitHub GraphQL responses into these
5 * shapes; everything downstream (classify.ts, route.ts, metrics.ts) is pure
6 * and operates only on these types, so it can be unit-tested with fixtures.
7 */
8
9export type CIState = 'success' | 'failure' | 'pending' | 'unknown'
10
11export interface TimelineEvent {
12 kind: 'comment' | 'review' | 'commit' | 'assigned' | 'review-requested'
13 /** GitHub login, or null when the account was deleted / unresolvable. */
14 actor: string | null
15 isBot: boolean
16 /** ISO timestamp. */
17 at: string
18 /** Only present for comments; used for bot-marker detection. */
19 body?: string
20 /** Only present for reviews: APPROVED | CHANGES_REQUESTED | COMMENTED | DISMISSED. */
21 reviewState?: string
22 /** Recipient of an assignment or review request (actor is the initiator). */
23 subject?: string | null
24}
25
26export interface PRItem {
27 type: 'pr'
28 number: number
29 title: string
30 url: string
31 author: string | null
32 authorIsBot: boolean
33 /** ISO timestamp of the author account creation, when resolvable. */
34 authorAccountCreatedAt: string | null
35 authorAssociation: string
36 createdAt: string
37 updatedAt: string
38 isDraft: boolean
39 /** MERGEABLE | CONFLICTING | UNKNOWN */
40 mergeable: string
41 /** '' | APPROVED | CHANGES_REQUESTED | REVIEW_REQUIRED */
42 reviewDecision: string
43 additions: number
44 deletions: number
45 changedFiles: number
46 /** All changed paths, paginated during collection. */
47 files: Array<string>
48 labels: Array<string>
49 assignees: Array<string>
50 requestedReviewers: Array<string>
51 ciState: CIState
52 /** Issue numbers this PR closes (via closingIssuesReferences). */
53 linkedIssues: Array<number>
54 timeline: Array<TimelineEvent>
55}
56
57export interface IssueItem {
58 type: 'issue'
59 number: number
60 title: string
61 url: string
62 author: string | null
63 authorIsBot: boolean
64 authorAssociation: string
65 createdAt: string
66 updatedAt: string
67 body: string
68 labels: Array<string>
69 assignees: Array<string>
70 timeline: Array<TimelineEvent>
71}
72
73export interface DiscussionItem {
74 type: 'discussion'
75 number: number
76 title: string
77 url: string
78 author: string | null
79 createdAt: string
80 updatedAt: string
81 isAnswered: boolean
82 category: string
83 upvotes: number
84 commentCount: number
85 /** Most recent comments (login + timestamp), newest last. */
86 comments: Array<{ actor: string | null; isBot: boolean; at: string }>
87}
88
89/** Minimal record of a recently closed PR/issue, for scorecard trend metrics. */
90export interface ClosedItem {
91 type: 'pr' | 'issue'
92 number: number
93 title: string
94 url: string
95 author: string | null
96 authorIsBot: boolean
97 createdAt: string
98 closedAt: string
99 /** Only for PRs; null when closed without merging. */
100 mergedAt: string | null
101 /** Changed paths for recent merged-PR area experience. */
102 files?: Array<string>
103 /** Comment/review and assignment/request events. */
104 timeline: Array<TimelineEvent>
105}
106
107export interface RepoSnapshot {
108 owner: string
109 repo: string
110 /** ISO timestamp the snapshot was taken. */
111 takenAt: string
112 /** CODEOWNERS from the default branch, never from PR code. */
113 codeowners: string
114 prs: Array<PRItem>
115 issues: Array<IssueItem>
116 discussions: Array<DiscussionItem>
117 /** PRs and issues closed within the lookback window (14 days). */
118 recentlyClosed: Array<ClosedItem>
119}
120
121// --- Configuration (.github/maintainers.json) ---
122
123export interface MaintainerEntry {
124 github: string
125 /** Discord user id (snowflake) for @-mentions in the digest; null → plain text. */
126 discord?: string | null
127 /** File globs this maintainer owns; used to route PR assignment. */
128 areas: Array<string>
129 /** Legacy setting, accepted for compatibility but no longer limits routing. */
130 maxOpenAssignments?: number
131}
132
133export interface SlaConfig {
134 /** Hours before an item with no maintainer response ever counts as breached. */
135 firstResponseHours: number
136 /** Hours to answer a follow-up message on an already-touched item. */
137 followUpResponseHours: number
138 /** Days of author silence before a waiting-on-author item counts as stale. */
139 staleAuthorDays: number
140}
141
142export interface SpamConfig {
143 /** Author accounts younger than this are eligible for the spam flag. */
144 maxAccountAgeDays: number
145 /** Diffs at or under this many changed lines are eligible for the spam flag. */
146 maxChangedLines: number
147}
148
149export interface ToolsetConfig {
150 /** owner/repo, e.g. "TanStack/ai". */
151 repo: string
152 maintainers: Array<MaintainerEntry>
153 sla: SlaConfig
154 spam: SpamConfig
155 /** Logins (without [bot] suffix) always treated as bots, e.g. "renovate". */
156 botAllowlist: Array<string>
157 /** Safety cap on comments posted per sweep run. */
158 maxCommentsPerRun: number
159}
160
161// --- Classification output ---
162
163export type WaitingOn = 'maintainer' | 'author' | 'nobody'
164
165export interface PRTriage {
166 item: PRItem
167 bot: boolean
168 rosterAuthor: boolean
169 firstTimeContributor: boolean
170 suspectedSpam: boolean
171 spamReasons: Array<string>
172 waitingOn: WaitingOn
173 waitingReason: string
174 readyToMerge: boolean
175 hasConflicts: boolean
176 ciFailing: boolean
177 missingChangeset: boolean
178 missingE2E: boolean
179 /** Last comment/review by a roster maintainer who isn't the PR author. */
180 lastMaintainerResponseAt: string | null
181 /** Last non-bot comment/commit by the author or a third party. */
182 lastContributorActivityAt: string | null
183 /** Oldest contributor message (or PR creation) still awaiting a maintainer reply. */
184 unansweredSince: string | null
185 /** Hours the oldest unanswered message has been waiting. */
186 unansweredHours: number | null
187 slaBreached: boolean
188 /** Hours from creation to first maintainer response; null if none yet. */
189 firstResponseHours: number | null
190 /** Contributor activity newer than the last maintainer response (which must exist). */
191 freshContributorReply: boolean
192 staleAuthor: boolean
193 hasAckComment: boolean
194 /** Set by the sweep when the PR is unassigned and routable. */
195 suggestedAssignee: string | null
196}
197
198export interface IssueTriage {
199 item: IssueItem
200 bot: boolean
201 rosterAuthor: boolean
202 waitingOn: WaitingOn
203 needsRepro: boolean
204 hasOpenPR: boolean
205 lastMaintainerResponseAt: string | null
206 lastContributorActivityAt: string | null
207 unansweredSince: string | null
208 unansweredHours: number | null
209 slaBreached: boolean
210 firstResponseHours: number | null
211 /** Contributor comment newer than the last maintainer response. */
212 freshContributorReply: boolean
213 staleAuthor: boolean
214 hasReproComment: boolean
215 suggestedAssignee: string | null
216}
217
218export interface DiscussionTriage {
219 item: DiscussionItem
220 /** True when unanswered and no roster maintainer has commented. */
221 needsAttention: boolean
222 /** Hours since the last comment (or creation) on a needs-attention discussion. */
223 waitingHours: number
224}
225
226export interface TriageResult {
227 prs: Array<PRTriage>
228 issues: Array<IssueTriage>
229 discussions: Array<DiscussionTriage>
230}