Skip to content
1,054 linesCodeBlameRaw
1import type { ChecksApi } from "./checks";
2import type { CodeownersReport, PullCodeOwners } from "./codeowners";
3import type { User, Viewer } from "./identity";
4import type { PullBranchUpdate, RepoPath } from "./repos";
5import type { Result } from "./result";
6import type { MergeRules, RulesApi } from "./rules";
7
8/**
9 * The filter on lists of issues and pull requests. An open pull request is
10 * a draft or one ready for review; a closed one was merged or closed
11 * without merging.
12 */
13export type State = "open" | "closed";
14
15/** Why an issue was closed. */
16export type IssueReason = "completed" | "not_planned";
17
18/**
19 * Something that should change in a repository: a bug, a feature, a
20 * question. Opened by a person, an agent or an integration. Pull requests
21 * are made against it; the one that is merged resolves it.
22 *
23 * Issues and pull requests share one sequence of numbers per repository.
24 */
25export type Issue = {
26 id: string;
27 repoId: string;
28 /** Shown as `#12`. */
29 number: number;
30 title: string;
31 /** Markdown. Also what an agent is given to work from. */
32 body: string;
33 labels: string[];
34 state: State;
35 /** Set when closed. */
36 reason: IssueReason | null;
37 /** The number of the pull request whose merge closed this issue. */
38 resolvedBy: number | null;
39 /** Who opened it: a person, an integration, or g1t (`kind` `agent`) for one its agent filed while at work. */
40 author: User;
41 /**
42 * For an issue g1t's agent filed: the person it was working for. They may
43 * manage it as its author could. See `workOwner`.
44 */
45 requestedBy: User | null;
46 /** RFC 3339. */
47 createdAt: string;
48 /** RFC 3339. */
49 updatedAt: string;
50 /** RFC 3339. */
51 closedAt: string | null;
52 /** Pull requests made against this issue, in any state. */
53 pullCount: number;
54 commentCount: number;
55 /** Usernames of the people it is assigned to. */
56 assignees: string[];
57 /** The numbers of the issues that have to be merged before this one is worked on. */
58 blockedBy: number[];
59 /**
60 * Whether a g1t agent takes it as soon as it can: at once, or when what it
61 * is blocked by has merged.
62 */
63 queued: boolean;
64 /**
65 * The agent working on it now: the one behind its newest pull request
66 * that is still in progress in a fork, such as `g1t`.
67 */
68 agent: string | null;
69 /** The milestone it is in, if any. */
70 milestone?: MilestoneRef | null;
71};
72
73/**
74 * A label of a repository: a name, a color and what it means. Issues and
75 * pull requests carry labels by name; names are lowercase.
76 */
77export type Label = {
78 name: string;
79 /** Six hex digits, without `#`. */
80 color: string;
81 description: string;
82 /** How many issues carry it, open or closed. */
83 issues: number;
84 /** How many pull requests carry it, in any state. */
85 pulls: number;
86};
87
88/** A milestone, as an issue or pull request names it. */
89export type MilestoneRef = { number: number; title: string };
90
91/**
92 * A goal, with an optional due date, that issues and pull requests are
93 * gathered under. Its progress is how many of them are closed.
94 */
95export type Milestone = {
96 /** Numbered from 1 in each repository, apart from issues. */
97 number: number;
98 title: string;
99 /** Markdown. */
100 description: string;
101 /** `YYYY-MM-DD`. */
102 dueOn: string | null;
103 state: State;
104 /** Open issues and pull requests in it. */
105 openItems: number;
106 /** Closed issues, and merged or closed pull requests, in it. */
107 closedItems: number;
108 createdAt: string;
109 updatedAt: string;
110 closedAt: string | null;
111};
112
113/** One milestone and what is in it, newest first. */
114export type MilestoneDetail = { milestone: Milestone; issues: Issue[]; pulls: Pull[] };
115
116/** How `setLabels` changes an item's labels. */
117export type LabelChange = "set" | "add" | "remove";
118
119/**
120 * Whose an issue or a pull request is to answer for: whoever asked g1t for
121 * it, or its author. They may change, close and steer it, are never asked to
122 * review it and cannot approve it, and see it as theirs. Mirrors
123 * `Pull::owner` in the Rust contracts.
124 */
125export function workOwner(item: Pick<Pull, "author" | "requestedBy">): User {
126 return item.requestedBy ?? item.author;
127}
128
129/** `draft` is still being worked on; `open` is ready for review. */
130export type PullStatus = "draft" | "open" | "merged" | "closed";
131
132/** Where the agent runs: on g1t's sandboxes, or in someone's own session. */
133export type Runtime = "hosted" | "external";
134
135/**
136 * A proposed change. It is made either in a fork created for it, which is
137 * how agents work, or on a branch pushed to the repository itself.
138 */
139export type Pull = {
140 id: string;
141 repoId: string;
142 /** Shown as `#12`. */
143 number: number;
144 /** The number of the issue this is for, if any. */
145 issue: number | null;
146 title: string;
147 /** Markdown: what changed and why. Set when marked ready. */
148 body: string | null;
149 /** A label for the agent doing the work, e.g. `claude-code`. */
150 agent: string;
151 runtime: Runtime;
152 status: PullStatus;
153 /** The fork holding the change, unless it is on a branch. */
154 fork: RepoPath | null;
155 /** The fork's repository id. */
156 forkRepoId: string | null;
157 /** The branch of the repository holding the change, unless it is in a fork. */
158 branch: string | null;
159 headCommit: string | null;
160 /**
161 * For a merged pull request, what the branch pointed to before the merge.
162 * Comparing against it shows what the pull request changed.
163 */
164 mergeBase: string | null;
165 /** Username of whoever merged it. */
166 mergedBy: string | null;
167 /** RFC 3339. */
168 mergedAt: string | null;
169 /**
170 * Set on a pull request closed because another one for the same issue was
171 * merged: that one's number.
172 */
173 supersededBy: number | null;
174 /**
175 * Where the latest run of the issue's acceptance checks stands, if there
176 * has been one against the current head.
177 */
178 checkStatus: CheckStatus | null;
179 /** The files it changes, as of its latest push. */
180 files: ChangedFile[];
181 /** Usernames of the people it is assigned to. */
182 assignees: string[];
183 /**
184 * Those whose review was asked for: usernames, and `g1t` when a g1t
185 * agent was asked.
186 */
187 reviewers: string[];
188 /**
189 * Teams whose review was asked for, as `workspace/slug`. A team stays here
190 * after review assignment picks people from it, who are in `reviewers`.
191 */
192 teamReviewers?: string[];
193 /** The labels it carries, by name. */
194 labels?: string[];
195 /** The milestone it is in, if any. */
196 milestone?: MilestoneRef | null;
197 /**
198 * The branch it merges into. Lists and `getPull` name it; null only in
199 * what services pass between themselves, for the default branch.
200 */
201 base?: string | null;
202 /** Who opened it: a person, or g1t (`kind` `agent`, username `g1t`) for a change g1t made. */
203 author: User;
204 /**
205 * For a change g1t made: the person who asked for it, by assigning an issue
206 * or handing g1t the work. They answer for it as its author would. See
207 * `workOwner`.
208 */
209 requestedBy: User | null;
210 /** RFC 3339. */
211 createdAt: string;
212 /** RFC 3339. */
213 updatedAt: string;
214 /** Who last moved its head (a user id), and when; absent until a push after rulesets arrived. */
215 headPushedBy?: string;
216 headPushedAt?: string;
217};
218
219/** One file a pull request changes, and by how much. */
220export type ChangedFile = { path: string; additions: number; deletions: number };
221
222/**
223 * Another pull request in progress that changes some of the same files. Two
224 * for the same issue are alternatives; two for different issues are heading
225 * for a conflict.
226 */
227export type Overlap = {
228 number: number;
229 title: string;
230 /** The number of the issue the other pull request is for. */
231 issue: number | null;
232 /** The files both change. */
233 paths: string[];
234};
235
236/**
237 * On a pull request, `failed` means the merge queue took it out, until its
238 * head moves. The other states are from runs of commands written on issues,
239 * which g1t no longer runs.
240 */
241export type CheckStatus = "queued" | "running" | "passed" | "failed" | "errored";
242
243/** How one command went, in a run recorded before checks were workflows. */
244export type CheckResult = {
245 command: string;
246 passed: boolean;
247 /** Null when the command was stopped for taking too long. */
248 exitCode: number | null;
249 /** What the command printed; the end of it, when there was a lot. */
250 output: string;
251 durationMs: number;
252};
253
254/**
255 * A record against a pull request's head: the merge queue taking it out,
256 * with why, or an earlier run of commands written on its issue.
257 */
258export type CheckRun = {
259 id: string;
260 /** The commit that was checked. */
261 headCommit: string;
262 status: CheckStatus;
263 results: CheckResult[];
264 /** Why the checks could not be run, when `status` is `errored`. */
265 error: string | null;
266 /** RFC 3339. */
267 createdAt: string;
268 /** RFC 3339. */
269 finishedAt: string | null;
270};
271
272/** A reviewer's decision on a pull request. */
273export type Verdict = "approve" | "request_changes";
274
275/**
276 * A comment on an issue or a pull request. On a pull request it can sit on
277 * one line of the change, and it can carry a reviewer's verdict.
278 */
279export type Comment = {
280 id: string;
281 /**
282 * Something a person or an agent wrote, or something that happened: an
283 * assignment, a review asked for, a close.
284 */
285 kind: "comment" | "event";
286 author: User;
287 /**
288 * Markdown. For an event, what its author did, as the rest of a sentence
289 * that starts with their name: "assigned ana".
290 */
291 body: string;
292 /** The file commented on, for a comment on a line. */
293 path: string | null;
294 /** The line of that file, as numbered after the change. */
295 line: number | null;
296 verdict: Verdict | null;
297 /** RFC 3339. */
298 createdAt: string;
299 /** When its text was last edited, RFC 3339; absent if it never was. */
300 editedAt?: string;
301 /**
302 * Set when one of the workspace's agents wrote it, as itself. `author`
303 * is then the agent (its id, its handle as `username`, kind `agent`):
304 * show it by `agent.displayName` with an Agent badge, never as a person.
305 */
306 agent?: AgentRef;
307 /** Who the agent acted for, whose access capped it. Set with `agent`. */
308 actingFor?: User;
309 /**
310 * An agent's review. Its `verdict` (none for a review that only
311 * comments) is shown but advisory: it never counts toward required
312 * approvals or code owners, and never blocks a merge.
313 */
314 advisory?: boolean;
315};
316
317/**
318 * One of a workspace's own agents, as a comment or review it wrote before
319 * g1t's agents were removed shows it: Margo (@margo), with the face drawn
320 * from `avatarSeed`. Kept so those comments still render.
321 */
322export type AgentRef = {
323 id: string;
324 handle: string;
325 displayName: string;
326 avatarSeed: string;
327};
328
329export type NewComment = {
330 /** May be empty when approving. */
331 body: string;
332 path?: string;
333 line?: number;
334 verdict?: Verdict;
335};
336
337/** What a sandbox needs to carry out a check run. */
338export type CheckJob = {
339 runId: string;
340 /** Lets the sandbox, and nothing else, report this run's results. */
341 token: string;
342 commands: string[];
343 /** The repository holding the commit: the fork, or the repository itself. */
344 source: RepoPath;
345 commit: string;
346 /** Who the pull request is for (`workOwner`: whoever asked g1t for it, or its author), and so can read its source. */
347 author: User;
348 /** Username of whoever wrote the checks: the issue's author. */
349 requestedBy: string;
350 repo: RepoPath;
351 number: number;
352};
353
354export type CheckReport = { results?: CheckResult[]; error?: string; skip?: boolean };
355
356export type SessionEntryKind = "prompt" | "message" | "tool_call" | "tool_result" | "note";
357
358/** One step of an agent's session: the "why" behind a pull request's commits. */
359export type SessionEntry = {
360 seq: number;
361 kind: SessionEntryKind;
362 text: string;
363 /** For tool calls and results. */
364 tool: string | null;
365 /** The fork's head commit when this entry was recorded, if known. */
366 commit: string | null;
367 /** RFC 3339. */
368 at: string;
369};
370
371export type NewSessionEntry = Pick<SessionEntry, "kind" | "text"> &
372 Partial<Pick<SessionEntry, "tool" | "commit">>;
373
374export type IssueDetail = {
375 issue: Issue;
376 /** Every pull request made against it, oldest first. */
377 pulls: Pull[];
378 comments: Comment[];
379};
380
381export type PullDetail = {
382 pull: Pull;
383 /** The issue it is for, if any. */
384 issue: Issue | null;
385 comments: Comment[];
386 /** The latest record against its head: the merge queue taking it out. */
387 checks: CheckRun | null;
388 /** Other pull requests in progress that change the same files. */
389 overlaps: Overlap[];
390 /**
391 * Whether the branch it would merge into has moved on without it, so that
392 * it has to catch up before it can merge.
393 */
394 behind: boolean;
395 /**
396 * Where it stands on its way to being merged, for a pull request g1t is
397 * seeing through. Null on anyone else's.
398 */
399 lifecycle: Lifecycle | null;
400 /**
401 * A merge was asked for while it was behind: g1t is bringing it up to
402 * date and will then land it.
403 */
404 landing: boolean;
405 /** Why g1t stopped working on it, if it did. */
406 stalled: string | null;
407 /** What workflow runs said about its head commit, one per workflow. */
408 statuses?: CommitStatus[];
409 /**
410 * Whether it merges cleanly into the branch it targets, worked out ahead
411 * of time whenever either side moves.
412 */
413 mergeable?: Mergeable;
414 /** When `mergeable` is `conflicting`: the files that conflict. */
415 conflicts?: string[];
416 /** Earlier records like `checks`, newest first, without their output. */
417 earlierChecks?: CheckRun[];
418 /**
419 * The checks the default branch's protection requires, each as it stands
420 * on the head commit. Empty when none are required.
421 */
422 requiredChecks?: RequiredCheck[];
423 /**
424 * Who owns the files it changes (the CODEOWNERS file of the branch it
425 * merges into) and whose approval is still needed. Absent without one.
426 */
427 codeOwners?: PullCodeOwners | null;
428 /**
429 * The rules of the branch it merges into it does not meet yet, for whoever
430 * is looking: what refuses the merge, what they may bypass, and what rulesets
431 * in evaluate would refuse. Absent once it is closed or merged.
432 */
433 rules?: MergeRules | null;
434};
435
436/** Where a required check stands on a commit; `expected` when nothing has reported it yet. */
437export type RequiredState = "success" | "failure" | "pending" | "expected";
438
439/** One check a branch's protection requires, as it stands on a commit. */
440export type RequiredCheck = {
441 /** A workflow's name, such as `CI`, or another status's context. */
442 name: string;
443 state: RequiredState;
444 description: string | null;
445 /** Where to see more: the workflow run, for one a workflow reported. */
446 targetUrl: string | null;
447};
448
449/** A check name reported on a repository's commits lately, for choosing required checks. */
450export type SeenCheck = {
451 name: string;
452 /** The events it was reported for, such as `pull_request`; empty for a status that names none. */
453 events: string[];
454 /** RFC 3339. */
455 lastSeen: string;
456};
457
458/**
459 * A status context's check name: `CI / pull_request` is the `CI` check,
460 * reported for a `pull_request` event. A context that does not end in an
461 * event, such as `g1t / deploy`, is its own name. As the work service reads it.
462 */
463export function checkName(context: string): string {
464 const at = context.lastIndexOf(" / ");
465 if (at <= 0) return context;
466 return STATUS_EVENTS.has(context.slice(at + 3)) ? context.slice(0, at) : context;
467}
468
469const STATUS_EVENTS = new Set([
470 "push",
471 "pull_request",
472 "pull_request_target",
473 "pull_request_review",
474 "merge_group",
475 "workflow_dispatch",
476 "workflow_run",
477 "workflow_call",
478 "schedule",
479 "release",
480 "issues",
481 "issue_comment",
482 "repository_dispatch",
483]);
484
485/**
486 * Whether a pull request merges cleanly into the branch it targets:
487 * `unknown` when it was never worked out or could not be, `checking` while
488 * a probe merges the two.
489 */
490export type Mergeable = "clean" | "conflicting" | "unknown" | "checking";
491
492/** What a sandbox needs to find out whether a pull request merges cleanly. */
493export type MergecheckJob = {
494 pullId: string;
495 /** Lets the sandbox, and nothing else, report this probe. */
496 token: string;
497 repo: RepoPath;
498 number: number;
499 defaultBranch: string;
500 /** The default branch's commit to merge into. */
501 base: string;
502 /** The repository holding the change: its fork, or the repository. */
503 source: RepoPath;
504 /** The branch of `source` holding it. */
505 branch: string;
506 /** The change's commit. */
507 head: string;
508 /** Who the pull request is for (`workOwner`: whoever asked g1t for it, or its author), and so can read its source. */
509 author: User;
510};
511
512/** What a workflow run (or another tool) says about a commit. */
513export type CommitStatus = {
514 /** What reported it, such as `CI / push`. */
515 context: string;
516 state: "pending" | "success" | "failure" | "error";
517 description: string | null;
518 targetUrl: string | null;
519 updatedAt: string;
520 /** The integration that reported it: `actions`, `deployments`, `security`, `g1t` or `api`. */
521 source?: string;
522 /** Set on the status a check run stands as: the check run's id. */
523 checkRunId?: string;
524};
525
526/**
527 * A step on the way from an assigned issue to a pull request that is ready
528 * to merge. g1t takes each one without being asked: `working` (the agent is
529 * making the change), `checking`, `reviewing`, `revising` (the agent is
530 * addressing failed checks or a review), `catching_up` (merging in the
531 * branch it would land on), `answering` (woken to answer another agent),
532 * then `ready` for a person to merge. `needs_you`
533 * means g1t has stopped and a person decides what happens next.
534 */
535export type Stage =
536 | "working"
537 | "checking"
538 | "reviewing"
539 | "revising"
540 | "catching_up"
541 | "answering"
542 | "queued"
543 | "ready"
544 | "needs_you";
545
546export type Lifecycle = {
547 stage: Stage;
548 /** One sentence saying what is happening, or why it stopped. */
549 detail: string;
550 /** How many times the agent has been sent back to revise it. */
551 revisions: number;
552};
553
554/**
555 * How a repository wants its pull requests handled. A repository that has
556 * changed nothing has the defaults.
557 */
558export type RepoSettings = {
559 /**
560 * Land a g1t agent's pull request without a person once it is ready:
561 * checks passed and approved as the settings below require.
562 */
563 autoMerge: boolean;
564 /**
565 * The checks that must pass on a pull request's head before it may merge
566 * into the default branch, by name: a workflow's name (`CI`) or another
567 * status's context (`g1t / deploy`). The same for people and agents, and
568 * for the merge queue.
569 */
570 requiredChecks: string[];
571 /**
572 * Refuse to merge a pull request that does not contain the default
573 * branch's latest commits, so that what merges is what was checked. When
574 * off, merging one that is behind brings it up to date first.
575 */
576 requireUpToDate: boolean;
577 /**
578 * How many approving reviews a pull request needs before it may merge. A
579 * reviewer who has since asked for changes blocks it.
580 */
581 requiredApprovals: number;
582 /** Whether a g1t agent's approval counts towards `requiredApprovals`. */
583 countAgentApprovals: boolean;
584 /** Whether someone who may merge can bypass required checks that have not passed. */
585 allowIgnoringChecks: boolean;
586 /**
587 * Merge through a queue: pull requests are tested together with those
588 * ahead of them, and only a combination that passed reaches the default
589 * branch.
590 */
591 mergeQueue: boolean;
592 /**
593 * Refuse to merge until the code owners of every file it changes have
594 * approved, as many as each section asks. People only; `g1t` only where
595 * the file names `@g1t`.
596 */
597 requireCodeOwnerReview?: boolean;
598 /** Username of the member who last changed the settings, if anyone has. */
599 updatedBy: string | null;
600 /** RFC 3339. */
601 updatedAt: string | null;
602};
603
604/** The settings a member can change. */
605export type RepoSettingsInput = Omit<RepoSettings, "updatedBy" | "updatedAt">;
606
607/**
608 * What the runner is to do next for a pull request: always nothing now,
609 * since no step of a pull request is carried out in a sandbox any more.
610 */
611export type Advance = { action: "none" };
612
613export type OpenIssueInput = {
614 title: string;
615 body: string;
616 labels?: string[];
617 /** Deprecated: commands, added to the body under "Definition of done". */
618 checks?: string[];
619 /** The number of the milestone to put it in. Needs the Triage role. */
620 milestone?: number;
621};
622
623export type UpdateIssueInput = {
624 title?: string;
625 body?: string;
626 labels?: string[];
627 /** Usernames of the people it is assigned to; replaces the whole set. */
628 assignees?: string[];
629 /** The number of the milestone to put it in; 0 takes it out. */
630 milestone?: number;
631};
632
633export type OpenPullInput = {
634 /** The number of the issue this is for. */
635 issue?: number;
636 /** Defaults to the issue's title; required without an issue. */
637 title?: string;
638 /** What changed and why. Usually set later, when a draft is marked ready. */
639 body?: string;
640 /**
641 * A branch of the repository that already holds the change. The pull
642 * request is then ready for review at once and has no fork.
643 */
644 branch?: string;
645 agent: string;
646 runtime: Runtime;
647 /** The branch to merge into: the default branch when left out. */
648 base?: string;
649 /**
650 * Opened from a branch as a draft, still being worked on: it can't merge,
651 * and agents' review routines wait, until it is marked ready.
652 */
653 draft?: boolean;
654};
655
656/** One repository's pull requests from `pullsForRepos`, newest first. */
657export type RepoPulls = {
658 repoId: string;
659 /** Draft and open. */
660 open: Pull[];
661 /** Merged and closed. */
662 closed: Pull[];
663};
664
665/** Issues, pull requests, comments and sessions. */
666export interface WorkApi extends RulesApi, ChecksApi {
667 openIssue(actor: User, repo: RepoPath, input: OpenIssueInput): Promise<Result<Issue>>;
668 /** Newest first. */
669 listIssues(
670 repo: RepoPath,
671 viewer: Viewer,
672 filter?: { state?: State; label?: string; milestone?: number },
673 ): Promise<Result<Issue[]>>;
674 getIssue(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<IssueDetail>>;
675 /** The author or a member of the workspace may. */
676 updateIssue(actor: User, repo: RepoPath, number: number, input: UpdateIssueInput): Promise<Result<Issue>>;
677 closeIssue(actor: User, repo: RepoPath, number: number, reason?: IssueReason): Promise<Result<Issue>>;
678 reopenIssue(actor: User, repo: RepoPath, number: number): Promise<Result<Issue>>;
679 /** A repository's labels, by name, each with how many issues and pull requests carry it. */
680 listLabels(repo: RepoPath, viewer: Viewer): Promise<Result<Label[]>>;
681 /**
682 * Creates a label, or with `name` changes one; renaming it renames it on
683 * everything that carries it. Needs the Triage role.
684 */
685 saveLabel(
686 actor: User,
687 repo: RepoPath,
688 label: { name?: string; newName?: string; color?: string; description?: string },
689 ): Promise<Result<Label>>;
690 /** Removes a label from the repository and everything carrying it. */
691 deleteLabel(actor: User, repo: RepoPath, name: string): Promise<Result<boolean>>;
692 /** Adds the default labels the repository does not have yet; returns them all. */
693 addDefaultLabels(actor: User, repo: RepoPath): Promise<Result<Label[]>>;
694 /**
695 * The labels of an issue or a pull request, replaced, added to or taken
696 * from. Labels the repository lacks are created for someone with the
697 * Triage role. Returns its labels now.
698 */
699 setLabels(
700 actor: User,
701 repo: RepoPath,
702 number: number,
703 labels: string[],
704 change?: LabelChange,
705 ): Promise<Result<string[]>>;
706 /** Open ones by due date, then closed ones; both unless `state` says. */
707 listMilestones(repo: RepoPath, viewer: Viewer, state?: State): Promise<Result<Milestone[]>>;
708 getMilestone(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<MilestoneDetail>>;
709 /** Creates a milestone, or with `number` changes the fields given. Needs the Triage role. */
710 saveMilestone(
711 actor: User,
712 repo: RepoPath,
713 milestone: { number?: number; title?: string; description?: string; dueOn?: string; state?: State },
714 ): Promise<Result<Milestone>>;
715 deleteMilestone(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
716 /** How many issues and pull requests are open. */
717 counts(repo: RepoPath, viewer: Viewer): Promise<Result<{ issues: number; pulls: number }>>;
718
719 /**
720 * On an issue or a pull request. On a pull request it may name a line of
721 * the change and carry a verdict; nobody can give a verdict on their own.
722 */
723 addComment(actor: User, repo: RepoPath, number: number, comment: NewComment): Promise<Result<Comment>>;
724 /**
725 * Changes a comment's text. Its author may, and so may anyone with the
726 * Maintain role or higher; notes of what happened cannot be changed.
727 */
728 editComment(actor: User, repo: RepoPath, commentId: string, body: string): Promise<Result<Comment>>;
729 /**
730 * Deletes a comment: its author, or anyone with the Maintain role or
731 * higher. A review that gave a verdict cannot be deleted, only edited.
732 */
733 deleteComment(actor: User, repo: RepoPath, commentId: string): Promise<Result<boolean>>;
734
735 /**
736 * Always refused now: a pull request's checks are the workflows run on
737 * it. Kept for a runner from before.
738 */
739 startChecks(pullId: string): Promise<Result<CheckJob>>;
740 /**
741 * What a sandbox says about a run from before checks were workflows: so
742 * one still finishing is recorded.
743 */
744 reportChecks(runId: string, token: string, report: CheckReport): Promise<Result<CheckRun>>;
745 /**
746 * Claims the probe of whether a pull request merges cleanly that a
747 * `pull.mergecheck` event asked for. Refused when it is no longer wanted
748 * or the repository has as many running as it may. For the runner service.
749 */
750 startMergecheck(pullId: string): Promise<Result<MergecheckJob>>;
751 /** Records that a probe could not be carried out. For the runner service. */
752 failMergecheck(pullId: string, token: string, error: string): Promise<Result<Mergeable>>;
753
754 /**
755 * Works out the next step for a pull request g1t is seeing through and,
756 * if there is one to take now, claims it, so that it is taken once
757 * however often this is called. For the runner service.
758 */
759 advance(pullId: string): Promise<Advance>;
760 /** Records that a step could not be carried out, so a person is asked. */
761 stall(pullId: string, reason: string): Promise<boolean>;
762 /** Ids of the open pull requests g1t is seeing through. */
763 managedPulls(repoId?: string): Promise<string[]>;
764
765 /** A repository's merge queue: what is in it, in order, and what recently left. */
766 queue(repo: RepoPath, viewer: Viewer): Promise<Result<QueueView>>;
767 /**
768 * The next batch of combined states to test for a repository, one per
769 * entry; empty while a batch is being tested or nothing waits.
770 */
771 queueBuild(repoId: string): Promise<QueueJob[]>;
772 /** Reports that a combined state could not be built or checked. */
773 failQueue(entryId: string, token: string, error: string): Promise<Result<QueueState>>;
774 /** Takes a pull request out of the merge queue. Members only. */
775 removeFromQueue(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
776
777 getSettings(repo: RepoPath, viewer: Viewer): Promise<Result<RepoSettings>>;
778 /** The check names reported on the repository's commits in the last 30 days, most recent first. */
779 seenChecks(repo: RepoPath, viewer: Viewer): Promise<Result<SeenCheck[]>>;
780 /** Members of the repository's workspace only. */
781 updateSettings(actor: User, repo: RepoPath, settings: RepoSettingsInput): Promise<Result<RepoSettings>>;
782 /** The CODEOWNERS file at a branch (the default when left out), checked. Needs Read. */
783 codeownersErrors(repo: RepoPath, viewer: Viewer, ref?: string | null): Promise<Result<CodeownersReport>>;
784
785 /**
786 * Opens a pull request: a draft with a fork to push to, or, given a
787 * branch, one ready for review.
788 */
789 openPull(actor: User, repo: RepoPath, input: OpenPullInput): Promise<Result<Pull>>;
790 /** Newest first. */
791 listPulls(
792 repo: RepoPath,
793 viewer: Viewer,
794 state?: State,
795 filter?: { label?: string; milestone?: number; base?: string },
796 ): Promise<Result<Pull[]>>;
797 /**
798 * The newest `limit` open and closed pull requests of each repository,
799 * in one call. Repositories the viewer cannot read, and forks, are left
800 * out: ask those with `listPulls`.
801 */
802 pullsForRepos(repoIds: string[], viewer: Viewer, limit: number): Promise<RepoPulls[]>;
803 getPull(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<PullDetail>>;
804 /**
805 * Changes who a pull request is assigned to and whose review is asked
806 * for; each list given replaces the whole set. Asking for `g1t`'s
807 * review does not by itself start one: the runner's `review` does.
808 */
809 updatePull(
810 actor: User,
811 repo: RepoPath,
812 number: number,
813 changes: {
814 assignees?: string[];
815 reviewers?: string[];
816 labels?: string[];
817 /** 0 takes it out of its milestone. */
818 milestone?: number;
819 /** The branch it merges into. Needs the Write role. */
820 base?: string;
821 },
822 ): Promise<Result<Pull>>;
823 /**
824 * Brings a pull request up to date with the default branch in seconds,
825 * without a sandbox, when the two changed different files: the merge
826 * commit is pushed to its branch as `actor`, who must be whoever opened
827 * it (for a fork) or a member (for a branch). Otherwise `needs_agent`, and
828 * nothing is pushed: the runner's `update` is the way on.
829 */
830 catchUpPull(actor: User, repo: RepoPath, number: number): Promise<Result<PullBranchUpdate>>;
831 /** Marks a draft ready for review and sets its description. */
832 readyPull(actor: User, repo: RepoPath, number: number, summary: string): Promise<Result<Pull>>;
833 closePull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
834 /** Opens a closed pull request again, as the draft it was if it was closed as one. Never a merged one. */
835 reopenPull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
836 /** Turns an open pull request back into a draft; it leaves the merge queue. */
837 convertPullToDraft(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
838 /**
839 * Lands the pull request on the repository's default branch. Unless
840 * `keepIssueOpen`, that resolves the issue it was for: the issue closes
841 * naming this pull request, and the others still in progress for it close
842 * as superseded. Only members of the repository's workspace may merge.
843 *
844 * If the default branch has moved, the pull request is brought up to date
845 * first and lands when that is done; it comes back still open, and
846 * `PullDetail.landing` is true meanwhile. A repository that requires pull
847 * requests to be up to date refuses instead.
848 */
849 mergePull(
850 actor: User,
851 repo: RepoPath,
852 number: number,
853 options?: {
854 keepIssueOpen?: boolean;
855 /** Merge although required checks have not passed, where the rule requiring them allows it. */
856 ignoreChecks?: boolean;
857 /** Merge past rules a ruleset lets the actor bypass. Recorded as a bypass. */
858 bypassRules?: boolean;
859 },
860 ): Promise<Result<Pull>>;
861 /**
862 * Drafts and open pull requests the viewer started, most recently active
863 * first, each with where it stands if g1t is seeing it through.
864 */
865 listActivePulls(
866 viewer: Viewer,
867 ): Promise<{ pull: Pull; issue: Issue | null; lifecycle: Lifecycle | null }[]>;
868 /**
869 * The issues and pull requests a person opened, a page at a time, only
870 * on repositories the viewer may read. Not found for no such account.
871 */
872 byAuthor(username: string, viewer: Viewer, filter?: AuthoredFilter): Promise<Result<Authored>>;
873 /**
874 * What a person did each day of the last year (issues and pull requests
875 * opened, reviews given), only on repositories the viewer may read: the
876 * calendar on their profile. Not found for no such account.
877 */
878 contributions(username: string, viewer: Viewer): Promise<Result<Contributions>>;
879
880
881 /** Open issues assigned to the viewer, most recently changed first. */
882 listAssignedIssues(viewer: Viewer): Promise<Issue[]>;
883
884 appendSession(actor: User, repo: RepoPath, number: number, entries: NewSessionEntry[]): Promise<Result<{ count: number }>>;
885 readSession(repo: RepoPath, number: number, viewer: Viewer, afterSeq?: number): Promise<Result<SessionEntry[]>>;
886}
887
888/**
889 * What to pass `ReposApi.compare` to see what a pull request changes.
890 *
891 * A fork is compared as a whole. A branch is compared by name while the
892 * pull request is open, and by the commit it was merged or closed at
893 * afterwards, so later pushes to the branch do not change the record.
894 */
895export function pullComparison(pull: Pull): {
896 repoId: string;
897 base: string | null;
898 head: string | null;
899 /** The branch it merges into, which it is compared from. */
900 baseBranch: string | null;
901} {
902 const baseBranch = pull.base ?? null;
903 if (pull.forkRepoId) return { repoId: pull.forkRepoId, base: pull.mergeBase, head: null, baseBranch };
904 const settled = pull.status === "merged" || pull.status === "closed";
905 return {
906 repoId: pull.repoId,
907 base: pull.mergeBase,
908 head: (settled && pull.headCommit) || pull.branch,
909 baseBranch,
910 };
911}
912
913
914export type QueueState = "waiting" | "testing" | "passed" | "failed" | "landed" | "removed";
915
916/** One pull request's place in a merge queue. */
917export type QueueEntry = {
918 id: string;
919 number: number;
920 title: string;
921 agent: string;
922 state: QueueState;
923 /** The pull requests merged ahead of it in the state being tested, in order. */
924 ahead: number[];
925 baseCommit: string | null;
926 combinedCommit: string | null;
927 error: string | null;
928 results: CheckResult[];
929 /** Username of whoever merged it into the queue: a person, or `g1t`. */
930 enqueuedBy: string;
931 /** RFC 3339. */
932 createdAt: string;
933 /** RFC 3339. */
934 finishedAt: string | null;
935};
936
937/** A repository's merge queue: what is in it, in order, and what recently left. */
938export type QueueView = {
939 enabled: boolean;
940 active: QueueEntry[];
941 /** Newest first. */
942 recent: QueueEntry[];
943};
944
945export type QueueStackItem = {
946 number: number;
947 title: string;
948 /** The repository holding the change, and its branch. */
949 source: RepoPath;
950 branch: string;
951 commit: string;
952};
953
954/** What a sandbox needs to build and check one combined state. */
955export type QueueJob = {
956 entryId: string;
957 token: string;
958 repo: RepoPath;
959 defaultBranch: string;
960 baseCommit: string;
961 branch: string;
962 stack: QueueStackItem[];
963 /** Always empty: the state is checked by the merge_group workflows run on it. */
964 checks: string[];
965 /** Always empty, as `checks`. */
966 contractChecks: string[];
967 actor: User;
968};
969
970// --- A person's work ---------------------------------------------------------
971// Mirrors the `Authored*` types in `crates/contracts/src/work.rs`.
972
973export type AuthoredKind = "issue" | "pull";
974/** `closed` takes in merged pull requests too; `merged` is only those. */
975export type AuthoredState = "open" | "closed" | "merged";
976/** `created` is newest first, `updated` most recently changed, `oldest` oldest first. */
977export type AuthoredSort = "created" | "updated" | "oldest";
978
979/** The most items one `byAuthor` page holds. */
980export const AUTHORED_PAGE = 25;
981
982export type AuthoredFilter = {
983 kind?: AuthoredKind;
984 state?: AuthoredState;
985 /** `namespace/name`. */
986 repo?: string;
987 sort?: AuthoredSort;
988 /** The `next` of the page before. */
989 before?: string;
990 limit?: number;
991};
992
993export type AuthoredItem = {
994 kind: AuthoredKind;
995 repo: RepoPath;
996 number: number;
997 title: string;
998 /** A merged pull request is closed. */
999 state: State;
1000 /** A pull request's own status; null on an issue. */
1001 status: PullStatus | null;
1002 /** Why an issue was closed. */
1003 reason: IssueReason | null;
1004 draft: boolean;
1005 merged: boolean;
1006 /** RFC 3339. */
1007 createdAt: string;
1008 /** RFC 3339. */
1009 updatedAt: string;
1010 /** RFC 3339. */
1011 mergedAt: string | null;
1012};
1013
1014/** Over every repository the viewer may read, whatever the filters. */
1015export type AuthoredCounts = {
1016 pullsMerged: number;
1017 pullsOpen: number;
1018 pulls: number;
1019 issues: number;
1020 issuesOpen: number;
1021};
1022
1023export type Authored = {
1024 items: AuthoredItem[];
1025 /** Pass as `before` for the next page; null on the last. */
1026 next: string | null;
1027 counts: AuthoredCounts;
1028 /** The repositories they worked in that the viewer may read, most work first. */
1029 repos: { repo: RepoPath; count: number }[];
1030};
1031
1032// Mirrors `Contributions` in `crates/contracts/src/work.rs`.
1033
1034/** How many days `contributions` covers: today and the 364 before it. */
1035export const CONTRIBUTION_DAYS = 365;
1036
1037/** One day with something on it; days with nothing are left out. */
1038export type ContributionDay = {
1039 /** `YYYY-MM-DD`, UTC. */
1040 date: string;
1041 /** Everything that day, commits included. */
1042 count: number;
1043 /** How many of `count` are commits they pushed to a default branch. */
1044 commits?: number;
1045};
1046
1047/** A person's year, as far as the viewer may see. */
1048export type Contributions = {
1049 /** Oldest first. */
1050 days: ContributionDay[];
1051 total: number;
1052 /** The first day counted, `YYYY-MM-DD`; the last is today (UTC). */
1053 from: string;
1054};