| 1 | import type { ChecksApi } from "./checks"; |
| 2 | import type { CodeownersReport, PullCodeOwners } from "./codeowners"; |
| 3 | import type { G1tEvent } from "./events"; |
| 4 | import type { User, Viewer } from "./identity"; |
| 5 | import type { PullBranchUpdate, RepoPath, UpdateMethod } from "./repos"; |
| 6 | import type { MergeMethod } from "./rules"; |
| 7 | import type { Result } from "./result"; |
| 8 | import type { MergeRules, RulesApi } from "./rules"; |
| 9 | |
| 10 | /** |
| 11 | * The filter on lists of issues and pull requests. An open pull request is |
| 12 | * a draft or one ready for review; a closed one was merged or closed |
| 13 | * without merging. |
| 14 | */ |
| 15 | export type State = "open" | "closed"; |
| 16 | |
| 17 | /** Why an issue was closed. */ |
| 18 | export type IssueReason = "completed" | "not_planned"; |
| 19 | |
| 20 | /** |
| 21 | * Something that should change in a repository: a bug, a feature, a |
| 22 | * question. Opened by a person, an agent or an integration. Pull requests |
| 23 | * are made against it; the one that is merged resolves it. |
| 24 | * |
| 25 | * Issues and pull requests share one sequence of numbers per repository. |
| 26 | */ |
| 27 | export type Issue = { |
| 28 | id: string; |
| 29 | repoId: string; |
| 30 | /** Shown as `#12`. */ |
| 31 | number: number; |
| 32 | title: string; |
| 33 | /** Markdown. Also what an agent is given to work from. */ |
| 34 | body: string; |
| 35 | labels: string[]; |
| 36 | state: State; |
| 37 | /** Set when closed. */ |
| 38 | reason: IssueReason | null; |
| 39 | /** The number of the pull request whose merge closed this issue. */ |
| 40 | resolvedBy: number | null; |
| 41 | /** The commit pushed to the default branch whose message closed this issue (`Closes #12`), when a commit rather than a pull request closed it. */ |
| 42 | resolvedCommit: string | null; |
| 43 | /** Who pushed that commit, by username. */ |
| 44 | resolvedPushedBy: string | null; |
| 45 | /** Who opened it: a person, an integration, or g1t (`kind` `agent`) for one its agent filed while at work. */ |
| 46 | author: User; |
| 47 | /** |
| 48 | * For an issue g1t's agent filed: the person it was working for. They may |
| 49 | * manage it as its author could. See `workOwner`. |
| 50 | */ |
| 51 | requestedBy: User | null; |
| 52 | /** RFC 3339. */ |
| 53 | createdAt: string; |
| 54 | /** RFC 3339. */ |
| 55 | updatedAt: string; |
| 56 | /** RFC 3339. */ |
| 57 | closedAt: string | null; |
| 58 | /** Pull requests made against this issue, in any state. */ |
| 59 | pullCount: number; |
| 60 | commentCount: number; |
| 61 | /** Usernames of the people it is assigned to. */ |
| 62 | assignees: string[]; |
| 63 | /** The numbers of the issues that have to be merged before this one is worked on. */ |
| 64 | blockedBy: number[]; |
| 65 | /** |
| 66 | * The agent working on it now: the one behind its newest pull request |
| 67 | * that is still in progress in a fork, such as `g1t`. |
| 68 | */ |
| 69 | agent: string | null; |
| 70 | /** The milestone it is in, if any. */ |
| 71 | milestone?: MilestoneRef | null; |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * A label of a repository: a name, a color and what it means. Issues and |
| 76 | * pull requests carry labels by name; names are lowercase. |
| 77 | */ |
| 78 | export type Label = { |
| 79 | name: string; |
| 80 | /** Six hex digits, without `#`. */ |
| 81 | color: string; |
| 82 | description: string; |
| 83 | /** How many issues carry it, open or closed. */ |
| 84 | issues: number; |
| 85 | /** How many pull requests carry it, in any state. */ |
| 86 | pulls: number; |
| 87 | }; |
| 88 | |
| 89 | /** A milestone, as an issue or pull request names it. */ |
| 90 | /** An issue a commit closed, as the commit page lists it. */ |
| 91 | export type ClosedIssue = { number: number; title: string }; |
| 92 | |
| 93 | export type MilestoneRef = { number: number; title: string }; |
| 94 | |
| 95 | /** |
| 96 | * A goal, with an optional due date, that issues and pull requests are |
| 97 | * gathered under. Its progress is how many of them are closed. |
| 98 | */ |
| 99 | export type Milestone = { |
| 100 | /** Numbered from 1 in each repository, apart from issues. */ |
| 101 | number: number; |
| 102 | title: string; |
| 103 | /** Markdown. */ |
| 104 | description: string; |
| 105 | /** `YYYY-MM-DD`. */ |
| 106 | dueOn: string | null; |
| 107 | state: State; |
| 108 | /** Open issues and pull requests in it. */ |
| 109 | openItems: number; |
| 110 | /** Closed issues, and merged or closed pull requests, in it. */ |
| 111 | closedItems: number; |
| 112 | createdAt: string; |
| 113 | updatedAt: string; |
| 114 | closedAt: string | null; |
| 115 | }; |
| 116 | |
| 117 | /** One milestone and what is in it, newest first. */ |
| 118 | export type MilestoneDetail = { milestone: Milestone; issues: Issue[]; pulls: Pull[] }; |
| 119 | |
| 120 | /** How `setLabels` changes an item's labels. */ |
| 121 | export type LabelChange = "set" | "add" | "remove"; |
| 122 | |
| 123 | /** |
| 124 | * Whose an issue or a pull request is to answer for: whoever asked g1t for |
| 125 | * it, or its author. They may change, close and steer it, are never asked to |
| 126 | * review it and cannot approve it, and see it as theirs. Mirrors |
| 127 | * `Pull::owner` in the Rust contracts. |
| 128 | */ |
| 129 | export function workOwner(item: Pick<Pull, "author" | "requestedBy">): User { |
| 130 | return item.requestedBy ?? item.author; |
| 131 | } |
| 132 | |
| 133 | /** `draft` is still being worked on; `open` is ready for review. */ |
| 134 | export type PullStatus = "draft" | "open" | "merged" | "closed"; |
| 135 | |
| 136 | /** Where the agent runs: on g1t's sandboxes, or in someone's own session. */ |
| 137 | export type Runtime = "hosted" | "external"; |
| 138 | |
| 139 | /** |
| 140 | * A proposed change. It is made either in a fork created for it, which is |
| 141 | * how agents work, on a branch pushed to the repository itself, or on a |
| 142 | * branch of someone's fork of it (`headRepo`). |
| 143 | */ |
| 144 | export type Pull = { |
| 145 | id: string; |
| 146 | repoId: string; |
| 147 | /** Shown as `#12`. */ |
| 148 | number: number; |
| 149 | /** The number of the issue this is for, if any. */ |
| 150 | issue: number | null; |
| 151 | title: string; |
| 152 | /** Markdown: what changed and why. Set when marked ready. */ |
| 153 | body: string | null; |
| 154 | /** A label for the agent doing the work, e.g. `claude-code`. */ |
| 155 | agent: string; |
| 156 | runtime: Runtime; |
| 157 | status: PullStatus; |
| 158 | /** The fork holding the change, unless it is on a branch. */ |
| 159 | fork: RepoPath | null; |
| 160 | /** The fork's repository id. */ |
| 161 | forkRepoId: string | null; |
| 162 | /** |
| 163 | * The branch holding the change, unless it is in a working copy (`fork`): |
| 164 | * of `headRepo` when set, else of the repository. |
| 165 | */ |
| 166 | branch: string | null; |
| 167 | /** |
| 168 | * A fork of the repository (its `parentId`, directly or through other |
| 169 | * forks) whose `branch` holds the change, when it was opened from one. |
| 170 | * Null for a branch of the repository itself and for a working copy. |
| 171 | */ |
| 172 | headRepo?: RepoPath | null; |
| 173 | /** `headRepo`'s id. */ |
| 174 | headRepoId?: string | null; |
| 175 | headCommit: string | null; |
| 176 | /** |
| 177 | * For a merged pull request, what the branch pointed to before the merge. |
| 178 | * Comparing against it shows what the pull request changed. |
| 179 | */ |
| 180 | mergeBase: string | null; |
| 181 | /** Username of whoever merged it. */ |
| 182 | mergedBy: string | null; |
| 183 | /** RFC 3339. */ |
| 184 | mergedAt: string | null; |
| 185 | /** How it merged, once merged. */ |
| 186 | mergeMethod?: MergeMethod | null; |
| 187 | /** Where its merge left the base: the merge or squash commit, the last rebased one, or its head. */ |
| 188 | mergeCommit?: string | null; |
| 189 | /** Merge it on its own once everything it needs is met, as a person asked. */ |
| 190 | autoMerge?: AutoMerge | null; |
| 191 | /** |
| 192 | * The issues it closes when it merges into the default branch: its issue and |
| 193 | * those its title and description name after a closing keyword (`Fixes #12`). |
| 194 | */ |
| 195 | closes?: number[]; |
| 196 | /** Its branch was deleted after it merged or closed, and can be restored at `headCommit`. */ |
| 197 | headBranchDeleted?: boolean; |
| 198 | /** |
| 199 | * Set on a pull request closed because another one for the same issue was |
| 200 | * merged: that one's number. |
| 201 | */ |
| 202 | supersededBy: number | null; |
| 203 | /** |
| 204 | * Where the latest run of the issue's acceptance checks stands, if there |
| 205 | * has been one against the current head. |
| 206 | */ |
| 207 | checkStatus: CheckStatus | null; |
| 208 | /** The files it changes, as of its latest push. */ |
| 209 | files: ChangedFile[]; |
| 210 | /** Usernames of the people it is assigned to. */ |
| 211 | assignees: string[]; |
| 212 | /** |
| 213 | * Those whose review was asked for: usernames, and `g1t` when a g1t |
| 214 | * agent was asked. |
| 215 | */ |
| 216 | reviewers: string[]; |
| 217 | /** |
| 218 | * Teams whose review was asked for, as `workspace/slug`. A team stays here |
| 219 | * after review assignment picks people from it, who are in `reviewers`. |
| 220 | */ |
| 221 | teamReviewers?: string[]; |
| 222 | /** The labels it carries, by name. */ |
| 223 | labels?: string[]; |
| 224 | /** The milestone it is in, if any. */ |
| 225 | milestone?: MilestoneRef | null; |
| 226 | /** |
| 227 | * The branch it merges into. Lists and `getPull` name it; null only in |
| 228 | * what services pass between themselves, for the default branch. |
| 229 | */ |
| 230 | base?: string | null; |
| 231 | /** Who opened it: a person, or g1t (`kind` `agent`, username `g1t`) for a change g1t made. */ |
| 232 | author: User; |
| 233 | /** |
| 234 | * For a change g1t made: the person who asked for it, by assigning an issue |
| 235 | * or handing g1t the work. They answer for it as its author would. See |
| 236 | * `workOwner`. |
| 237 | */ |
| 238 | requestedBy: User | null; |
| 239 | /** RFC 3339. */ |
| 240 | createdAt: string; |
| 241 | /** RFC 3339. */ |
| 242 | updatedAt: string; |
| 243 | /** Who last moved its head (a user id), and when; absent until a push after rulesets arrived. */ |
| 244 | headPushedBy?: string; |
| 245 | headPushedAt?: string; |
| 246 | }; |
| 247 | |
| 248 | /** One file a pull request changes, and by how much. */ |
| 249 | export type ChangedFile = { path: string; additions: number; deletions: number }; |
| 250 | |
| 251 | /** |
| 252 | * Another pull request in progress that changes some of the same files. Two |
| 253 | * for the same issue are alternatives; two for different issues are heading |
| 254 | * for a conflict. |
| 255 | */ |
| 256 | export type Overlap = { |
| 257 | number: number; |
| 258 | title: string; |
| 259 | /** The number of the issue the other pull request is for. */ |
| 260 | issue: number | null; |
| 261 | /** The files both change. */ |
| 262 | paths: string[]; |
| 263 | }; |
| 264 | |
| 265 | /** |
| 266 | * On a pull request, `failed` means the merge queue took it out, until its |
| 267 | * head moves. The other states are from runs of commands written on issues, |
| 268 | * which g1t no longer runs. |
| 269 | */ |
| 270 | export type CheckStatus = "queued" | "running" | "passed" | "failed" | "errored"; |
| 271 | |
| 272 | /** How one command went, in a run recorded before checks were workflows. */ |
| 273 | export type CheckResult = { |
| 274 | command: string; |
| 275 | passed: boolean; |
| 276 | /** Null when the command was stopped for taking too long. */ |
| 277 | exitCode: number | null; |
| 278 | /** What the command printed; the end of it, when there was a lot. */ |
| 279 | output: string; |
| 280 | durationMs: number; |
| 281 | }; |
| 282 | |
| 283 | /** |
| 284 | * A record against a pull request's head: the merge queue taking it out, |
| 285 | * with why, or an earlier run of commands written on its issue. |
| 286 | */ |
| 287 | export type CheckRun = { |
| 288 | id: string; |
| 289 | /** The commit that was checked. */ |
| 290 | headCommit: string; |
| 291 | status: CheckStatus; |
| 292 | results: CheckResult[]; |
| 293 | /** Why the checks could not be run, when `status` is `errored`. */ |
| 294 | error: string | null; |
| 295 | /** RFC 3339. */ |
| 296 | createdAt: string; |
| 297 | /** RFC 3339. */ |
| 298 | finishedAt: string | null; |
| 299 | }; |
| 300 | |
| 301 | /** A reviewer's decision on a pull request. */ |
| 302 | export type Verdict = "approve" | "request_changes"; |
| 303 | |
| 304 | /** |
| 305 | * A comment on an issue or a pull request. On a pull request it can sit on |
| 306 | * one line of the change, and it can carry a reviewer's verdict. |
| 307 | */ |
| 308 | export type Comment = { |
| 309 | id: string; |
| 310 | /** |
| 311 | * Something a person or an agent wrote, or something that happened: an |
| 312 | * assignment, a review asked for, a close. |
| 313 | */ |
| 314 | kind: "comment" | "event"; |
| 315 | author: User; |
| 316 | /** |
| 317 | * Markdown. For an event, what its author did, as the rest of a sentence |
| 318 | * that starts with their name: "assigned ana". |
| 319 | */ |
| 320 | body: string; |
| 321 | /** The file commented on, for a comment on a line. */ |
| 322 | path: string | null; |
| 323 | /** The line of that file, as numbered after the change. */ |
| 324 | line: number | null; |
| 325 | verdict: Verdict | null; |
| 326 | /** RFC 3339. */ |
| 327 | createdAt: string; |
| 328 | /** When its text was last edited, RFC 3339; absent if it never was. */ |
| 329 | editedAt?: string; |
| 330 | /** |
| 331 | * Set when one of the workspace's agents wrote it, as itself. `author` |
| 332 | * is then the agent (its id, its handle as `username`, kind `agent`): |
| 333 | * show it by `agent.displayName` with an Agent badge, never as a person. |
| 334 | */ |
| 335 | agent?: AgentRef; |
| 336 | /** Who the agent acted for, whose access capped it. Set with `agent`. */ |
| 337 | actingFor?: User; |
| 338 | /** |
| 339 | * An agent's review. Its `verdict` (none for a review that only |
| 340 | * comments) is shown but advisory: it never counts toward required |
| 341 | * approvals or code owners, and never blocks a merge. |
| 342 | */ |
| 343 | advisory?: boolean; |
| 344 | /** How people (and g1t) reacted to it. Absent when nobody has. */ |
| 345 | reactions?: ReactionGroup[]; |
| 346 | }; |
| 347 | |
| 348 | /** An emoji reaction: the same eight as everywhere else people react to code. */ |
| 349 | export type ReactionContent = "+1" | "-1" | "laugh" | "hooray" | "confused" | "heart" | "rocket" | "eyes"; |
| 350 | |
| 351 | /** The reactions, in the order they are offered, with the emoji each shows. */ |
| 352 | export const REACTIONS: { content: ReactionContent; emoji: string; label: string }[] = [ |
| 353 | { content: "+1", emoji: "👍", label: "Thumbs up" }, |
| 354 | { content: "-1", emoji: "👎", label: "Thumbs down" }, |
| 355 | { content: "laugh", emoji: "😄", label: "Laugh" }, |
| 356 | { content: "hooray", emoji: "🎉", label: "Hooray" }, |
| 357 | { content: "confused", emoji: "😕", label: "Confused" }, |
| 358 | { content: "heart", emoji: "❤️", label: "Heart" }, |
| 359 | { content: "rocket", emoji: "🚀", label: "Rocket" }, |
| 360 | { content: "eyes", emoji: "👀", label: "Eyes" }, |
| 361 | ]; |
| 362 | |
| 363 | /** Everyone who reacted one way to the same thing, first to react first; `g1t` for g1t. */ |
| 364 | export type ReactionGroup = { |
| 365 | content: ReactionContent; |
| 366 | count: number; |
| 367 | users: string[]; |
| 368 | }; |
| 369 | |
| 370 | /** |
| 371 | * One of a workspace's own agents, as a comment or review it wrote before |
| 372 | * g1t's agents were removed shows it: Margo (@margo), with the face drawn |
| 373 | * from `avatarSeed`. Kept so those comments still render. |
| 374 | */ |
| 375 | export type AgentRef = { |
| 376 | id: string; |
| 377 | handle: string; |
| 378 | displayName: string; |
| 379 | avatarSeed: string; |
| 380 | }; |
| 381 | |
| 382 | export type NewComment = { |
| 383 | /** May be empty when approving. */ |
| 384 | body: string; |
| 385 | path?: string; |
| 386 | line?: number; |
| 387 | verdict?: Verdict; |
| 388 | }; |
| 389 | |
| 390 | export type CheckReport = { results?: CheckResult[]; error?: string; skip?: boolean }; |
| 391 | |
| 392 | export type SessionEntryKind = "prompt" | "message" | "tool_call" | "tool_result" | "note" | "skill"; |
| 393 | |
| 394 | /** One step of an agent's session: the "why" behind a pull request's commits. */ |
| 395 | export type SessionEntry = { |
| 396 | seq: number; |
| 397 | kind: SessionEntryKind; |
| 398 | text: string; |
| 399 | /** For tool calls and results. */ |
| 400 | tool: string | null; |
| 401 | /** The fork's head commit when this entry was recorded, if known. */ |
| 402 | commit: string | null; |
| 403 | /** RFC 3339. */ |
| 404 | at: string; |
| 405 | }; |
| 406 | |
| 407 | export type NewSessionEntry = Pick<SessionEntry, "kind" | "text"> & |
| 408 | Partial<Pick<SessionEntry, "tool" | "commit">>; |
| 409 | |
| 410 | export type IssueDetail = { |
| 411 | issue: Issue; |
| 412 | /** Every pull request made against it, oldest first. */ |
| 413 | pulls: Pull[]; |
| 414 | comments: Comment[]; |
| 415 | /** How people (and g1t) reacted to its description. */ |
| 416 | reactions: ReactionGroup[]; |
| 417 | }; |
| 418 | |
| 419 | export type PullDetail = { |
| 420 | pull: Pull; |
| 421 | /** The issue it is for, if any. */ |
| 422 | issue: Issue | null; |
| 423 | comments: Comment[]; |
| 424 | /** How people (and g1t) reacted to its description. */ |
| 425 | reactions: ReactionGroup[]; |
| 426 | /** The latest record against its head: the merge queue taking it out. */ |
| 427 | checks: CheckRun | null; |
| 428 | /** Other pull requests in progress that change the same files. */ |
| 429 | overlaps: Overlap[]; |
| 430 | /** |
| 431 | * Whether the branch it would merge into has moved on without it, so that |
| 432 | * it has to catch up before it can merge. |
| 433 | */ |
| 434 | behind: boolean; |
| 435 | /** |
| 436 | * Where it stands on its way to being merged, for a pull request g1t is |
| 437 | * seeing through. Null on anyone else's. |
| 438 | */ |
| 439 | lifecycle: Lifecycle | null; |
| 440 | /** |
| 441 | * A merge was asked for while it was behind: g1t is bringing it up to |
| 442 | * date and will then land it. |
| 443 | */ |
| 444 | landing: boolean; |
| 445 | /** Why g1t stopped working on it, if it did. */ |
| 446 | stalled: string | null; |
| 447 | /** What workflow runs said about its head commit, one per workflow. */ |
| 448 | statuses?: CommitStatus[]; |
| 449 | /** |
| 450 | * Whether it merges cleanly into the branch it targets, worked out ahead |
| 451 | * of time whenever either side moves. |
| 452 | */ |
| 453 | mergeable?: Mergeable; |
| 454 | /** When `mergeable` is `conflicting`: the files that conflict. */ |
| 455 | conflicts?: string[]; |
| 456 | /** Earlier records like `checks`, newest first, without their output. */ |
| 457 | earlierChecks?: CheckRun[]; |
| 458 | /** |
| 459 | * The checks the default branch's protection requires, each as it stands |
| 460 | * on the head commit. Empty when none are required. |
| 461 | */ |
| 462 | requiredChecks?: RequiredCheck[]; |
| 463 | /** |
| 464 | * Who owns the files it changes (the CODEOWNERS file of the branch it |
| 465 | * merges into) and whose approval is still needed. Absent without one. |
| 466 | */ |
| 467 | codeOwners?: PullCodeOwners | null; |
| 468 | /** |
| 469 | * The rules of the branch it merges into it does not meet yet, for whoever |
| 470 | * is looking: what refuses the merge, what they may bypass, and what rulesets |
| 471 | * in evaluate would refuse. Absent once it is closed or merged. |
| 472 | */ |
| 473 | rules?: MergeRules | null; |
| 474 | }; |
| 475 | |
| 476 | /** Where a required check stands on a commit; `expected` when nothing has reported it yet. */ |
| 477 | export type RequiredState = "success" | "failure" | "pending" | "expected"; |
| 478 | |
| 479 | /** One check a branch's protection requires, as it stands on a commit. */ |
| 480 | export type RequiredCheck = { |
| 481 | /** A workflow's name, such as `CI`, or another status's context. */ |
| 482 | name: string; |
| 483 | state: RequiredState; |
| 484 | description: string | null; |
| 485 | /** Where to see more: the workflow run, for one a workflow reported. */ |
| 486 | targetUrl: string | null; |
| 487 | }; |
| 488 | |
| 489 | /** A check name reported on a repository's commits lately, for choosing required checks. */ |
| 490 | export type SeenCheck = { |
| 491 | name: string; |
| 492 | /** The events it was reported for, such as `pull_request`; empty for a status that names none. */ |
| 493 | events: string[]; |
| 494 | /** RFC 3339. */ |
| 495 | lastSeen: string; |
| 496 | }; |
| 497 | |
| 498 | /** |
| 499 | * A status context's check name: `CI / pull_request` is the `CI` check, |
| 500 | * reported for a `pull_request` event. A context that does not end in an |
| 501 | * event, such as `g1t / deploy`, is its own name. As the work service reads it. |
| 502 | */ |
| 503 | export function checkName(context: string): string { |
| 504 | const at = context.lastIndexOf(" / "); |
| 505 | if (at <= 0) return context; |
| 506 | return STATUS_EVENTS.has(context.slice(at + 3)) ? context.slice(0, at) : context; |
| 507 | } |
| 508 | |
| 509 | const STATUS_EVENTS = new Set([ |
| 510 | "push", |
| 511 | "pull_request", |
| 512 | "pull_request_target", |
| 513 | "pull_request_review", |
| 514 | "merge_group", |
| 515 | "workflow_dispatch", |
| 516 | "workflow_run", |
| 517 | "workflow_call", |
| 518 | "schedule", |
| 519 | "release", |
| 520 | "issues", |
| 521 | "issue_comment", |
| 522 | "repository_dispatch", |
| 523 | ]); |
| 524 | |
| 525 | /** |
| 526 | * Whether a pull request merges cleanly into the branch it targets: |
| 527 | * `unknown` when it was never worked out or could not be, `checking` while |
| 528 | * a probe merges the two. |
| 529 | */ |
| 530 | export type Mergeable = "clean" | "conflicting" | "unknown" | "checking"; |
| 531 | |
| 532 | /** What a sandbox needs to find out whether a pull request merges cleanly. */ |
| 533 | export type MergecheckJob = { |
| 534 | pullId: string; |
| 535 | /** Lets the sandbox, and nothing else, report this probe. */ |
| 536 | token: string; |
| 537 | repo: RepoPath; |
| 538 | number: number; |
| 539 | defaultBranch: string; |
| 540 | /** The default branch's commit to merge into. */ |
| 541 | base: string; |
| 542 | /** The repository holding the change: its fork, or the repository. */ |
| 543 | source: RepoPath; |
| 544 | /** The branch of `source` holding it. */ |
| 545 | branch: string; |
| 546 | /** The change's commit. */ |
| 547 | head: string; |
| 548 | /** Who the pull request is for (`workOwner`: whoever asked g1t for it, or its author), and so can read its source. */ |
| 549 | author: User; |
| 550 | }; |
| 551 | |
| 552 | /** What a workflow run (or another tool) says about a commit. */ |
| 553 | export type CommitStatus = { |
| 554 | /** What reported it, such as `CI / push`. */ |
| 555 | context: string; |
| 556 | state: "pending" | "success" | "failure" | "error"; |
| 557 | description: string | null; |
| 558 | targetUrl: string | null; |
| 559 | updatedAt: string; |
| 560 | /** The integration that reported it: `actions`, `deployments`, `security`, `g1t` or `api`. */ |
| 561 | source?: string; |
| 562 | /** Set on the status a check run stands as: the check run's id. */ |
| 563 | checkRunId?: string; |
| 564 | }; |
| 565 | |
| 566 | /** |
| 567 | * A step on the way from an assigned issue to a pull request that is ready |
| 568 | * to merge. g1t takes each one without being asked: `working` (the agent is |
| 569 | * making the change), `checking`, `reviewing`, `revising` (the agent is |
| 570 | * addressing failed checks or a review), `catching_up` (merging in the |
| 571 | * branch it would land on), `answering` (woken to answer another agent), |
| 572 | * then `ready` for a person to merge. `needs_you` |
| 573 | * means g1t has stopped and a person decides what happens next. |
| 574 | */ |
| 575 | export type Stage = |
| 576 | | "working" |
| 577 | | "checking" |
| 578 | | "reviewing" |
| 579 | | "revising" |
| 580 | | "catching_up" |
| 581 | | "answering" |
| 582 | | "queued" |
| 583 | | "ready" |
| 584 | | "needs_you"; |
| 585 | |
| 586 | export type Lifecycle = { |
| 587 | stage: Stage; |
| 588 | /** One sentence saying what is happening, or why it stopped. */ |
| 589 | detail: string; |
| 590 | /** How many times the agent has been sent back to revise it. */ |
| 591 | revisions: number; |
| 592 | }; |
| 593 | |
| 594 | /** |
| 595 | * How a repository wants its pull requests handled. A repository that has |
| 596 | * changed nothing has the defaults. |
| 597 | */ |
| 598 | export type RepoSettings = { |
| 599 | /** |
| 600 | * Land a g1t agent's pull request without a person once it is ready: |
| 601 | * checks passed and approved as the settings below require. |
| 602 | */ |
| 603 | autoMerge: boolean; |
| 604 | /** |
| 605 | * The checks that must pass on a pull request's head before it may merge |
| 606 | * into the default branch, by name: a workflow's name (`CI`) or another |
| 607 | * status's context (`g1t / deploy`). The same for people and agents, and |
| 608 | * for the merge queue. |
| 609 | */ |
| 610 | requiredChecks: string[]; |
| 611 | /** |
| 612 | * Refuse to merge a pull request that does not contain the default |
| 613 | * branch's latest commits, so that what merges is what was checked. When |
| 614 | * off, merging one that is behind brings it up to date first. |
| 615 | */ |
| 616 | requireUpToDate: boolean; |
| 617 | /** |
| 618 | * How many approving reviews a pull request needs before it may merge. A |
| 619 | * reviewer who has since asked for changes blocks it. |
| 620 | */ |
| 621 | requiredApprovals: number; |
| 622 | /** Whether a g1t agent's approval counts towards `requiredApprovals`. */ |
| 623 | countAgentApprovals: boolean; |
| 624 | /** Whether someone who may merge can bypass required checks that have not passed. */ |
| 625 | allowIgnoringChecks: boolean; |
| 626 | /** |
| 627 | * Merge through a queue: pull requests are tested together with those |
| 628 | * ahead of them, and only a combination that passed reaches the default |
| 629 | * branch. |
| 630 | */ |
| 631 | mergeQueue: boolean; |
| 632 | /** |
| 633 | * Refuse to merge until the code owners of every file it changes have |
| 634 | * approved, as many as each section asks. People only; `g1t` only where |
| 635 | * the file names `@g1t`. |
| 636 | */ |
| 637 | requireCodeOwnerReview?: boolean; |
| 638 | /** |
| 639 | * Whether issues can be opened in it: null for the default, which is on |
| 640 | * for a repository and off for a fork of one. Existing issues stay |
| 641 | * readable either way. |
| 642 | */ |
| 643 | hasIssues?: boolean | null; |
| 644 | /** Whether issues can be opened in it now: `hasIssues`, or its default. */ |
| 645 | issuesEnabled?: boolean; |
| 646 | /** Which merge methods pull requests may use (at least one); rules can narrow them per branch. */ |
| 647 | allowMergeCommit: boolean; |
| 648 | allowSquashMerge: boolean; |
| 649 | allowRebaseMerge: boolean; |
| 650 | allowFastForward: boolean; |
| 651 | /** The method offered first, and used when none is named. */ |
| 652 | defaultMergeMethod: MergeMethod; |
| 653 | /** What merge and squash commits say unless their merger writes it. */ |
| 654 | mergeCommitMessage: CommitMessageDefault; |
| 655 | squashCommitMessage: CommitMessageDefault; |
| 656 | /** |
| 657 | * For `custom`: templates whose `{title}`, `{number}`, `{body}`, `{branch}`, |
| 658 | * `{head_repo}`, `{base}`, `{author}`, `{commits}`, `{issues}` and |
| 659 | * `{co_authors}` are filled in. |
| 660 | */ |
| 661 | mergeCommitTemplate: string | null; |
| 662 | squashCommitTemplate: string | null; |
| 663 | /** Offer to bring a pull request up to date whenever its base has new commits. */ |
| 664 | suggestUpdatingBranches: boolean; |
| 665 | /** Let people turn on auto-merge for a pull request. */ |
| 666 | allowAutoMerge: boolean; |
| 667 | /** Delete a pull request's branch once it merges (restorable from it). */ |
| 668 | deleteBranchOnMerge: boolean; |
| 669 | /** Commits made on g1t.sh carry a `Signed-off-by:` trailer for whoever made them. */ |
| 670 | requireWebCommitSignOff: boolean; |
| 671 | /** Let anyone who can read it comment on its commits. */ |
| 672 | allowCommitComments: boolean; |
| 673 | /** Close the issues a pull request names when it merges into the default branch. */ |
| 674 | autoCloseIssues: boolean; |
| 675 | /** Username of the member who last changed the settings, if anyone has. */ |
| 676 | updatedBy: string | null; |
| 677 | /** RFC 3339. */ |
| 678 | updatedAt: string | null; |
| 679 | }; |
| 680 | |
| 681 | /** What a merge or squash commit's message says by default (`pull_title_and_commits` is squash only). */ |
| 682 | export type CommitMessageDefault = "default" | "pull_title" | "pull_title_and_description" | "pull_title_and_commits" | "custom"; |
| 683 | |
| 684 | /** A person's request that a pull request merge on its own once it may. */ |
| 685 | export type AutoMerge = { |
| 686 | method: MergeMethod; |
| 687 | commitTitle: string | null; |
| 688 | commitMessage: string | null; |
| 689 | /** Username of who asked. */ |
| 690 | enabledBy: string; |
| 691 | /** RFC 3339. */ |
| 692 | enabledAt: string; |
| 693 | }; |
| 694 | |
| 695 | /** A comment on a commit, or on one line (`path`, `line`) of a file it changed. */ |
| 696 | export type CommitComment = { |
| 697 | id: string; |
| 698 | repoId: string; |
| 699 | /** The commit's full hash. */ |
| 700 | commit: string; |
| 701 | path: string | null; |
| 702 | line: number | null; |
| 703 | /** Username. */ |
| 704 | author: string; |
| 705 | /** Markdown. */ |
| 706 | body: string; |
| 707 | /** RFC 3339. */ |
| 708 | createdAt: string; |
| 709 | updatedAt: string | null; |
| 710 | }; |
| 711 | |
| 712 | /** How a pull request may merge now, for whoever is looking (`mergeChoices`). */ |
| 713 | export type MergeChoices = { |
| 714 | /** The methods it may merge by: the repository's, as the rules for its base allow. In the order offered. */ |
| 715 | methods: MergeMethod[]; |
| 716 | /** The one offered first: the repository's default when it may be used, else the first of `methods`. */ |
| 717 | defaultMethod: MergeMethod | null; |
| 718 | /** Each of `methods`, with its default commit message and whether it can be used now. */ |
| 719 | options: MergeChoice[]; |
| 720 | /** Its base has commits it does not have. */ |
| 721 | behind: boolean; |
| 722 | /** It contains its base's head, so it can fast-forward as it is. */ |
| 723 | canFastForward: boolean; |
| 724 | /** Offer to bring it up to date: it is behind, and the repository suggests (or requires) it. */ |
| 725 | suggestUpdate: boolean; |
| 726 | /** The repository requires it to be up to date before it merges. */ |
| 727 | requireUpToDate: boolean; |
| 728 | /** It merges through the merge queue, which lands it as tested whatever method is chosen. */ |
| 729 | mergeQueue: boolean; |
| 730 | /** The viewer may turn on auto-merge for it. */ |
| 731 | autoMergeAllowed: boolean; |
| 732 | /** Whether "delete the branch" starts ticked. */ |
| 733 | deleteBranchDefault: boolean; |
| 734 | /** Its branch can be deleted once it merges (never a working copy's). */ |
| 735 | canDeleteBranch: boolean; |
| 736 | /** Commits made merging it carry a `Signed-off-by:` trailer for the merger. */ |
| 737 | signOff: boolean; |
| 738 | }; |
| 739 | |
| 740 | /** One way a pull request may merge. */ |
| 741 | export type MergeChoice = { |
| 742 | method: MergeMethod; |
| 743 | /** For `merge` and `squash`: the commit's default title and the rest of its message. */ |
| 744 | commitTitle: string | null; |
| 745 | commitMessage: string | null; |
| 746 | /** Why it cannot merge this way now, if it cannot. */ |
| 747 | unavailable: string | null; |
| 748 | }; |
| 749 | |
| 750 | /** How a pull request merges, as the merger chose. */ |
| 751 | export type MergeOptions = { |
| 752 | keepIssueOpen?: boolean; |
| 753 | /** Merge although required checks have not passed, where the rule requiring them allows it. */ |
| 754 | ignoreChecks?: boolean; |
| 755 | /** Merge past rules a ruleset lets the actor bypass. Recorded as a bypass. */ |
| 756 | bypassRules?: boolean; |
| 757 | /** The repository's default when absent. */ |
| 758 | mergeMethod?: MergeMethod; |
| 759 | /** For `merge` and `squash`: the commit's title and the rest of its message. */ |
| 760 | commitTitle?: string; |
| 761 | commitMessage?: string; |
| 762 | /** Refuse if its head is no longer this commit. */ |
| 763 | expectedHead?: string; |
| 764 | /** Delete its branch once merged; the repository's setting when absent. */ |
| 765 | deleteBranch?: boolean; |
| 766 | }; |
| 767 | |
| 768 | /** The settings a member can change. */ |
| 769 | export type RepoSettingsInput = Omit<RepoSettings, "updatedBy" | "updatedAt" | "issuesEnabled">; |
| 770 | |
| 771 | /** |
| 772 | * What the runner is to do next for a pull request: always nothing now, |
| 773 | * since no step of a pull request is carried out in a sandbox any more. |
| 774 | */ |
| 775 | export type Advance = { action: "none" }; |
| 776 | |
| 777 | export type OpenIssueInput = { |
| 778 | title: string; |
| 779 | body: string; |
| 780 | labels?: string[]; |
| 781 | /** Deprecated: commands, added to the body under "Definition of done". */ |
| 782 | checks?: string[]; |
| 783 | /** The number of the milestone to put it in. Needs the Triage role. */ |
| 784 | milestone?: number; |
| 785 | }; |
| 786 | |
| 787 | export type UpdateIssueInput = { |
| 788 | title?: string; |
| 789 | body?: string; |
| 790 | labels?: string[]; |
| 791 | /** Usernames of the people it is assigned to; replaces the whole set. */ |
| 792 | assignees?: string[]; |
| 793 | /** The number of the milestone to put it in; 0 takes it out. */ |
| 794 | milestone?: number; |
| 795 | /** The issues of the same repository that have to land first; replaces the whole set. */ |
| 796 | blocked_by?: number[]; |
| 797 | }; |
| 798 | |
| 799 | export type OpenPullInput = { |
| 800 | /** The number of the issue this is for. */ |
| 801 | issue?: number; |
| 802 | /** Defaults to the issue's title; required without an issue. */ |
| 803 | title?: string; |
| 804 | /** What changed and why. Usually set later, when a draft is marked ready. */ |
| 805 | body?: string; |
| 806 | /** |
| 807 | * A branch of the repository that already holds the change. The pull |
| 808 | * request is then ready for review at once and has no fork. |
| 809 | */ |
| 810 | branch?: string; |
| 811 | /** |
| 812 | * A fork of the repository (directly or through other forks) whose |
| 813 | * `branch` holds the change. Needs `branch`. |
| 814 | */ |
| 815 | headRepo?: RepoPath; |
| 816 | agent: string; |
| 817 | runtime: Runtime; |
| 818 | /** The branch to merge into: the default branch when left out. */ |
| 819 | base?: string; |
| 820 | /** |
| 821 | * Opened from a branch as a draft, still being worked on: it can't merge |
| 822 | * until it is marked ready. |
| 823 | */ |
| 824 | draft?: boolean; |
| 825 | }; |
| 826 | |
| 827 | /** One repository's pull requests from `pullsForRepos`, newest first. */ |
| 828 | export type RepoPulls = { |
| 829 | repoId: string; |
| 830 | /** Draft and open. */ |
| 831 | open: Pull[]; |
| 832 | /** Merged and closed. */ |
| 833 | closed: Pull[]; |
| 834 | }; |
| 835 | |
| 836 | /** Issues, pull requests, comments and sessions. */ |
| 837 | export interface WorkApi extends RulesApi, ChecksApi, CoordinationApi { |
| 838 | openIssue(actor: User, repo: RepoPath, input: OpenIssueInput): Promise<Result<Issue>>; |
| 839 | /** Newest first. */ |
| 840 | listIssues( |
| 841 | repo: RepoPath, |
| 842 | viewer: Viewer, |
| 843 | filter?: { state?: State; label?: string; milestone?: number }, |
| 844 | ): Promise<Result<Issue[]>>; |
| 845 | getIssue(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<IssueDetail>>; |
| 846 | /** The issues of the repository, of those the viewer may read, that this commit's message closed when it was pushed to the default branch. */ |
| 847 | closedByCommit(repo: RepoPath, commit: string, viewer: Viewer): Promise<Result<ClosedIssue[]>>; |
| 848 | /** The author or a member of the workspace may. */ |
| 849 | updateIssue(actor: User, repo: RepoPath, number: number, input: UpdateIssueInput): Promise<Result<Issue>>; |
| 850 | closeIssue(actor: User, repo: RepoPath, number: number, reason?: IssueReason): Promise<Result<Issue>>; |
| 851 | reopenIssue(actor: User, repo: RepoPath, number: number): Promise<Result<Issue>>; |
| 852 | /** A repository's labels, by name, each with how many issues and pull requests carry it. */ |
| 853 | listLabels(repo: RepoPath, viewer: Viewer): Promise<Result<Label[]>>; |
| 854 | /** |
| 855 | * Creates a label, or with `name` changes one; renaming it renames it on |
| 856 | * everything that carries it. Needs the Triage role. |
| 857 | */ |
| 858 | saveLabel( |
| 859 | actor: User, |
| 860 | repo: RepoPath, |
| 861 | label: { name?: string; newName?: string; color?: string; description?: string }, |
| 862 | ): Promise<Result<Label>>; |
| 863 | /** Removes a label from the repository and everything carrying it. */ |
| 864 | deleteLabel(actor: User, repo: RepoPath, name: string): Promise<Result<boolean>>; |
| 865 | /** Adds the default labels the repository does not have yet; returns them all. */ |
| 866 | addDefaultLabels(actor: User, repo: RepoPath): Promise<Result<Label[]>>; |
| 867 | /** |
| 868 | * The labels of an issue or a pull request, replaced, added to or taken |
| 869 | * from. Labels the repository lacks are created for someone with the |
| 870 | * Triage role. Returns its labels now. |
| 871 | */ |
| 872 | setLabels( |
| 873 | actor: User, |
| 874 | repo: RepoPath, |
| 875 | number: number, |
| 876 | labels: string[], |
| 877 | change?: LabelChange, |
| 878 | ): Promise<Result<string[]>>; |
| 879 | /** Open ones by due date, then closed ones; both unless `state` says. */ |
| 880 | listMilestones(repo: RepoPath, viewer: Viewer, state?: State): Promise<Result<Milestone[]>>; |
| 881 | getMilestone(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<MilestoneDetail>>; |
| 882 | /** Creates a milestone, or with `number` changes the fields given. Needs the Triage role. */ |
| 883 | saveMilestone( |
| 884 | actor: User, |
| 885 | repo: RepoPath, |
| 886 | milestone: { number?: number; title?: string; description?: string; dueOn?: string; state?: State }, |
| 887 | ): Promise<Result<Milestone>>; |
| 888 | deleteMilestone(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>; |
| 889 | /** How many issues and pull requests are open. */ |
| 890 | counts(repo: RepoPath, viewer: Viewer): Promise<Result<{ issues: number; pulls: number }>>; |
| 891 | |
| 892 | /** |
| 893 | * On an issue or a pull request. On a pull request it may name a line of |
| 894 | * the change and carry a verdict; nobody can give a verdict on their own. |
| 895 | */ |
| 896 | addComment(actor: User, repo: RepoPath, number: number, comment: NewComment): Promise<Result<Comment>>; |
| 897 | /** |
| 898 | * Changes a comment's text. Its author may, and so may anyone with the |
| 899 | * Maintain role or higher; notes of what happened cannot be changed. |
| 900 | */ |
| 901 | editComment(actor: User, repo: RepoPath, commentId: string, body: string): Promise<Result<Comment>>; |
| 902 | /** |
| 903 | * Deletes a comment: its author, or anyone with the Maintain role or |
| 904 | * higher. A review that gave a verdict cannot be deleted, only edited. |
| 905 | */ |
| 906 | deleteComment(actor: User, repo: RepoPath, commentId: string): Promise<Result<boolean>>; |
| 907 | /** |
| 908 | * Reacts to comment `commentId` on issue or pull request `number`, or to |
| 909 | * its description without one; with `remove`, takes it back. Anyone who |
| 910 | * can read the repository may. What it has now. |
| 911 | */ |
| 912 | react( |
| 913 | actor: User, |
| 914 | repo: RepoPath, |
| 915 | number: number, |
| 916 | reaction: { commentId?: string; content: ReactionContent; remove?: boolean }, |
| 917 | ): Promise<Result<ReactionGroup[]>>; |
| 918 | |
| 919 | /** |
| 920 | * What a sandbox says about a run from before checks were workflows: so |
| 921 | * one still finishing is recorded. |
| 922 | */ |
| 923 | reportChecks(runId: string, token: string, report: CheckReport): Promise<Result<CheckRun>>; |
| 924 | /** |
| 925 | * Claims the probe of whether a pull request merges cleanly that a |
| 926 | * `pull.mergecheck` event asked for. Refused when it is no longer wanted |
| 927 | * or the repository has as many running as it may. For the runner service. |
| 928 | */ |
| 929 | startMergecheck(pullId: string): Promise<Result<MergecheckJob>>; |
| 930 | /** Records that a probe could not be carried out. For the runner service. */ |
| 931 | failMergecheck(pullId: string, token: string, error: string): Promise<Result<Mergeable>>; |
| 932 | |
| 933 | /** |
| 934 | * Works out the next step for a pull request g1t is seeing through and, |
| 935 | * if there is one to take now, claims it, so that it is taken once |
| 936 | * however often this is called. For the runner service. |
| 937 | */ |
| 938 | advance(pullId: string): Promise<Advance>; |
| 939 | /** |
| 940 | * Ids of the open pull requests to move along: those g1t merges by itself |
| 941 | * or someone set to auto-merge; with `repoId`, also every open one whose |
| 942 | * lifecycle is remembered, to bring it up to date after a merge there. |
| 943 | */ |
| 944 | managedPulls(repoId?: string): Promise<string[]>; |
| 945 | |
| 946 | /** A repository's merge queue: what is in it, in order, and what recently left. */ |
| 947 | queue(repo: RepoPath, viewer: Viewer): Promise<Result<QueueView>>; |
| 948 | /** |
| 949 | * The next batch of combined states to test for a repository, one per |
| 950 | * entry; empty while a batch is being tested or nothing waits. |
| 951 | */ |
| 952 | queueBuild(repoId: string): Promise<QueueJob[]>; |
| 953 | /** Reports that a combined state could not be built or checked. */ |
| 954 | failQueue(entryId: string, token: string, error: string): Promise<Result<QueueState>>; |
| 955 | /** Takes a pull request out of the merge queue. Members only. */ |
| 956 | removeFromQueue(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 957 | |
| 958 | getSettings(repo: RepoPath, viewer: Viewer): Promise<Result<RepoSettings>>; |
| 959 | /** The check names reported on the repository's commits in the last 30 days, most recent first. */ |
| 960 | seenChecks(repo: RepoPath, viewer: Viewer): Promise<Result<SeenCheck[]>>; |
| 961 | /** Members of the repository's workspace only. */ |
| 962 | updateSettings(actor: User, repo: RepoPath, settings: RepoSettingsInput): Promise<Result<RepoSettings>>; |
| 963 | /** The CODEOWNERS file at a branch (the default when left out), checked. Needs Read. */ |
| 964 | codeownersErrors(repo: RepoPath, viewer: Viewer, ref?: string | null): Promise<Result<CodeownersReport>>; |
| 965 | |
| 966 | /** |
| 967 | * Opens a pull request: a draft with a fork to push to, or, given a |
| 968 | * branch, one ready for review. |
| 969 | */ |
| 970 | openPull(actor: User, repo: RepoPath, input: OpenPullInput): Promise<Result<Pull>>; |
| 971 | /** Newest first. */ |
| 972 | listPulls( |
| 973 | repo: RepoPath, |
| 974 | viewer: Viewer, |
| 975 | state?: State, |
| 976 | filter?: { label?: string; milestone?: number; base?: string }, |
| 977 | ): Promise<Result<Pull[]>>; |
| 978 | /** |
| 979 | * Delivery for up to 100 repositories over UTC days `from` through |
| 980 | * `until`, over their whole history. Repositories the viewer cannot read, |
| 981 | * and forks, are left out of `projects`. |
| 982 | */ |
| 983 | deliveryInsights(repoIds: string[], viewer: Viewer, from: string, until: string): Promise<DeliveryInsights>; |
| 984 | /** |
| 985 | * The newest `limit` open and closed pull requests of each repository, |
| 986 | * in one call. Repositories the viewer cannot read, and forks, are left |
| 987 | * out: ask those with `listPulls`. |
| 988 | */ |
| 989 | pullsForRepos(repoIds: string[], viewer: Viewer, limit: number): Promise<RepoPulls[]>; |
| 990 | getPull(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<PullDetail>>; |
| 991 | /** |
| 992 | * Changes who a pull request is assigned to and whose review is asked |
| 993 | * for; each list given replaces the whole set. Asking for `g1t`'s |
| 994 | * review does not by itself start one: the runner's `review` does. |
| 995 | */ |
| 996 | updatePull( |
| 997 | actor: User, |
| 998 | repo: RepoPath, |
| 999 | number: number, |
| 1000 | changes: { |
| 1001 | assignees?: string[]; |
| 1002 | reviewers?: string[]; |
| 1003 | labels?: string[]; |
| 1004 | /** 0 takes it out of its milestone. */ |
| 1005 | milestone?: number; |
| 1006 | /** The branch it merges into. Needs the Write role. */ |
| 1007 | base?: string; |
| 1008 | }, |
| 1009 | ): Promise<Result<Pull>>; |
| 1010 | /** |
| 1011 | * Brings a pull request up to date with the default branch in seconds, |
| 1012 | * without a sandbox, when the two changed different files: the merge |
| 1013 | * commit is pushed to its branch as `actor`, who must be whoever opened |
| 1014 | * it (for a fork) or a member (for a branch). Otherwise `needs_agent`, and |
| 1015 | * nothing is pushed: the runner's `update` is the way on. |
| 1016 | */ |
| 1017 | catchUpPull( |
| 1018 | actor: User, |
| 1019 | repo: RepoPath, |
| 1020 | number: number, |
| 1021 | options?: { updateMethod?: UpdateMethod; expectedHead?: string }, |
| 1022 | ): Promise<Result<PullBranchUpdate>>; |
| 1023 | /** |
| 1024 | * Turns a pull request's auto-merge on (with how to merge) or off. On needs |
| 1025 | * Write, since it merges as whoever turned it on; its author may also turn |
| 1026 | * it off. Refused where the repository does not allow auto-merge or the |
| 1027 | * method. One that may merge already merges at once. |
| 1028 | */ |
| 1029 | setAutoMerge( |
| 1030 | actor: User, |
| 1031 | repo: RepoPath, |
| 1032 | number: number, |
| 1033 | enabled: boolean, |
| 1034 | options?: { mergeMethod?: MergeMethod; commitTitle?: string; commitMessage?: string }, |
| 1035 | ): Promise<Result<Pull>>; |
| 1036 | /** How a pull request may merge now: methods, default messages, auto-merge and branch deletion. */ |
| 1037 | mergeChoices(viewer: Viewer, repo: RepoPath, number: number): Promise<Result<MergeChoices>>; |
| 1038 | /** Deletes a merged or closed pull request's branch (Push on where it is). */ |
| 1039 | deleteHeadBranch(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 1040 | /** Makes a deleted pull request branch again at its head. */ |
| 1041 | restoreHeadBranch(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 1042 | /** A commit's comments, oldest first; with no commit, the repository's, newest first, 30 a page. */ |
| 1043 | commitComments(viewer: Viewer, repo: RepoPath, commit?: string | null, page?: number): Promise<Result<CommitComment[]>>; |
| 1044 | /** Comments on a commit, or on one line of a file it changed. Needs Read, where commit comments are on. */ |
| 1045 | addCommitComment( |
| 1046 | actor: User, |
| 1047 | repo: RepoPath, |
| 1048 | commit: string, |
| 1049 | body: string, |
| 1050 | at?: { path: string; line: number }, |
| 1051 | ): Promise<Result<CommitComment>>; |
| 1052 | editCommitComment(actor: User, repo: RepoPath, id: string, body: string): Promise<Result<CommitComment>>; |
| 1053 | deleteCommitComment(actor: User, repo: RepoPath, id: string): Promise<Result<boolean>>; |
| 1054 | /** Marks a draft ready for review and sets its description. */ |
| 1055 | readyPull(actor: User, repo: RepoPath, number: number, summary: string): Promise<Result<Pull>>; |
| 1056 | closePull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 1057 | /** Opens a closed pull request again, as the draft it was if it was closed as one. Never a merged one. */ |
| 1058 | reopenPull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 1059 | /** Turns an open pull request back into a draft; it leaves the merge queue. */ |
| 1060 | convertPullToDraft(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 1061 | /** |
| 1062 | * Lands the pull request on the repository's default branch. Unless |
| 1063 | * `keepIssueOpen`, that resolves the issue it was for: the issue closes |
| 1064 | * naming this pull request, and the others still in progress for it close |
| 1065 | * as superseded. Only members of the repository's workspace may merge. |
| 1066 | * |
| 1067 | * If the default branch has moved, the pull request is brought up to date |
| 1068 | * first and lands when that is done; it comes back still open, and |
| 1069 | * `PullDetail.landing` is true meanwhile. A repository that requires pull |
| 1070 | * requests to be up to date refuses instead. |
| 1071 | */ |
| 1072 | mergePull(actor: User, repo: RepoPath, number: number, options?: MergeOptions): Promise<Result<Pull>>; |
| 1073 | /** |
| 1074 | * Drafts and open pull requests the viewer started, most recently active |
| 1075 | * first, each with where it stands if g1t is seeing it through. |
| 1076 | */ |
| 1077 | listActivePulls( |
| 1078 | viewer: Viewer, |
| 1079 | ): Promise<{ pull: Pull; issue: Issue | null; lifecycle: Lifecycle | null }[]>; |
| 1080 | /** |
| 1081 | * The issues and pull requests a person opened, a page at a time, only |
| 1082 | * on repositories the viewer may read. Not found for no such account. |
| 1083 | */ |
| 1084 | byAuthor(username: string, viewer: Viewer, filter?: AuthoredFilter): Promise<Result<Authored>>; |
| 1085 | /** |
| 1086 | * What a person did each day of the last year (issues and pull requests |
| 1087 | * opened, reviews given), only on repositories the viewer may read: the |
| 1088 | * calendar on their profile. Not found for no such account. |
| 1089 | */ |
| 1090 | contributions(username: string, viewer: Viewer): Promise<Result<Contributions>>; |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | appendSession(actor: User, repo: RepoPath, number: number, entries: NewSessionEntry[]): Promise<Result<{ count: number }>>; |
| 1095 | readSession(repo: RepoPath, number: number, viewer: Viewer, afterSeq?: number): Promise<Result<SessionEntry[]>>; |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * What to pass `ReposApi.compare` to see what a pull request changes. |
| 1100 | * |
| 1101 | * A working copy is compared as a whole. A branch, of the repository or of |
| 1102 | * a fork of it, is compared by name while the pull request is open, and by |
| 1103 | * the commit it was merged or closed at afterwards, so later pushes to the |
| 1104 | * branch do not change the record. A fork's branch is compared from the |
| 1105 | * repository it merges into (`targetId`). |
| 1106 | */ |
| 1107 | export function pullComparison(pull: Pull): { |
| 1108 | repoId: string; |
| 1109 | base: string | null; |
| 1110 | head: string | null; |
| 1111 | /** The branch it merges into, which it is compared from. */ |
| 1112 | baseBranch: string | null; |
| 1113 | /** For a fork's branch: the repository it merges into. */ |
| 1114 | targetId: string | null; |
| 1115 | } { |
| 1116 | const baseBranch = pull.base ?? null; |
| 1117 | if (pull.forkRepoId) return { repoId: pull.forkRepoId, base: pull.mergeBase, head: null, baseBranch, targetId: null }; |
| 1118 | const settled = pull.status === "merged" || pull.status === "closed"; |
| 1119 | return { |
| 1120 | repoId: pull.headRepoId ?? pull.repoId, |
| 1121 | base: pull.mergeBase, |
| 1122 | // A fork's branch by the commit it was last seen at, which the repository |
| 1123 | // it merges into holds too, so those who read that repository can read it. |
| 1124 | head: ((settled || pull.headRepoId) && pull.headCommit) || pull.branch, |
| 1125 | baseBranch, |
| 1126 | targetId: pull.headRepoId ? pull.repoId : null, |
| 1127 | }; |
| 1128 | } |
| 1129 | |
| 1130 | /** The id of the repository holding a pull request's change: its working copy, its fork, or the repository. */ |
| 1131 | export function pullSourceId(pull: Pull): string { |
| 1132 | return pull.forkRepoId ?? pull.headRepoId ?? pull.repoId; |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | export type QueueState = "waiting" | "testing" | "passed" | "failed" | "landed" | "removed"; |
| 1137 | |
| 1138 | /** One pull request's place in a merge queue. */ |
| 1139 | export type QueueEntry = { |
| 1140 | id: string; |
| 1141 | number: number; |
| 1142 | title: string; |
| 1143 | agent: string; |
| 1144 | state: QueueState; |
| 1145 | /** The pull requests merged ahead of it in the state being tested, in order. */ |
| 1146 | ahead: number[]; |
| 1147 | baseCommit: string | null; |
| 1148 | combinedCommit: string | null; |
| 1149 | error: string | null; |
| 1150 | results: CheckResult[]; |
| 1151 | /** Username of whoever merged it into the queue: a person, or `g1t`. */ |
| 1152 | enqueuedBy: string; |
| 1153 | /** RFC 3339. */ |
| 1154 | createdAt: string; |
| 1155 | /** RFC 3339. */ |
| 1156 | finishedAt: string | null; |
| 1157 | }; |
| 1158 | |
| 1159 | /** A repository's merge queue: what is in it, in order, and what recently left. */ |
| 1160 | export type QueueView = { |
| 1161 | enabled: boolean; |
| 1162 | active: QueueEntry[]; |
| 1163 | /** Newest first. */ |
| 1164 | recent: QueueEntry[]; |
| 1165 | }; |
| 1166 | |
| 1167 | export type QueueStackItem = { |
| 1168 | number: number; |
| 1169 | title: string; |
| 1170 | /** The repository holding the change, and its branch. */ |
| 1171 | source: RepoPath; |
| 1172 | branch: string; |
| 1173 | commit: string; |
| 1174 | /** How it lands: the state is built with its commits made this way. */ |
| 1175 | method?: MergeMethod; |
| 1176 | /** For merge and squash: the commit's message. */ |
| 1177 | message?: string; |
| 1178 | /** For squash: who the commit is by. */ |
| 1179 | author?: User; |
| 1180 | }; |
| 1181 | |
| 1182 | /** What a sandbox needs to build and check one combined state. */ |
| 1183 | export type QueueJob = { |
| 1184 | entryId: string; |
| 1185 | token: string; |
| 1186 | repo: RepoPath; |
| 1187 | defaultBranch: string; |
| 1188 | baseCommit: string; |
| 1189 | branch: string; |
| 1190 | stack: QueueStackItem[]; |
| 1191 | /** Always empty: the state is checked by the merge_group workflows run on it. */ |
| 1192 | checks: string[]; |
| 1193 | /** Always empty, as `checks`. */ |
| 1194 | contractChecks: string[]; |
| 1195 | actor: User; |
| 1196 | }; |
| 1197 | |
| 1198 | // --- A person's work --------------------------------------------------------- |
| 1199 | // Mirrors the `Authored*` types in `crates/contracts/src/work.rs`. |
| 1200 | |
| 1201 | export type AuthoredKind = "issue" | "pull"; |
| 1202 | /** `closed` takes in merged pull requests too; `merged` is only those. */ |
| 1203 | export type AuthoredState = "open" | "closed" | "merged"; |
| 1204 | /** `created` is newest first, `updated` most recently changed, `oldest` oldest first. */ |
| 1205 | export type AuthoredSort = "created" | "updated" | "oldest"; |
| 1206 | |
| 1207 | /** The most items one `byAuthor` page holds. */ |
| 1208 | export const AUTHORED_PAGE = 25; |
| 1209 | |
| 1210 | export type AuthoredFilter = { |
| 1211 | kind?: AuthoredKind; |
| 1212 | state?: AuthoredState; |
| 1213 | /** `namespace/name`. */ |
| 1214 | repo?: string; |
| 1215 | sort?: AuthoredSort; |
| 1216 | /** The `next` of the page before. */ |
| 1217 | before?: string; |
| 1218 | limit?: number; |
| 1219 | }; |
| 1220 | |
| 1221 | export type AuthoredItem = { |
| 1222 | kind: AuthoredKind; |
| 1223 | repo: RepoPath; |
| 1224 | number: number; |
| 1225 | title: string; |
| 1226 | /** A merged pull request is closed. */ |
| 1227 | state: State; |
| 1228 | /** A pull request's own status; null on an issue. */ |
| 1229 | status: PullStatus | null; |
| 1230 | /** Why an issue was closed. */ |
| 1231 | reason: IssueReason | null; |
| 1232 | draft: boolean; |
| 1233 | merged: boolean; |
| 1234 | /** RFC 3339. */ |
| 1235 | createdAt: string; |
| 1236 | /** RFC 3339. */ |
| 1237 | updatedAt: string; |
| 1238 | /** RFC 3339. */ |
| 1239 | mergedAt: string | null; |
| 1240 | }; |
| 1241 | |
| 1242 | /** Over every repository the viewer may read, whatever the filters. */ |
| 1243 | export type AuthoredCounts = { |
| 1244 | pullsMerged: number; |
| 1245 | pullsOpen: number; |
| 1246 | pulls: number; |
| 1247 | issues: number; |
| 1248 | issuesOpen: number; |
| 1249 | }; |
| 1250 | |
| 1251 | export type Authored = { |
| 1252 | items: AuthoredItem[]; |
| 1253 | /** Pass as `before` for the next page; null on the last. */ |
| 1254 | next: string | null; |
| 1255 | counts: AuthoredCounts; |
| 1256 | /** The repositories they worked in that the viewer may read, most work first. */ |
| 1257 | repos: { repo: RepoPath; count: number }[]; |
| 1258 | }; |
| 1259 | |
| 1260 | // Mirrors `Contributions` in `crates/contracts/src/work.rs`. |
| 1261 | |
| 1262 | /** How many days `contributions` covers: today and the 364 before it. */ |
| 1263 | export const CONTRIBUTION_DAYS = 365; |
| 1264 | |
| 1265 | /** One day with something on it; days with nothing are left out. */ |
| 1266 | export type ContributionDay = { |
| 1267 | /** `YYYY-MM-DD`, UTC. */ |
| 1268 | date: string; |
| 1269 | /** Everything that day, commits included. */ |
| 1270 | count: number; |
| 1271 | /** How many of `count` are commits they pushed to a default branch. */ |
| 1272 | commits?: number; |
| 1273 | }; |
| 1274 | |
| 1275 | /** A person's year, as far as the viewer may see. */ |
| 1276 | export type Contributions = { |
| 1277 | /** Oldest first. */ |
| 1278 | days: ContributionDay[]; |
| 1279 | total: number; |
| 1280 | /** The first day counted, `YYYY-MM-DD`; the last is today (UTC). */ |
| 1281 | from: string; |
| 1282 | }; |
| 1283 | |
| 1284 | // --- Coordinating work: sessions, claims and dependencies ----------------- |
| 1285 | // Mirrors `crates/contracts/src/work/coordination.rs`. |
| 1286 | |
| 1287 | /** The harness a session runs in. */ |
| 1288 | export type Harness = "claude_code" | "claude_managed_agents" | "codex" | "cursor" | "copilot" | "other"; |
| 1289 | |
| 1290 | /** A session as a mark on something it made. */ |
| 1291 | export type SessionRef = { id: string; harness: Harness }; |
| 1292 | |
| 1293 | /** The sessions tied to one pull request (`pullSessions`). */ |
| 1294 | export type PullSessions = { number: number; sessions: SessionRef[] }; |
| 1295 | |
| 1296 | /** Active: heard from in 15 minutes; idle: not since; ended: ended, or quiet for 2 hours. */ |
| 1297 | export type SessionState = "active" | "idle" | "ended"; |
| 1298 | |
| 1299 | /** One run of someone's own harness on a repository. */ |
| 1300 | export type WorkSession = { |
| 1301 | /** `ses_…`. */ |
| 1302 | id: string; |
| 1303 | repoId: string; |
| 1304 | issue: number | null; |
| 1305 | pull: number | null; |
| 1306 | branch: string | null; |
| 1307 | actor: { id: string; username: string }; |
| 1308 | harness: Harness; |
| 1309 | harnessSessionId: string | null; |
| 1310 | title: string | null; |
| 1311 | state: SessionState; |
| 1312 | headCommit: string | null; |
| 1313 | startedAt: string; |
| 1314 | lastSeenAt: string; |
| 1315 | endedAt: string | null; |
| 1316 | /** What the harness said, or `timed_out`. */ |
| 1317 | endReason: string | null; |
| 1318 | /** For a subagent: the session that started it. */ |
| 1319 | parentId?: string | null; |
| 1320 | /** For a subagent: its kind (Explore, security-reviewer). */ |
| 1321 | agentType?: string | null; |
| 1322 | /** For a subagent: the task it was given, in a few words. */ |
| 1323 | task?: string | null; |
| 1324 | /** For a subagent: the prompt its parent gave it. */ |
| 1325 | prompt?: string | null; |
| 1326 | /** What it reported when it finished: a subagent's final message. */ |
| 1327 | result?: string | null; |
| 1328 | model?: string | null; |
| 1329 | /** How many subagents it started. */ |
| 1330 | subagents?: number; |
| 1331 | /** In a list, for one with no title: the start of the first prompt it recorded. */ |
| 1332 | firstPrompt?: string | null; |
| 1333 | }; |
| 1334 | |
| 1335 | /** What kind of thing a session touched. */ |
| 1336 | export type TouchKind = "file" | "commit" | "branch" | "pull" | "issue"; |
| 1337 | |
| 1338 | /** Something a session touched, kept once per session. */ |
| 1339 | export type SessionTouch = { sessionId: string; kind: TouchKind; value: string; at: string }; |
| 1340 | |
| 1341 | /** How a session was tied to an issue or pull request. */ |
| 1342 | export type LinkVia = "attached" | "claim" | "branch" | "commit" | "trailer" | "opened" | "ref"; |
| 1343 | |
| 1344 | /** An issue or pull request a session, or one of its subagents, worked on. */ |
| 1345 | export type SessionLink = { |
| 1346 | kind: "issue" | "pull"; |
| 1347 | number: number; |
| 1348 | title: string; |
| 1349 | /** The issue's state or the pull request's status. */ |
| 1350 | state: string; |
| 1351 | via: LinkVia[]; |
| 1352 | sessionIds: string[]; |
| 1353 | }; |
| 1354 | |
| 1355 | /** A skill a session used, by name. */ |
| 1356 | export type SessionSkill = { sessionId: string; name: string; uses: number }; |
| 1357 | |
| 1358 | export type ClaimState = "active" | "released" | "expired" | "handed_off"; |
| 1359 | |
| 1360 | /** An advisory, expiring "I'm working on #N". Never a lock. */ |
| 1361 | export type Claim = { |
| 1362 | /** `clm_…`. */ |
| 1363 | id: string; |
| 1364 | repoId: string; |
| 1365 | issue: number; |
| 1366 | sessionId: string | null; |
| 1367 | actor: { id: string; username: string }; |
| 1368 | harness: Harness | null; |
| 1369 | note: string | null; |
| 1370 | state: ClaimState; |
| 1371 | createdAt: string; |
| 1372 | expiresAt: string; |
| 1373 | endedAt: string | null; |
| 1374 | endReason: string | null; |
| 1375 | /** For a hand-off: who it was handed to; null for anyone. */ |
| 1376 | handoffTo: string | null; |
| 1377 | }; |
| 1378 | |
| 1379 | /** `session.started` and `session.ended`. */ |
| 1380 | export type SessionEventData = { repoId: string; number?: number; issue?: number; session: WorkSession }; |
| 1381 | |
| 1382 | /** `work.claimed`, `work.released`, `work.claim_expired` and `work.handoff_requested`. */ |
| 1383 | export type ClaimEventData = { |
| 1384 | repoId: string; |
| 1385 | number: number; |
| 1386 | issue: number; |
| 1387 | claim: Claim; |
| 1388 | others?: Claim[]; |
| 1389 | tookOver?: string; |
| 1390 | reason?: string; |
| 1391 | from?: string; |
| 1392 | to?: string; |
| 1393 | note?: string; |
| 1394 | }; |
| 1395 | |
| 1396 | /** `dependency.changed`. */ |
| 1397 | export type DependencyChangedData = { |
| 1398 | repoId: string; |
| 1399 | number: number; |
| 1400 | issue: number; |
| 1401 | blockedBy: number[]; |
| 1402 | added: number[]; |
| 1403 | removed: number[]; |
| 1404 | cleared: number[]; |
| 1405 | remaining: number[]; |
| 1406 | mergedPull?: number; |
| 1407 | }; |
| 1408 | |
| 1409 | /** `overlap.detected` between two pull requests, sent once for each side of a new overlap. */ |
| 1410 | export type PullOverlapData = { |
| 1411 | repoId: string; |
| 1412 | number: number; |
| 1413 | pull: number; |
| 1414 | otherPull: number; |
| 1415 | files: string[]; |
| 1416 | issue?: number; |
| 1417 | otherIssue?: number; |
| 1418 | }; |
| 1419 | |
| 1420 | /** `overlap.detected` between two sessions that touched the same files (siblings included), once for each side. */ |
| 1421 | export type SessionOverlapData = { |
| 1422 | repoId: string; |
| 1423 | number?: number; |
| 1424 | sessionId: string; |
| 1425 | otherSessionId: string; |
| 1426 | otherActor: string; |
| 1427 | files: string[]; |
| 1428 | issue?: number; |
| 1429 | otherIssue?: number; |
| 1430 | }; |
| 1431 | |
| 1432 | /** `overlap.detected`: between pull requests, or between sessions (with `sessionId`). */ |
| 1433 | export type OverlapDetectedData = PullOverlapData | SessionOverlapData; |
| 1434 | |
| 1435 | /** `session.progressed`: a session recorded more (at most every few seconds). */ |
| 1436 | export type SessionProgressedData = { repoId: string; number?: number; sessionId: string; rootId?: string }; |
| 1437 | |
| 1438 | /** An issue in brief. */ |
| 1439 | export type IssueBrief = { number: number; title: string; state: State }; |
| 1440 | |
| 1441 | /** A pull request in brief. */ |
| 1442 | export type PullBrief = { number: number; title: string; status: PullStatus }; |
| 1443 | |
| 1444 | /** An issue another is blocked by, and where it stands. */ |
| 1445 | export type Blocker = { |
| 1446 | number: number; |
| 1447 | title: string; |
| 1448 | state: State; |
| 1449 | /** Active claims on it. */ |
| 1450 | claims: Claim[]; |
| 1451 | pulls: PullBrief[]; |
| 1452 | }; |
| 1453 | |
| 1454 | /** A pull request's place in the merge queue; `position` 1 is the front. */ |
| 1455 | export type QueuePlace = { state: QueueState; position: number }; |
| 1456 | |
| 1457 | /** One of an issue's pull requests, with where it stands. */ |
| 1458 | export type WorkPull = { |
| 1459 | number: number; |
| 1460 | title: string; |
| 1461 | status: PullStatus; |
| 1462 | branch: string | null; |
| 1463 | headCommit: string | null; |
| 1464 | author: { id: string; username: string }; |
| 1465 | /** `failed` when the merge queue took it out, until its head moves. */ |
| 1466 | checkStatus: CheckStatus | null; |
| 1467 | requiredChecks: RequiredCheck[]; |
| 1468 | mergeable: Mergeable; |
| 1469 | /** Other pull requests in progress changing the same files. */ |
| 1470 | overlaps: Overlap[]; |
| 1471 | /** Its place in the merge queue, while it is in it. */ |
| 1472 | queue: QueuePlace | null; |
| 1473 | }; |
| 1474 | |
| 1475 | // --- Decision records (crates/contracts/src/decisions.rs) ------------------ |
| 1476 | |
| 1477 | export type DecisionKind = |
| 1478 | | "proposal" |
| 1479 | | "claim" |
| 1480 | | "integration_failure" |
| 1481 | | "integration_passed" |
| 1482 | | "fix" |
| 1483 | | "approval" |
| 1484 | | "merge" |
| 1485 | | "note"; |
| 1486 | |
| 1487 | /** Claimed: someone said so. Tested: a check or the merge queue proved it. Approved: a person approved it. */ |
| 1488 | export type DecisionConfidence = "claimed" | "tested" | "approved"; |
| 1489 | |
| 1490 | /** A structured reason kept on an issue or pull request, with how sure it is. */ |
| 1491 | export type Decision = { |
| 1492 | /** `dec_…`. */ |
| 1493 | id: string; |
| 1494 | issue: number | null; |
| 1495 | pull: number | null; |
| 1496 | sessionId: string | null; |
| 1497 | /** Username of who recorded it; null when g1t did. */ |
| 1498 | actor: string | null; |
| 1499 | kind: DecisionKind; |
| 1500 | confidence: DecisionConfidence; |
| 1501 | summary: string; |
| 1502 | /** |
| 1503 | * What it rests on, kept as recorded, in snake_case: `commit`, `check` |
| 1504 | * (`name`, `conclusion`, `url`), `combination`, `other_pulls`, |
| 1505 | * `suspects`, `bisected`, `merge_queue`. |
| 1506 | */ |
| 1507 | evidence: Record<string, unknown>; |
| 1508 | /** RFC 3339. */ |
| 1509 | createdAt: string; |
| 1510 | }; |
| 1511 | |
| 1512 | /** Everything about an issue an agent needs to pick it up: `get_work`. */ |
| 1513 | export type WorkContext = { |
| 1514 | issue: Issue; |
| 1515 | /** The items under its "Definition of done" heading. */ |
| 1516 | definitionOfDone: string[]; |
| 1517 | /** The checks every pull request into the default branch must pass. */ |
| 1518 | requiredChecks: string[]; |
| 1519 | /** Active claims on it. */ |
| 1520 | claims: Claim[]; |
| 1521 | /** Sessions on it or its pull requests, most recently heard from first. */ |
| 1522 | sessions: WorkSession[]; |
| 1523 | pulls: WorkPull[]; |
| 1524 | blockedBy: Blocker[]; |
| 1525 | /** The issues it blocks. */ |
| 1526 | blocks: IssueBrief[]; |
| 1527 | /** On it and its pull requests, newest first. */ |
| 1528 | decisions: Decision[]; |
| 1529 | /** The latest `integration_failure` decision among them. */ |
| 1530 | lastIntegrationFailure: Decision | null; |
| 1531 | /** Its latest coordination events, newest first. */ |
| 1532 | recent: G1tEvent[]; |
| 1533 | }; |
| 1534 | |
| 1535 | /** A harness session and what it recorded. */ |
| 1536 | export type WorkSessionDetail = { |
| 1537 | /** Pending repository coordination events; reading does not acknowledge them. */ |
| 1538 | updates?: { id: string; kind: string; data: unknown; at: string }[]; |
| 1539 | session: WorkSession; |
| 1540 | entries: SessionEntry[]; |
| 1541 | /** Its subagents and theirs, in the order they started. */ |
| 1542 | children?: WorkSession[]; |
| 1543 | /** What it and its subagents touched. */ |
| 1544 | touched?: SessionTouch[]; |
| 1545 | /** The issues and pull requests it and its subagents worked on. */ |
| 1546 | links?: SessionLink[]; |
| 1547 | skills?: SessionSkill[]; |
| 1548 | /** For a subagent: the session at the top of its tree. */ |
| 1549 | root?: WorkSession | null; |
| 1550 | }; |
| 1551 | |
| 1552 | /** Reading coordination: work service methods (services/work/src/coordination, decisions.rs). */ |
| 1553 | export interface CoordinationApi { |
| 1554 | getWork(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<WorkContext>>; |
| 1555 | /** Newest first; active ones unless `state` says otherwise. */ |
| 1556 | listClaims(repo: RepoPath, viewer: Viewer, filter?: { state?: ClaimState; issue?: number }): Promise<Result<Claim[]>>; |
| 1557 | /** Most recently heard from first. */ |
| 1558 | listWorkSessions( |
| 1559 | repo: RepoPath, |
| 1560 | viewer: Viewer, |
| 1561 | filter?: { state?: SessionState; issue?: number; pull?: number; path?: string; subagents?: boolean }, |
| 1562 | ): Promise<Result<WorkSession[]>>; |
| 1563 | getWorkSession(repo: RepoPath, id: string, viewer: Viewer, afterSeq?: number): Promise<Result<WorkSessionDetail>>; |
| 1564 | /** |
| 1565 | * The harness sessions tied to some pull requests (at most 100), any way |
| 1566 | * a session is tied to one; a subagent's as the session that started it. |
| 1567 | * Only pull requests with any are listed. |
| 1568 | */ |
| 1569 | pullSessions(repo: RepoPath, viewer: Viewer, numbers: number[]): Promise<Result<PullSessions[]>>; |
| 1570 | /** An issue's (with its pull requests') or a pull request's, oldest first. */ |
| 1571 | listDecisions(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<Decision[]>>; |
| 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * Delivery counts cover the requested UTC days; waiting counts are current. |
| 1576 | * `checking` and `failed` count each open pull request once, by its head's |
| 1577 | * checks (statuses, check runs and g1t Actions jobs); one with none is in neither. |
| 1578 | */ |
| 1579 | export type DeliveryMetrics = { repoId: string; opened: number; merged: number; active: number; unreviewed: number; checking: number; failed: number; queued: number; leadSeconds: number; reviewSeconds: number; reviewed: number }; |
| 1580 | /** `checksUnavailable`: g1t Actions could not be read, so `checking` and `failed` are not known. */ |
| 1581 | export type DeliveryInsights = { projects: DeliveryMetrics[]; days: { day: string; merged: number }[]; checksUnavailable: boolean }; |