g1t/crates/contracts/src/work.rs

1,304 lines42,843 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Issues and pull requests replace intents and attempts1//! The work service: issues, pull requests, comments and sessions.
Work service in Rust, with RFC 3339 timestamps2//!
3//! Each `*Args` struct is the argument of the method of the same name,
4//! served at `POST /rpc/<method>`.
Issues and pull requests replace intents and attempts5//!
6//! Issues and pull requests share one sequence of numbers per repository,
7//! so `#12` names exactly one of them.
Work service in Rust, with RFC 3339 timestamps8
9use serde::{Deserialize, Serialize};
10
Agents as a team: lifecycle, merge queue, billing and a new shell11use crate::repos::{CompareArgs, RepoPath};
Work service in Rust, with RFC 3339 timestamps12use crate::{User, Viewer};
13
Issues and pull requests replace intents and attempts14/// Labels every repository starts with. Any other label comes into being
15/// the first time it is put on an issue.
16pub const DEFAULT_LABELS: [&str; 5] = ["bug", "feature", "docs", "chore", "question"];
17
18/// `open` or `closed`: the filter on lists of issues and pull requests. An
19/// open pull request is a draft or one ready for review; a closed one was
20/// merged or closed without merging.
Work service in Rust, with RFC 3339 timestamps21#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "lowercase")]
Issues and pull requests replace intents and attempts23pub enum State {
Work service in Rust, with RFC 3339 timestamps24 Open,
Issues and pull requests replace intents and attempts25 Closed,
26}
27
28/// Why an issue was closed.
29#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
30#[serde(rename_all = "snake_case")]
31pub enum IssueReason {
32 /// The work was done. If a pull request did it, `resolved_by` names it.
33 Completed,
34 NotPlanned,
Work service in Rust, with RFC 3339 timestamps35}
36
Issues and pull requests replace intents and attempts37impl IssueReason {
38 pub fn as_str(self) -> &'static str {
39 match self {
40 IssueReason::Completed => "completed",
41 IssueReason::NotPlanned => "not_planned",
42 }
43 }
44}
45
46/// Something that should change in a repository: a bug, a feature, a
47/// question. Opened by a person, an agent or an integration. Pull requests
48/// are made against it; the one that is merged resolves it.
Work service in Rust, with RFC 3339 timestamps49#[derive(Clone, Debug, Serialize, Deserialize)]
50#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts51pub struct Issue {
Work service in Rust, with RFC 3339 timestamps52 pub id: String,
53 pub repo_id: String,
Issues and pull requests replace intents and attempts54 /// Shown as `#12`.
Work service in Rust, with RFC 3339 timestamps55 pub number: u32,
56 pub title: String,
Issues and pull requests replace intents and attempts57 /// Markdown. Also what an agent is given to work from.
58 pub body: String,
59 pub labels: Vec<String>,
60 /// Commands that must pass for a pull request to be accepted.
Work service in Rust, with RFC 3339 timestamps61 pub checks: Vec<String>,
Issues and pull requests replace intents and attempts62 pub state: State,
63 /// Set when closed.
64 pub reason: Option<IssueReason>,
65 /// The number of the pull request whose merge closed this issue.
66 pub resolved_by: Option<u32>,
Work service in Rust, with RFC 3339 timestamps67 pub author: User,
68 /// RFC 3339.
69 pub created_at: String,
Issues and pull requests replace intents and attempts70 /// RFC 3339.
71 pub updated_at: String,
72 /// RFC 3339.
73 pub closed_at: Option<String>,
74 /// Pull requests made against this issue, in any state.
75 pub pull_count: u32,
76 pub comment_count: u32,
Agents as a team: lifecycle, merge queue, billing and a new shell77 /// Usernames of the people it is assigned to.
78 #[serde(default)]
79 pub assignees: Vec<String>,
80 /// The numbers of the issues that have to be merged before this one is
81 /// worked on.
82 #[serde(default)]
83 pub blocked_by: Vec<u32>,
84 /// Whether a g1t agent takes it as soon as it can: at once, or when
85 /// what it is blocked by has merged.
86 #[serde(default)]
87 pub queued: bool,
88 /// The agent working on it now: the one behind its newest pull request
89 /// that is still in progress in a fork, such as `g1t-agent`.
90 #[serde(default)]
91 pub agent: Option<String>,
Work service in Rust, with RFC 3339 timestamps92}
93
94#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
95#[serde(rename_all = "lowercase")]
Issues and pull requests replace intents and attempts96pub enum PullStatus {
97 /// Still being worked on.
98 Draft,
99 /// Ready for review.
100 Open,
101 Merged,
102 /// Closed without merging.
103 Closed,
Work service in Rust, with RFC 3339 timestamps104}
105
Issues and pull requests replace intents and attempts106impl PullStatus {
Work service in Rust, with RFC 3339 timestamps107 pub fn as_str(self) -> &'static str {
108 match self {
Issues and pull requests replace intents and attempts109 PullStatus::Draft => "draft",
110 PullStatus::Open => "open",
111 PullStatus::Merged => "merged",
112 PullStatus::Closed => "closed",
Work service in Rust, with RFC 3339 timestamps113 }
114 }
115
Issues and pull requests replace intents and attempts116 /// Whether the pull request can still be changed or merged.
Work service in Rust, with RFC 3339 timestamps117 pub fn is_active(self) -> bool {
Issues and pull requests replace intents and attempts118 matches!(self, PullStatus::Draft | PullStatus::Open)
Work service in Rust, with RFC 3339 timestamps119 }
120}
121
122/// Where the agent runs: on g1t's sandboxes, or in someone's own session.
123#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
124#[serde(rename_all = "lowercase")]
Issues and pull requests replace intents and attempts125pub enum Runtime {
Work service in Rust, with RFC 3339 timestamps126 Hosted,
127 External,
128}
129
Pull requests from branches130/// A proposed change. It is made either in a fork created for it, which is
131/// how agents work, or on a branch pushed to the repository itself.
Work service in Rust, with RFC 3339 timestamps132#[derive(Clone, Debug, Serialize, Deserialize)]
133#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts134pub struct Pull {
Work service in Rust, with RFC 3339 timestamps135 pub id: String,
136 pub repo_id: String,
Issues and pull requests replace intents and attempts137 /// Shown as `#12`.
Work service in Rust, with RFC 3339 timestamps138 pub number: u32,
Issues and pull requests replace intents and attempts139 /// The number of the issue this is for, if any.
140 pub issue: Option<u32>,
141 pub title: String,
142 /// Markdown: what changed and why. Set when marked ready.
143 pub body: Option<String>,
Work service in Rust, with RFC 3339 timestamps144 /// A label for the agent doing the work, e.g. `claude-code`.
145 pub agent: String,
Issues and pull requests replace intents and attempts146 pub runtime: Runtime,
147 pub status: PullStatus,
Pull requests from branches148 /// The fork holding the change, unless it is on a branch.
149 pub fork: Option<RepoPath>,
Work service in Rust, with RFC 3339 timestamps150 /// The fork's repository id.
Pull requests from branches151 pub fork_repo_id: Option<String>,
152 /// The branch of the repository holding the change, unless it is in a
153 /// fork.
154 pub branch: Option<String>,
Work service in Rust, with RFC 3339 timestamps155 pub head_commit: Option<String>,
Issues and pull requests replace intents and attempts156 /// For a merged pull request, what the branch pointed to before the
157 /// merge. Comparing against it shows what the pull request changed.
158 pub merge_base: Option<String>,
159 /// Username of whoever merged it.
160 pub merged_by: Option<String>,
161 /// RFC 3339.
162 pub merged_at: Option<String>,
163 /// Set on a pull request closed because another one for the same issue
164 /// was merged: that one's number.
165 pub superseded_by: Option<u32>,
Acceptance checks in sandboxes, line comments and review verdicts166 /// Where the latest run of the issue's acceptance checks stands, if
167 /// there has been one against the current head.
168 pub check_status: Option<CheckStatus>,
Agents as a team: lifecycle, merge queue, billing and a new shell169 /// The files it changes, as of its latest push.
170 #[serde(default)]
171 pub files: Vec<ChangedFile>,
172 /// Usernames of the people it is assigned to.
173 #[serde(default)]
174 pub assignees: Vec<String>,
175 /// Those whose review was asked for: usernames, and `g1t-agent` when a
176 /// g1t agent was asked.
177 #[serde(default)]
178 pub reviewers: Vec<String>,
Issues and pull requests replace intents and attempts179 pub author: User,
Work service in Rust, with RFC 3339 timestamps180 /// RFC 3339.
181 pub created_at: String,
182 /// RFC 3339.
183 pub updated_at: String,
184}
185
Agents as a team: lifecycle, merge queue, billing and a new shell186/// One file a pull request changes, and by how much.
187#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
188pub struct ChangedFile {
189 pub path: String,
190 pub additions: u32,
191 pub deletions: u32,
192}
193
194/// Another pull request in progress that changes some of the same files.
195/// Two for the same issue are alternatives; two for different issues are
196/// heading for a conflict.
197#[derive(Clone, Debug, Serialize, Deserialize)]
198pub struct Overlap {
199 pub number: u32,
200 pub title: String,
201 /// The number of the issue the other pull request is for.
202 pub issue: Option<u32>,
203 /// The files both change.
204 pub paths: Vec<String>,
205}
206
207impl Pull {
208 /// What to ask the repos service to see what this pull request changes.
209 ///
210 /// A fork is compared as a whole. A branch is compared by name while
211 /// the pull request is open, and by the commit it was merged or closed
212 /// at afterwards, so later pushes to the branch do not change the record.
213 pub fn comparison(&self, viewer: &Viewer) -> CompareArgs {
214 let settled = matches!(self.status, PullStatus::Merged | PullStatus::Closed);
215 let (repo_id, head) = match &self.fork_repo_id {
216 Some(fork) => (fork.clone(), None),
217 None => (
218 self.repo_id.clone(),
219 self.head_commit
220 .clone()
221 .filter(|_| settled)
222 .or_else(|| self.branch.clone()),
223 ),
224 };
225 CompareArgs {
226 repo_id,
227 viewer: viewer.clone(),
228 base: self.merge_base.clone(),
229 head,
230 }
231 }
232}
233
Acceptance checks in sandboxes, line comments and review verdicts234#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
235#[serde(rename_all = "lowercase")]
236pub enum CheckStatus {
237 /// Waiting for a sandbox.
238 Queued,
239 Running,
240 Passed,
241 Failed,
242 /// The checks could not be run at all.
243 Errored,
244}
245
246impl CheckStatus {
247 pub fn as_str(self) -> &'static str {
248 match self {
249 CheckStatus::Queued => "queued",
250 CheckStatus::Running => "running",
251 CheckStatus::Passed => "passed",
252 CheckStatus::Failed => "failed",
253 CheckStatus::Errored => "errored",
254 }
255 }
256}
257
258/// How one acceptance check went.
259#[derive(Clone, Debug, Serialize, Deserialize)]
260#[serde(rename_all = "camelCase")]
261pub struct CheckResult {
262 pub command: String,
263 pub passed: bool,
264 /// Absent when the command was stopped for taking too long.
265 #[serde(default)]
266 pub exit_code: Option<i32>,
267 /// What the command printed, standard output and error together. The
268 /// end of it, when there was a lot.
269 #[serde(default)]
270 pub output: String,
271 #[serde(default)]
272 pub duration_ms: u64,
273}
274
275/// One run of an issue's acceptance checks against a pull request's head,
276/// in a sandbox that holds nothing but that commit.
277#[derive(Clone, Debug, Serialize, Deserialize)]
278#[serde(rename_all = "camelCase")]
279pub struct CheckRun {
280 pub id: String,
281 /// The commit that was checked.
282 pub head_commit: String,
283 pub status: CheckStatus,
284 pub results: Vec<CheckResult>,
285 /// Why the checks could not be run, when `status` is `errored`.
286 pub error: Option<String>,
287 /// RFC 3339.
288 pub created_at: String,
289 /// RFC 3339.
290 pub finished_at: Option<String>,
291}
292
293/// A reviewer's decision on a pull request.
294#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
295#[serde(rename_all = "snake_case")]
296pub enum Verdict {
297 Approve,
298 RequestChanges,
299}
300
301impl Verdict {
302 pub fn as_str(self) -> &'static str {
303 match self {
304 Verdict::Approve => "approve",
305 Verdict::RequestChanges => "request_changes",
306 }
307 }
308}
309
Agents as a team: lifecycle, merge queue, billing and a new shell310/// What an entry in a conversation is.
311#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
312#[serde(rename_all = "lowercase")]
313pub enum CommentKind {
314 /// Something a person or an agent wrote.
315 #[default]
316 Comment,
317 /// Something that happened: an assignment, a review asked for, a close.
318 Event,
319}
320
Acceptance checks in sandboxes, line comments and review verdicts321/// A comment on an issue or a pull request. On a pull request it can sit
322/// on one line of the change, and it can carry a reviewer's verdict.
Issues and pull requests replace intents and attempts323#[derive(Clone, Debug, Serialize, Deserialize)]
324#[serde(rename_all = "camelCase")]
325pub struct Comment {
326 pub id: String,
Agents as a team: lifecycle, merge queue, billing and a new shell327 /// Something a person wrote, or something that happened.
328 #[serde(default)]
329 pub kind: CommentKind,
Issues and pull requests replace intents and attempts330 pub author: User,
Agents as a team: lifecycle, merge queue, billing and a new shell331 /// Markdown. For an event, what its author did, as the rest of a
332 /// sentence that starts with their name: "assigned ana".
Issues and pull requests replace intents and attempts333 pub body: String,
Acceptance checks in sandboxes, line comments and review verdicts334 /// The file commented on, for a comment on a line.
335 pub path: Option<String>,
336 /// The line of that file, as numbered after the change.
337 pub line: Option<u32>,
338 pub verdict: Option<Verdict>,
Issues and pull requests replace intents and attempts339 /// RFC 3339.
340 pub created_at: String,
341}
342
Work service in Rust, with RFC 3339 timestamps343#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
344#[serde(rename_all = "snake_case")]
345pub enum SessionEntryKind {
346 Prompt,
347 Message,
348 ToolCall,
349 ToolResult,
350 Note,
351}
352
Issues and pull requests replace intents and attempts353/// One step of an agent's session: the "why" behind a pull request's commits.
Work service in Rust, with RFC 3339 timestamps354#[derive(Clone, Debug, Serialize, Deserialize)]
355pub struct SessionEntry {
356 pub seq: u32,
357 pub kind: SessionEntryKind,
358 pub text: String,
359 /// For tool calls and results.
360 pub tool: Option<String>,
361 /// The fork's head commit when this entry was recorded, if known.
362 pub commit: Option<String>,
363 /// RFC 3339.
364 pub at: String,
365}
366
367#[derive(Clone, Debug, Serialize, Deserialize)]
368pub struct NewSessionEntry {
369 pub kind: SessionEntryKind,
370 pub text: String,
371 #[serde(default)]
372 pub tool: Option<String>,
373 #[serde(default)]
374 pub commit: Option<String>,
375}
376
377#[derive(Clone, Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts378pub struct IssueDetail {
379 pub issue: Issue,
380 /// Every pull request made against it, oldest first.
381 pub pulls: Vec<Pull>,
382 pub comments: Vec<Comment>,
Work service in Rust, with RFC 3339 timestamps383}
384
385#[derive(Clone, Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts386pub struct PullDetail {
387 pub pull: Pull,
388 /// The issue it is for, if any.
389 pub issue: Option<Issue>,
390 pub comments: Vec<Comment>,
Acceptance checks in sandboxes, line comments and review verdicts391 /// The latest run of the issue's acceptance checks.
392 pub checks: Option<CheckRun>,
Agents as a team: lifecycle, merge queue, billing and a new shell393 /// Other pull requests in progress that change the same files.
394 #[serde(default)]
395 pub overlaps: Vec<Overlap>,
396 /// Whether the branch it would merge into has moved on without it, so
397 /// that it has to catch up before it can merge.
398 #[serde(default)]
399 pub behind: bool,
400 /// Whether a g1t agent is reviewing it right now.
401 #[serde(default)]
402 pub review_pending: bool,
403 /// Where it stands on its way to being merged, for a pull request g1t
404 /// is seeing through. Absent on anyone else's.
405 #[serde(default)]
406 pub lifecycle: Option<Lifecycle>,
407 /// A merge was asked for while it was behind: g1t is bringing it up to
408 /// date and will then land it.
409 #[serde(default)]
410 pub landing: bool,
411 /// Why g1t stopped working on it, if it did: a catch-up that could not
412 /// be completed, for example.
413 #[serde(default)]
414 pub stalled: Option<String>,
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request415 /// Messages people sent the agent while it worked, oldest first.
416 #[serde(default)]
417 pub messages: Vec<AgentMessage>,
418}
419
420/// A message a person sent an agent at work on a pull request. The agent
421/// receives it at its next step.
422#[derive(Clone, Debug, Serialize, Deserialize)]
423#[serde(rename_all = "camelCase")]
424pub struct AgentMessage {
425 pub id: String,
426 pub author: String,
427 pub body: String,
428 /// RFC 3339.
429 pub created_at: String,
430 /// RFC 3339. When the agent received it; null until then.
431 pub delivered_at: Option<String>,
432}
433
434/// `message_agent`: sends the agent working on a pull request a message.
435/// The pull request's author and members of the workspace may. Returns
436/// `Outcome<AgentMessage>`.
437#[derive(Debug, Serialize, Deserialize)]
438pub struct MessageAgentArgs {
439 pub actor: User,
440 pub repo: RepoPath,
441 pub number: u32,
442 pub body: String,
443}
444
445/// `take_messages`: the messages not yet delivered to the agent working on
446/// a pull request, marked delivered. Only g1t's agents may. Returns
447/// `Outcome<Vec<AgentMessage>>`.
448#[derive(Debug, Serialize, Deserialize)]
449pub struct TakeMessagesArgs {
450 pub actor: User,
451 pub repo: RepoPath,
452 pub number: u32,
Agents as a team: lifecycle, merge queue, billing and a new shell453}
454
455/// A step on the way from an assigned issue to a pull request that is ready
456/// to merge. g1t takes each one without being asked.
457#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
458#[serde(rename_all = "snake_case")]
459pub enum Stage {
460 /// The agent is making the change.
461 Working,
462 /// The issue's acceptance checks are running against it.
463 Checking,
464 /// A g1t agent is reviewing it.
465 Reviewing,
466 /// The agent is addressing failed checks or a review.
467 Revising,
468 /// The agent is merging in the branch it would land on, which moved.
469 CatchingUp,
470 /// In the repository's merge queue, being tested with what is ahead of
471 /// it before it lands.
472 Queued,
473 /// Checks passed, reviewed and approved, up to date. A person merges.
474 Ready,
475 /// g1t has stopped and a person has to decide what happens next.
476 NeedsYou,
477}
478
479/// Where a pull request made by a g1t agent stands. See [`Stage`].
480#[derive(Clone, Debug, Serialize, Deserialize)]
481pub struct Lifecycle {
482 pub stage: Stage,
483 /// One sentence saying what is happening, or why it stopped.
484 pub detail: String,
485 /// How many times the agent has been sent back to revise it.
486 pub revisions: u32,
487}
488
489/// `advance`: works out the next step for a pull request g1t is seeing
490/// through and, if there is one to take now, claims it, so that it is
491/// taken once however many times this is called. Called by the runner
492/// service, which carries the step out. Returns `Advance`.
493#[derive(Debug, Serialize, Deserialize)]
494#[serde(rename_all = "camelCase")]
495pub struct AdvanceArgs {
496 pub pull_id: String,
497}
498
499#[derive(Debug, Serialize, Deserialize)]
500#[serde(tag = "action", rename_all = "snake_case")]
501pub enum Advance {
502 /// Nothing to do now: a step is under way, or it is a person's turn.
503 None,
504 /// Have a g1t agent review it.
505 Review { job: LifecycleJob },
506 /// Send the agent back to address `job.feedback`.
507 Revise { job: LifecycleJob },
508 /// Merge in the branch it would land on.
509 CatchUp { job: LifecycleJob },
Work service in Rust, with RFC 3339 timestamps510}
511
Agents as a team: lifecycle, merge queue, billing and a new shell512/// What the runner needs to carry out a step of a pull request's lifecycle.
513#[derive(Debug, Serialize, Deserialize)]
514#[serde(rename_all = "camelCase")]
515pub struct LifecycleJob {
516 pub pull_id: String,
517 pub repo: RepoPath,
518 pub number: u32,
519 /// Who the pull request belongs to. Sandboxes act as them.
520 pub author: User,
521 /// The repository holding the change: its fork, or the repository
522 /// itself for one made on a branch.
523 pub source: RepoPath,
524 /// The branch of the source holding the change; its default branch
525 /// when absent.
526 #[serde(default)]
527 pub branch: Option<String>,
528 pub default_branch: String,
529 pub title: String,
530 pub description: String,
531 pub issue: Option<Issue>,
532 /// For a revision: the failed checks or the review to address.
533 pub feedback: String,
534 /// For a revision: which one this is, from 1.
535 pub round: u32,
536}
537
538/// How a repository wants its pull requests handled. A repository that has
539/// changed nothing has the defaults.
540#[derive(Clone, Debug, Serialize, Deserialize)]
541#[serde(rename_all = "camelCase", default)]
542pub struct RepoSettings {
543 /// Land a g1t agent's pull request without a person once it is ready:
544 /// checks passed and approved as the settings below require.
545 pub auto_merge: bool,
546 /// Refuse to merge a pull request that does not contain the default
547 /// branch's latest commits, so that what merges is what was checked.
548 /// When off, merging one that is behind brings it up to date first.
549 pub require_up_to_date: bool,
550 /// How many approving reviews a pull request needs before it may
551 /// merge. A reviewer who has since asked for changes blocks it.
552 pub required_approvals: u32,
553 /// Whether a g1t agent's approval counts towards `required_approvals`.
554 pub count_agent_approvals: bool,
555 /// Whether a member may merge although the acceptance checks did not
556 /// pass.
557 pub allow_ignoring_checks: bool,
558 /// Whether a g1t agent's pull request is reviewed by a second agent
559 /// without being asked.
560 pub agent_review: bool,
561 /// How many times a g1t agent is sent back to its pull request before
562 /// a person is asked instead.
563 pub max_revisions: u32,
564 /// Merge through a queue: pull requests are tested together with those
565 /// ahead of them, and only a combination that passed reaches the default
566 /// branch.
567 pub merge_queue: bool,
568 /// Username of the member who last changed the settings, if anyone has.
569 pub updated_by: Option<String>,
570 /// RFC 3339.
571 pub updated_at: Option<String>,
572}
573
574impl Default for RepoSettings {
575 fn default() -> Self {
576 RepoSettings {
577 auto_merge: false,
578 require_up_to_date: false,
579 required_approvals: 0,
580 count_agent_approvals: true,
581 allow_ignoring_checks: true,
582 agent_review: true,
583 max_revisions: 2,
584 merge_queue: false,
585 updated_by: None,
586 updated_at: None,
587 }
588 }
589}
590
591/// `update_settings`: replaces a repository's settings. Members of its
592/// workspace only. Returns `Outcome<RepoSettings>`. `get_settings` takes
593/// `ViewArgs` and returns the same.
594#[derive(Debug, Serialize, Deserialize)]
595pub struct UpdateSettingsArgs {
596 pub actor: User,
597 pub repo: RepoPath,
598 /// Who changed them and when are filled in by the service.
599 pub settings: RepoSettings,
600}
601
602/// `catch_up_job`: what the runner needs to bring a pull request up to date
603/// because a merge of it was asked for. Null if none was. Returns
604/// `Option<LifecycleJob>`.
605#[derive(Debug, Serialize, Deserialize)]
606#[serde(rename_all = "camelCase")]
607pub struct CatchUpJobArgs {
608 pub pull_id: String,
609}
610
611/// `stall`: records that a step could not be carried out, so that g1t
612/// stops and a person is asked. Returns `bool`.
613#[derive(Debug, Serialize, Deserialize)]
614#[serde(rename_all = "camelCase")]
615pub struct StallArgs {
616 pub pull_id: String,
617 pub reason: String,
618}
619
620/// `managed_pulls`: ids of the open pull requests g1t is seeing through,
621/// in one repository or in all of them. Returns `Vec<String>`.
622#[derive(Debug, Default, Serialize, Deserialize)]
623#[serde(rename_all = "camelCase")]
624pub struct ManagedPullsArgs {
625 #[serde(default)]
626 pub repo_id: Option<String>,
627}
628
Issues and pull requests replace intents and attempts629/// `open_issue`. Returns `Outcome<Issue>`.
Work service in Rust, with RFC 3339 timestamps630#[derive(Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts631pub struct OpenIssueArgs {
Work service in Rust, with RFC 3339 timestamps632 pub actor: User,
633 pub repo: RepoPath,
634 pub title: String,
635 #[serde(default)]
Issues and pull requests replace intents and attempts636 pub body: String,
637 #[serde(default)]
638 pub labels: Vec<String>,
Work service in Rust, with RFC 3339 timestamps639 #[serde(default)]
640 pub checks: Vec<String>,
641}
642
Issues and pull requests replace intents and attempts643/// `list_issues`, newest first. Returns `Outcome<Vec<Issue>>`.
Work service in Rust, with RFC 3339 timestamps644#[derive(Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts645pub struct ListIssuesArgs {
Work service in Rust, with RFC 3339 timestamps646 pub repo: RepoPath,
647 pub viewer: Viewer,
648 #[serde(default)]
Issues and pull requests replace intents and attempts649 pub state: Option<State>,
650 /// Only issues carrying this label.
651 #[serde(default)]
652 pub label: Option<String>,
Work service in Rust, with RFC 3339 timestamps653}
654
Issues and pull requests replace intents and attempts655/// `list_pulls`, newest first. Returns `Outcome<Vec<Pull>>`.
Work service in Rust, with RFC 3339 timestamps656#[derive(Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts657pub struct ListPullsArgs {
658 pub repo: RepoPath,
659 pub viewer: Viewer,
660 #[serde(default)]
661 pub state: Option<State>,
662}
663
664/// `get_issue` (`Outcome<IssueDetail>`), `get_pull` (`Outcome<PullDetail>`),
665/// `read_session` (`Outcome<Vec<SessionEntry>>`), `list_labels`
666/// (`Outcome<Vec<String>>`) and `counts` (`Outcome<Counts>`). The last two
667/// ignore `number`.
668#[derive(Debug, Serialize, Deserialize)]
669#[serde(rename_all = "camelCase")]
670pub struct ViewArgs {
Work service in Rust, with RFC 3339 timestamps671 pub repo: RepoPath,
Issues and pull requests replace intents and attempts672 #[serde(default)]
Work service in Rust, with RFC 3339 timestamps673 pub number: u32,
674 pub viewer: Viewer,
Issues and pull requests replace intents and attempts675 /// For `read_session`: only entries after this sequence number.
676 #[serde(default)]
677 pub after_seq: u32,
678}
679
680/// How many issues and pull requests are open on a repository.
681#[derive(Debug, Serialize, Deserialize)]
682pub struct Counts {
683 pub issues: u32,
684 pub pulls: u32,
685}
686
687/// `update_issue`: changes whichever fields are given. The author or a
688/// member of the workspace may. Returns `Outcome<Issue>`.
689#[derive(Debug, Serialize, Deserialize)]
690pub struct UpdateIssueArgs {
691 pub actor: User,
692 pub repo: RepoPath,
693 pub number: u32,
694 #[serde(default)]
695 pub title: Option<String>,
696 #[serde(default)]
697 pub body: Option<String>,
698 #[serde(default)]
699 pub labels: Option<Vec<String>>,
Agents as a team: lifecycle, merge queue, billing and a new shell700 /// Usernames of the people it is assigned to; replaces the whole set.
701 /// Assigning it to the g1t agent is the runner's `run`, not this.
702 #[serde(default)]
703 pub assignees: Option<Vec<String>>,
Work service in Rust, with RFC 3339 timestamps704}
705
Issues and pull requests replace intents and attempts706/// `close_issue` and `reopen_issue`. Each returns `Outcome<Issue>`.
Work service in Rust, with RFC 3339 timestamps707#[derive(Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts708pub struct IssueActionArgs {
Work service in Rust, with RFC 3339 timestamps709 pub actor: User,
Issues and pull requests replace intents and attempts710 pub repo: RepoPath,
711 pub number: u32,
712 /// For `close_issue`; `completed` if left out.
713 #[serde(default)]
714 pub reason: Option<IssueReason>,
Work service in Rust, with RFC 3339 timestamps715}
716
Acceptance checks in sandboxes, line comments and review verdicts717/// `add_comment`, on an issue or a pull request. On a pull request it may
718/// name a line of the change, and may carry a verdict; nobody can give a
719/// verdict on their own pull request. Returns `Outcome<Comment>`.
Work service in Rust, with RFC 3339 timestamps720#[derive(Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts721pub struct AddCommentArgs {
Work service in Rust, with RFC 3339 timestamps722 pub actor: User,
Issues and pull requests replace intents and attempts723 pub repo: RepoPath,
724 pub number: u32,
Acceptance checks in sandboxes, line comments and review verdicts725 /// May be empty when approving.
726 #[serde(default)]
Issues and pull requests replace intents and attempts727 pub body: String,
Acceptance checks in sandboxes, line comments and review verdicts728 #[serde(default)]
729 pub path: Option<String>,
730 #[serde(default)]
731 pub line: Option<u32>,
732 #[serde(default)]
733 pub verdict: Option<Verdict>,
Work service in Rust, with RFC 3339 timestamps734}
735
Pull requests from branches736/// `open_pull`. Without `branch`, forks the repo and returns a draft pull
737/// request to push to. With it, opens a pull request, ready for review,
738/// for a branch already pushed to the repo. Returns `Outcome<Pull>`.
Work service in Rust, with RFC 3339 timestamps739#[derive(Debug, Serialize, Deserialize)]
Issues and pull requests replace intents and attempts740pub struct OpenPullArgs {
741 pub actor: User,
742 pub repo: RepoPath,
743 /// The issue this is for.
Work service in Rust, with RFC 3339 timestamps744 #[serde(default)]
Issues and pull requests replace intents and attempts745 pub issue: Option<u32>,
746 /// Defaults to the issue's title; required without an issue.
747 #[serde(default)]
748 pub title: String,
Pull requests from branches749 /// What changed and why. Usually set later, when a draft is marked ready.
750 #[serde(default)]
751 pub body: String,
752 /// A branch of the repository that already holds the change.
753 #[serde(default)]
754 pub branch: Option<String>,
Issues and pull requests replace intents and attempts755 #[serde(default)]
756 pub agent: String,
757 pub runtime: Runtime,
Work service in Rust, with RFC 3339 timestamps758}
759
Issues and pull requests replace intents and attempts760/// `ready_pull`, `close_pull` and `merge_pull`. Each returns `Outcome<Pull>`.
Work service in Rust, with RFC 3339 timestamps761#[derive(Debug, Serialize, Deserialize)]
762#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts763pub struct PullActionArgs {
Work service in Rust, with RFC 3339 timestamps764 pub actor: User,
Issues and pull requests replace intents and attempts765 pub repo: RepoPath,
766 pub number: u32,
767 /// For `ready_pull`: what changed and why.
Work service in Rust, with RFC 3339 timestamps768 #[serde(default)]
769 pub summary: String,
Issues and pull requests replace intents and attempts770 /// For `merge_pull`: leave the issue open and the other pull requests
771 /// for it untouched, because this one is only part of the work.
772 #[serde(default)]
773 pub keep_issue_open: bool,
Acceptance checks in sandboxes, line comments and review verdicts774 /// For `merge_pull`: merge although the acceptance checks have not
775 /// passed.
776 #[serde(default)]
777 pub ignore_checks: bool,
778}
779
Agents as a team: lifecycle, merge queue, billing and a new shell780/// Where a plan stands.
781#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
782#[serde(rename_all = "lowercase")]
783pub enum PlanStatus {
784 /// An agent is reading the repository and writing it.
785 Planning,
786 /// Written, and waiting for a person to read and apply it.
787 Ready,
788 /// It could not be written.
789 Failed,
790 /// Its issues have been opened.
791 Applied,
792}
793
794/// One issue a plan proposes.
795#[derive(Clone, Debug, Default, Serialize, Deserialize)]
796#[serde(rename_all = "camelCase", default)]
797pub struct PlannedIssue {
798 pub title: String,
799 /// Markdown: what to change, where, and why.
800 pub body: String,
801 pub labels: Vec<String>,
802 /// Commands that must pass once the change is made.
803 pub checks: Vec<String>,
804 /// The files it will most likely change.
805 pub files: Vec<String>,
806 /// The positions, counting from 1, of earlier issues in the plan that
807 /// have to be merged first. An agent writes this as `depends_on`.
808 #[serde(alias = "depends_on")]
809 pub depends_on: Vec<u32>,
810 /// Its number, once the plan has been applied and it was kept.
811 pub number: Option<u32>,
812}
813
814/// An outcome someone wrote, and the issues an agent proposes to get there.
815#[derive(Clone, Debug, Serialize, Deserialize)]
816#[serde(rename_all = "camelCase")]
817pub struct Plan {
818 pub id: String,
819 pub repo_id: String,
820 /// The outcome wanted, as written.
821 pub brief: String,
822 pub status: PlanStatus,
823 /// The agent's account of how it split the work.
824 pub summary: String,
825 pub issues: Vec<PlannedIssue>,
826 /// Why it could not be written, when `status` is `failed`.
827 pub error: Option<String>,
828 pub author: User,
829 /// RFC 3339.
830 pub created_at: String,
831 /// RFC 3339.
832 pub finished_at: Option<String>,
Dark gray base with lavender as an accent, and a live outcome view for plans833 /// Once applied: where each issue it opened stands now, in plan order.
834 /// Filled in by `get_plan` only.
835 #[serde(default)]
836 pub progress: Vec<IssueProgress>,
837}
838
839/// Where one issue of an applied plan stands.
840#[derive(Clone, Debug, Serialize, Deserialize)]
841#[serde(rename_all = "camelCase")]
842pub struct IssueProgress {
843 pub number: u32,
844 pub title: String,
845 /// `blocked` (waiting on issues it depends on), `waiting` (for an
846 /// agent), `open` (nobody on it), one of the lifecycle stages
847 /// (`working`, `checking`, `reviewing`, `revising`, `catching_up`,
848 /// `queued`, `ready`, `needs_you`), `landed` or `closed`.
849 pub state: String,
850 /// One sentence about where it stands.
851 pub detail: String,
852 /// The issues it is waiting on that are still open.
853 pub blocked_by: Vec<u32>,
854 /// The pull request carrying it, the newest if several.
855 pub pull: Option<u32>,
856 /// Who or what is working on it, e.g. `g1t-agent`.
857 pub agent: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell858}
859
860/// `start_plan`: records an outcome to plan for. Members of the
861/// repository's workspace only. Called by the runner service, which starts
862/// the sandbox. Returns `Outcome<PlanJob>`.
863#[derive(Debug, Serialize, Deserialize)]
864pub struct StartPlanArgs {
865 pub actor: User,
866 pub repo: RepoPath,
867 pub brief: String,
868}
869
870/// What a sandbox needs to write a plan.
871#[derive(Debug, Serialize, Deserialize)]
872#[serde(rename_all = "camelCase")]
873pub struct PlanJob {
874 pub plan_id: String,
875 /// Lets the sandbox, and nothing else, report this plan.
876 pub token: String,
877 pub brief: String,
878 pub repo: RepoPath,
879}
880
881/// `report_plan`: the plan a sandbox's agent wrote, or why it could not
882/// write one. Returns `Outcome<bool>`.
883#[derive(Debug, Serialize, Deserialize)]
884#[serde(rename_all = "camelCase")]
885pub struct ReportPlanArgs {
886 pub plan_id: String,
887 pub token: String,
888 #[serde(default)]
889 pub summary: String,
890 #[serde(default)]
891 pub issues: Vec<PlannedIssue>,
892 #[serde(default)]
893 pub error: Option<String>,
894}
895
896/// `get_plan`. Members only. Returns `Outcome<Plan>`. `list_plans` takes
897/// `ViewArgs` and returns `Outcome<Vec<Plan>>`, newest first.
898#[derive(Debug, Serialize, Deserialize)]
899pub struct PlanArgs {
900 pub repo: RepoPath,
901 pub viewer: Viewer,
902 pub id: String,
903}
904
905/// `apply_plan`: opens a plan's issues, each blocked by the ones it depends
906/// on. Members only, and once. Returns `Outcome<Plan>`, its issues now
907/// carrying their numbers.
908#[derive(Debug, Serialize, Deserialize)]
909pub struct ApplyPlanArgs {
910 pub actor: User,
911 pub repo: RepoPath,
912 pub id: String,
913 /// Queue every issue for a g1t agent.
914 #[serde(default)]
915 pub assign: bool,
916 /// The positions, counting from 1, of the issues to open. All of them
917 /// when absent.
918 #[serde(default)]
919 pub keep: Option<Vec<u32>>,
920}
921
922/// `queue_issue`: asks for a g1t agent to take an issue as soon as it can,
923/// or withdraws that. The author or a member may. Returns `Outcome<bool>`.
924#[derive(Debug, Serialize, Deserialize)]
925pub struct QueueIssueArgs {
926 pub actor: User,
927 pub repo: RepoPath,
928 pub number: u32,
929 pub queued: bool,
930}
931
932/// `ready_issues`: issues waiting for a g1t agent that can be given one
933/// now, in one repository or in all. Called by the runner service. Returns
934/// `Vec<ReadyIssue>`.
935#[derive(Debug, Default, Serialize, Deserialize)]
936#[serde(rename_all = "camelCase")]
937pub struct ReadyIssuesArgs {
938 #[serde(default)]
939 pub repo_id: Option<String>,
940}
941
942#[derive(Debug, Serialize, Deserialize)]
943pub struct ReadyIssue {
944 pub repo: RepoPath,
945 pub number: u32,
946 /// Who queued it, on whose say-so the agent works.
947 pub actor: User,
948}
949
950/// `update_pull`: changes who a pull request is assigned to and whose
951/// review is asked for. Each list given replaces the whole set. Whoever
952/// opened it, or a member of the workspace, may. Returns `Outcome<Pull>`.
953#[derive(Debug, Serialize, Deserialize)]
954pub struct UpdatePullArgs {
955 pub actor: User,
956 pub repo: RepoPath,
957 pub number: u32,
958 #[serde(default)]
959 pub assignees: Option<Vec<String>>,
960 /// May include `g1t-agent`. Asking for its review does not by itself
961 /// start one; the runner's `review` does.
962 #[serde(default)]
963 pub reviewers: Option<Vec<String>>,
964}
965
Acceptance checks in sandboxes, line comments and review verdicts966/// `start_checks`: begins a run of the acceptance checks for a pull request
967/// that is ready for review. Called by the runner service, which starts the
968/// sandbox. Returns `Outcome<CheckJob>`.
969#[derive(Debug, Serialize, Deserialize)]
970#[serde(rename_all = "camelCase")]
971pub struct StartChecksArgs {
972 pub pull_id: String,
973}
974
975/// What a sandbox needs to carry out a check run.
976#[derive(Debug, Serialize, Deserialize)]
977#[serde(rename_all = "camelCase")]
978pub struct CheckJob {
979 pub run_id: String,
980 /// Lets the sandbox, and nothing else, report this run's results.
981 pub token: String,
982 pub commands: Vec<String>,
983 /// The repository holding the commit: the fork, or the repository itself.
984 pub source: RepoPath,
985 pub commit: String,
986 /// Who opened the pull request, and so can read its source.
987 pub author: User,
988 /// Username of whoever wrote the checks: the issue's author.
989 pub requested_by: String,
990 pub repo: RepoPath,
991 pub number: u32,
992}
993
994/// `report_checks`: what a sandbox says about its run. With no results and
995/// no error it has started. `skip` forgets the run, for one that will not
996/// be carried out. Returns `Outcome<CheckRun>`.
997#[derive(Debug, Serialize, Deserialize)]
998#[serde(rename_all = "camelCase")]
999pub struct ReportChecksArgs {
1000 pub run_id: String,
1001 pub token: String,
1002 #[serde(default)]
1003 pub results: Vec<CheckResult>,
1004 #[serde(default)]
1005 pub error: Option<String>,
1006 #[serde(default)]
1007 pub skip: bool,
Work service in Rust, with RFC 3339 timestamps1008}
1009
Issues and pull requests replace intents and attempts1010/// A pull request in progress, with where it lives.
1011#[derive(Debug, Serialize, Deserialize)]
1012pub struct ActivePull {
1013 pub pull: Pull,
1014 pub issue: Option<Issue>,
Agents as a team: lifecycle, merge queue, billing and a new shell1015 /// Where it stands, for one g1t is seeing through.
1016 #[serde(default)]
1017 pub lifecycle: Option<Lifecycle>,
Issues and pull requests replace intents and attempts1018}
1019
1020/// `list_active_pulls`: drafts and open pull requests the viewer started,
Agents as a team: lifecycle, merge queue, billing and a new shell1021/// most recently active first. Returns `Vec<ActivePull>`. Also
1022/// `list_assigned_issues`: open issues assigned to the viewer, most
1023/// recently changed first. Returns `Vec<Issue>`.
Work service in Rust, with RFC 3339 timestamps1024#[derive(Debug, Serialize, Deserialize)]
1025pub struct ViewerArgs {
1026 pub viewer: Viewer,
1027}
1028
1029/// `append_session`. Returns `Outcome<Appended>`.
1030#[derive(Debug, Serialize, Deserialize)]
1031pub struct AppendSessionArgs {
1032 pub actor: User,
Issues and pull requests replace intents and attempts1033 pub repo: RepoPath,
1034 pub number: u32,
Work service in Rust, with RFC 3339 timestamps1035 pub entries: Vec<NewSessionEntry>,
1036}
1037
1038#[derive(Debug, Serialize, Deserialize)]
1039pub struct Appended {
1040 pub count: u32,
1041}
Issues and pull requests replace intents and attempts1042
Agents as a team: lifecycle, merge queue, billing and a new shell1043/// `start_review`: begins a review of a pull request by a g1t agent. Called
1044/// by the runner service, which starts the sandbox. Returns
1045/// `Outcome<ReviewJob>`.
1046#[derive(Debug, Serialize, Deserialize)]
1047#[serde(rename_all = "camelCase")]
1048pub struct StartReviewArgs {
1049 pub pull_id: String,
1050}
1051
1052/// What a sandbox needs to review a pull request.
1053#[derive(Debug, Serialize, Deserialize)]
1054#[serde(rename_all = "camelCase")]
1055pub struct ReviewJob {
1056 pub run_id: String,
1057 /// Lets the sandbox, and nothing else, report this review.
1058 pub token: String,
1059 /// The repository holding the commit: the fork, or the repository itself.
1060 pub source: RepoPath,
1061 pub commit: String,
1062 pub repo: RepoPath,
1063 pub default_branch: String,
1064 pub number: u32,
1065 pub title: String,
1066 pub description: String,
1067 /// The issue the pull request is for, which says what it should achieve.
1068 pub issue: Option<Issue>,
1069 /// Who opened the pull request, and so can read its source.
1070 pub author: User,
1071}
1072
1073/// A comment on one line, as a reviewing agent reports it.
1074#[derive(Debug, Serialize, Deserialize)]
1075pub struct ReviewComment {
1076 pub path: String,
1077 #[serde(default)]
1078 pub line: u32,
1079 pub body: String,
1080}
1081
1082/// `report_review`: the review a sandbox's agent wrote, or why it could not
1083/// write one. Returns `Outcome<bool>`.
1084#[derive(Debug, Serialize, Deserialize)]
1085#[serde(rename_all = "camelCase")]
1086pub struct ReportReviewArgs {
1087 pub run_id: String,
1088 pub token: String,
1089 #[serde(default)]
1090 pub verdict: Option<Verdict>,
1091 #[serde(default)]
1092 pub body: String,
1093 #[serde(default)]
1094 pub comments: Vec<ReviewComment>,
1095 /// The model that wrote it, by its public name.
1096 #[serde(default)]
1097 pub model: Option<String>,
1098 #[serde(default)]
1099 pub error: Option<String>,
1100}
1101
Issues and pull requests replace intents and attempts1102/// Lowercases, trims and de-duplicates labels, dropping empty ones.
1103/// Returns `None` if there are too many or one is too long.
1104pub fn normalize_labels(labels: &[String]) -> Option<Vec<String>> {
1105 const MAX_LABELS: usize = 10;
1106 const MAX_LABEL_CHARS: usize = 40;
1107 let mut normalized: Vec<String> = Vec::new();
1108 for label in labels {
1109 let label = label
1110 .split_whitespace()
1111 .collect::<Vec<_>>()
1112 .join(" ")
1113 .to_lowercase();
1114 if label.is_empty() || normalized.contains(&label) {
1115 continue;
1116 }
1117 if label.chars().count() > MAX_LABEL_CHARS {
1118 return None;
1119 }
1120 normalized.push(label);
1121 }
1122 (normalized.len() <= MAX_LABELS).then_some(normalized)
1123}
1124
1125#[cfg(test)]
1126mod tests {
1127 use super::normalize_labels;
1128
1129 fn labels(names: &[&str]) -> Vec<String> {
1130 names.iter().map(|name| (*name).to_owned()).collect()
1131 }
1132
1133 #[test]
1134 fn labels_are_lowercased_trimmed_and_unique() {
1135 assert_eq!(
1136 normalize_labels(&labels(&[" Bug ", "bug", "", "Good First Issue"])),
1137 Some(labels(&["bug", "good first issue"]))
1138 );
1139 }
1140
1141 #[test]
1142 fn too_long_or_too_many_labels_are_refused() {
1143 assert_eq!(normalize_labels(&["x".repeat(41)]), None);
1144 let many: Vec<String> = (0..11).map(|i| format!("label-{i}")).collect();
1145 assert_eq!(normalize_labels(&many), None);
1146 }
1147}
Agents as a team: lifecycle, merge queue, billing and a new shell1148
1149
1150// --- Merge queue ----------------------------------------------------------
1151
1152/// Where a pull request in a merge queue stands.
1153#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1154#[serde(rename_all = "snake_case")]
1155pub enum QueueState {
1156 /// Waiting for its turn to be tested.
1157 Waiting,
1158 /// Its combined state is being built and checked.
1159 Testing,
1160 /// Its combined state passed; it lands once everything ahead has.
1161 Passed,
1162 /// Its combined state failed, or would not merge. It left the queue.
1163 Failed,
1164 /// On the default branch.
1165 Landed,
1166 /// Taken out of the queue by a person, or closed.
1167 Removed,
1168}
1169
1170impl QueueState {
1171 pub fn as_str(self) -> &'static str {
1172 match self {
1173 QueueState::Waiting => "waiting",
1174 QueueState::Testing => "testing",
1175 QueueState::Passed => "passed",
1176 QueueState::Failed => "failed",
1177 QueueState::Landed => "landed",
1178 QueueState::Removed => "removed",
1179 }
1180 }
1181
1182 /// Still in the queue.
1183 pub fn is_active(self) -> bool {
1184 matches!(
1185 self,
1186 QueueState::Waiting | QueueState::Testing | QueueState::Passed
1187 )
1188 }
1189}
1190
1191/// One pull request's place in a merge queue.
1192#[derive(Clone, Debug, Serialize, Deserialize)]
1193#[serde(rename_all = "camelCase")]
1194pub struct QueueEntry {
1195 pub id: String,
1196 pub number: u32,
1197 pub title: String,
1198 /// Who or what made the pull request, e.g. `g1t-agent`.
1199 pub agent: String,
1200 pub state: QueueState,
1201 /// The pull requests merged ahead of it in the state being tested, in
1202 /// queue order. Empty when it was tested on the default branch alone.
1203 pub ahead: Vec<u32>,
1204 /// The default branch's commit the tested state was built on.
1205 pub base_commit: Option<String>,
1206 /// The tested state: the default branch with everything ahead and this.
1207 pub combined_commit: Option<String>,
1208 /// Why it failed: a merge conflict or what could not be run.
1209 pub error: Option<String>,
1210 /// The checks run against the tested state.
1211 pub results: Vec<CheckResult>,
1212 /// Username of whoever merged it into the queue: a person, or `g1t`.
1213 pub enqueued_by: String,
1214 /// RFC 3339.
1215 pub created_at: String,
1216 /// RFC 3339. When it landed or left.
1217 pub finished_at: Option<String>,
1218}
1219
1220/// A repository's merge queue: what is in it, in order, and what recently
1221/// left it.
1222#[derive(Clone, Debug, Serialize, Deserialize)]
1223#[serde(rename_all = "camelCase")]
1224pub struct QueueView {
1225 /// Whether the repository merges through the queue.
1226 pub enabled: bool,
1227 pub active: Vec<QueueEntry>,
1228 /// Newest first.
1229 pub recent: Vec<QueueEntry>,
1230}
1231
1232/// `queue`: a repository's merge queue. Returns `Outcome<QueueView>`.
1233#[derive(Debug, Serialize, Deserialize)]
1234pub struct QueueArgs {
1235 pub repo: RepoPath,
1236 pub viewer: Viewer,
1237}
1238
1239/// `queue_build`: the next batch to test for a repository, if nothing is
1240/// being tested now. Returns `Vec<QueueJob>`, one per entry, each testing
1241/// the default branch with that entry and everything ahead of it.
1242#[derive(Debug, Serialize, Deserialize)]
1243#[serde(rename_all = "camelCase")]
1244pub struct QueueBuildArgs {
1245 pub repo_id: String,
1246}
1247
1248/// One pull request in a state being tested: where its change is.
1249#[derive(Clone, Debug, Serialize, Deserialize)]
1250#[serde(rename_all = "camelCase")]
1251pub struct QueueStackItem {
1252 pub number: u32,
1253 pub title: String,
1254 /// The repository holding the change: its fork, or the repository.
1255 pub source: RepoPath,
1256 /// The branch of `source` holding it.
1257 pub branch: String,
1258 pub commit: String,
1259}
1260
1261/// What a sandbox needs to build and check one combined state.
1262#[derive(Clone, Debug, Serialize, Deserialize)]
1263#[serde(rename_all = "camelCase")]
1264pub struct QueueJob {
1265 pub entry_id: String,
1266 /// Lets the sandbox, and nothing else, report this state's result.
1267 pub token: String,
1268 pub repo: RepoPath,
1269 pub default_branch: String,
1270 /// The default branch's commit to build on.
1271 pub base_commit: String,
1272 /// Where to push the tested state, in the repository itself.
1273 pub branch: String,
1274 /// The pull requests to merge in, in order; the last is the entry.
1275 pub stack: Vec<QueueStackItem>,
1276 /// Every acceptance check of every pull request in the stack.
1277 pub checks: Vec<String>,
1278 /// The checks of issues already completed: the default branch's
1279 /// contract. One that fails on the base alone is not held against the
1280 /// entry.
1281 #[serde(default)]
1282 pub contract_checks: Vec<String>,
1283 /// Who the sandbox acts as: a member who can push the tested state.
1284 pub actor: User,
1285}
1286
1287/// `report_queue`: a sandbox's result for one combined state. Returns
1288/// `Outcome<QueueState>`.
1289#[derive(Debug, Serialize, Deserialize)]
1290#[serde(rename_all = "camelCase")]
1291pub struct ReportQueueArgs {
1292 pub entry_id: String,
1293 pub token: String,
1294 #[serde(default)]
1295 pub combined_commit: Option<String>,
1296 #[serde(default)]
1297 pub results: Vec<CheckResult>,
1298 /// Set when the state could not be built or checked.
1299 #[serde(default)]
1300 pub error: Option<String>,
1301 /// For a merge conflict: the pull request whose change it collided with.
1302 #[serde(default)]
1303 pub conflict_with: Option<u32>,
1304}