Skip to content

g1t/crates/contracts/src/repos.rs

1,324 lines45,036 bytesCodeBlame
1//! The repos service: repository metadata, contents, forks and git access.
2//!
3//! Each `*Args` struct is the argument of the method of the same name,
4//! served at `POST /rpc/<method>`.
5
6use serde::{Deserialize, Serialize};
7
8use crate::{User, Viewer};
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Repo {
13 pub id: String,
14 /// The slug of the workspace that owns it: the first URL segment.
15 pub namespace: String,
16 pub name: String,
17 pub description: Option<String>,
18 pub is_private: bool,
19 pub owner_id: String,
20 pub default_branch: String,
21 /// Set when this repo is a pull request's working copy of another repo.
22 pub fork_of: Option<String>,
23 /// Whether the default branch is protected: it changes only by merging
24 /// a pull request, and pushes to it are refused.
25 #[serde(default)]
26 pub protected: bool,
27 /// RFC 3339.
28 pub created_at: String,
29 /// Words that say what it is about, for search and Explore: lowercase
30 /// letters, digits and hyphens. See [`clean_topics`].
31 #[serde(default)]
32 pub topics: Vec<String>,
33 /// Its home page, an http(s) address, shown beside its description.
34 /// See [`clean_website`].
35 #[serde(default)]
36 pub website: Option<String>,
37 /// RFC 3339: when it was archived, made read-only. Null when it is not.
38 #[serde(default)]
39 pub archived_at: Option<String>,
40}
41
42impl Repo {
43 pub fn archived(&self) -> bool {
44 self.archived_at.is_some()
45 }
46}
47
48/// `storage_options` (no arguments, `{}`): what a workspace may choose
49/// about where its repositories are kept. `eu_available`: an EU namespace
50/// is configured and takes new repositories, so a workspace may keep its
51/// data in the EU (`set_workspace_residency` on identity). Returns
52/// `StorageOptions`.
53#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
54#[serde(rename_all = "camelCase")]
55pub struct StorageOptions {
56 pub eu_available: bool,
57}
58
59/// How long a deleted repository can be restored before it is purged.
60pub const RESTORE_DAYS: u64 = 30;
61
62/// A deleted repository, as its workspace's Recently deleted list shows
63/// it: restorable until `purge_after`.
64#[derive(Clone, Debug, Serialize, Deserialize)]
65#[serde(rename_all = "camelCase")]
66pub struct DeletedRepo {
67 pub id: String,
68 pub namespace: String,
69 pub name: String,
70 pub description: Option<String>,
71 pub is_private: bool,
72 /// RFC 3339.
73 pub deleted_at: String,
74 /// The username of who deleted it.
75 pub deleted_by: String,
76 /// RFC 3339: when it is purged, unless restored first.
77 pub purge_after: String,
78}
79
80/// The longest website address a repository keeps.
81pub const MAX_WEBSITE_CHARS: usize = 255;
82
83/// A website as it is kept: an http(s) address, `https://` added when no
84/// scheme is given; empty clears it. Anything else is refused.
85pub fn clean_website(text: &str) -> Result<Option<String>, String> {
86 let text = text.trim();
87 if text.is_empty() {
88 return Ok(None);
89 }
90 let url = if text.starts_with("https://") || text.starts_with("http://") {
91 text.to_owned()
92 } else if text.contains("://") {
93 return Err("A website is an http or https address.".into());
94 } else {
95 format!("https://{text}")
96 };
97 let host = url
98 .split("://")
99 .nth(1)
100 .unwrap_or("")
101 .split(['/', '?', '#'])
102 .next()
103 .unwrap_or("");
104 if url.chars().count() > MAX_WEBSITE_CHARS
105 || host.is_empty()
106 || !host.contains('.')
107 || url.chars().any(char::is_whitespace)
108 {
109 return Err("That is not a website address, such as https://example.com.".into());
110 }
111 Ok(Some(url))
112}
113
114/// Whether `name` can be a branch people name: what `git check-ref-format
115/// --branch` accepts, less the names g1t keeps for itself
116/// ([`G1T_BRANCH_PREFIX`]).
117pub fn is_valid_branch_name(name: &str) -> bool {
118 !name.is_empty()
119 && name.len() <= 200
120 && !name.starts_with('-')
121 && !name.starts_with('/')
122 && !name.ends_with('/')
123 && !name.ends_with('.')
124 && !name.ends_with(".lock")
125 && !name.contains("..")
126 && !name.contains("//")
127 && !name.contains("@{")
128 && name != "@"
129 && !name.starts_with(G1T_BRANCH_PREFIX)
130 && !name.split('/').any(|part| part.starts_with('.'))
131 && name
132 .chars()
133 .all(|c| !c.is_control() && !matches!(c, ' ' | '~' | '^' | ':' | '?' | '*' | '[' | '\\'))
134}
135
136/// The most topics a repository has.
137pub const MAX_TOPICS: usize = 20;
138/// The longest topic.
139pub const MAX_TOPIC_CHARS: usize = 35;
140
141/// Topics as they are kept: lowercase, spaces and underscores made
142/// hyphens, each of letters, digits and hyphens, starting with a letter or
143/// digit, without repeats, at most [`MAX_TOPICS`]. Anything else is the
144/// first topic that could not be read.
145pub fn clean_topics(topics: &[String]) -> Result<Vec<String>, String> {
146 let mut kept: Vec<String> = Vec::new();
147 for topic in topics {
148 let topic: String = topic
149 .trim()
150 .to_lowercase()
151 .chars()
152 .map(|c| if c == ' ' || c == '_' { '-' } else { c })
153 .collect();
154 if topic.is_empty() {
155 continue;
156 }
157 let valid = topic.chars().count() <= MAX_TOPIC_CHARS
158 && topic.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-')
159 && topic.chars().next().is_some_and(|c| c.is_ascii_alphanumeric());
160 if !valid {
161 return Err(format!(
162 "\"{topic}\" is not a topic: use letters, digits and hyphens, at most {MAX_TOPIC_CHARS} characters."
163 ));
164 }
165 if !kept.contains(&topic) {
166 kept.push(topic);
167 }
168 }
169 if kept.len() > MAX_TOPICS {
170 return Err(format!("A repository has at most {MAX_TOPICS} topics."));
171 }
172 Ok(kept)
173}
174
175#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
176pub struct RepoPath {
177 pub namespace: String,
178 pub name: String,
179}
180
181#[derive(Clone, Debug, Serialize, Deserialize)]
182pub struct Signature {
183 pub name: String,
184 pub email: String,
185}
186
187#[derive(Clone, Debug, Serialize, Deserialize)]
188#[serde(rename_all = "camelCase")]
189pub struct Commit {
190 pub hash: String,
191 pub tree_hash: String,
192 pub message: String,
193 pub author: Signature,
194 pub parents: Vec<String>,
195 /// RFC 3339.
196 pub authored_at: String,
197}
198
199#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
200#[serde(rename_all = "lowercase")]
201pub enum EntryKind {
202 Tree,
203 Blob,
204 Symlink,
205 Gitlink,
206 Exec,
207}
208
209#[derive(Clone, Debug, Serialize, Deserialize)]
210pub struct TreeEntry {
211 pub name: String,
212 pub hash: String,
213 pub kind: EntryKind,
214}
215
216#[derive(Clone, Debug, Serialize, Deserialize)]
217pub struct Readme {
218 pub name: String,
219 /// Null when the file is binary or too large to show.
220 pub text: Option<String>,
221}
222
223#[derive(Clone, Debug, Serialize, Deserialize)]
224pub struct TreeView {
225 pub repo: Repo,
226 #[serde(rename = "ref")]
227 pub git_ref: String,
228 pub path: String,
229 /// Null when the repo has no commits yet.
230 pub head: Option<Commit>,
231 pub entries: Vec<TreeEntry>,
232 pub readme: Option<Readme>,
233}
234
235#[derive(Clone, Debug, Serialize, Deserialize)]
236pub struct BlobView {
237 pub repo: Repo,
238 #[serde(rename = "ref")]
239 pub git_ref: String,
240 pub path: String,
241 pub size: u64,
242 /// Null when the file is binary or too large to show.
243 pub text: Option<String>,
244}
245
246/// A git remote and a short-lived credential for it.
247#[derive(Clone, Debug, Serialize, Deserialize)]
248pub struct GitAccess {
249 pub remote: String,
250 pub token: String,
251}
252
253#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
254pub enum GitService {
255 #[serde(rename = "git-upload-pack")]
256 UploadPack,
257 #[serde(rename = "git-receive-pack")]
258 ReceivePack,
259}
260
261/// The result of landing a pull request.
262#[derive(Clone, Debug, Serialize, Deserialize)]
263pub struct Landed {
264 /// The commit the branch points to now.
265 pub commit: String,
266 /// The commit it pointed to before, if it had one. Comparing against
267 /// this shows what the pull request changed.
268 pub previous: Option<String>,
269}
270
271/// `get`. Returns `Outcome<Repo>`.
272#[derive(Debug, Serialize, Deserialize)]
273pub struct GetArgs {
274 pub path: RepoPath,
275 pub viewer: Viewer,
276}
277
278/// `path_by_id`: where a repository is, whoever may see it. For g1t's own
279/// services, which hold a repository's id from an event and act for its
280/// workspace; nothing outside reaches it. Returns `Option<RepoPath>`, null
281/// for a fork or an unknown id.
282#[derive(Debug, Serialize, Deserialize)]
283pub struct PathByIdArgs {
284 pub id: String,
285}
286
287/// `get_by_id`. Returns `Outcome<Repo>`.
288#[derive(Debug, Serialize, Deserialize)]
289pub struct GetByIdArgs {
290 pub id: String,
291 pub viewer: Viewer,
292}
293
294/// `list`: repos the viewer may see, newest first. Returns `Vec<Repo>`.
295#[derive(Debug, Default, Serialize, Deserialize)]
296#[serde(rename_all = "camelCase")]
297pub struct ListArgs {
298 pub viewer: Viewer,
299 #[serde(default)]
300 pub query: Option<String>,
301 /// Only repos in this workspace.
302 #[serde(default)]
303 pub namespace: Option<String>,
304 /// Only repos in workspaces the viewer belongs to.
305 #[serde(default)]
306 pub member_only: bool,
307}
308
309/// `create`. Returns `Outcome<Repo>`.
310#[derive(Debug, Serialize, Deserialize)]
311#[serde(rename_all = "camelCase")]
312pub struct CreateArgs {
313 /// Who is creating it; they must belong to the workspace.
314 pub owner: User,
315 /// The workspace it is created in.
316 pub namespace: String,
317 pub name: String,
318 #[serde(default)]
319 pub description: Option<String>,
320 #[serde(default)]
321 pub is_private: bool,
322 /// The https address of a public git repository to copy the default
323 /// branch of, such as `https://github.com/owner/repo`.
324 #[serde(default)]
325 pub import_url: Option<String>,
326 /// With `import_url`: a GitHub installation access token that opens it,
327 /// for a private repository. Every branch and tag is then copied, not
328 /// only the default branch. Set only by the integrations service.
329 #[serde(default, skip_serializing_if = "Option::is_none")]
330 pub import_token: Option<String>,
331}
332
333/// `mirror`: makes a repository's branches and tags match another git
334/// host's, or pushes its own out to one. Services only. Returns
335/// `Outcome<Mirrored>`.
336#[derive(Debug, Serialize, Deserialize)]
337#[serde(rename_all = "camelCase")]
338pub struct MirrorArgs {
339 pub repo_id: String,
340 /// The other host's https address, such as
341 /// `https://github.com/owner/repo.git`.
342 pub url: String,
343 /// A GitHub installation access token for it. Opaque: any length.
344 pub token: String,
345 pub direction: MirrorDirection,
346}
347
348#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
349#[serde(rename_all = "snake_case")]
350pub enum MirrorDirection {
351 /// The repository on g1t follows the other host: its refs are moved,
352 /// and removed, to match.
353 Pull,
354 /// The other host follows g1t: refs g1t has are pushed there; refs only
355 /// the other host has are left alone.
356 Push,
357}
358
359/// What a `mirror` changed.
360#[derive(Clone, Debug, Default, Serialize, Deserialize)]
361#[serde(rename_all = "camelCase")]
362pub struct Mirrored {
363 /// Full ref names created or moved.
364 pub updated: Vec<String>,
365 pub deleted: Vec<String>,
366}
367
368/// `update`: changes whichever of a repository's details are given.
369/// Members of its workspace only. Returns `Outcome<Repo>`.
370#[derive(Debug, Serialize, Deserialize)]
371#[serde(rename_all = "camelCase")]
372pub struct UpdateArgs {
373 pub actor: User,
374 pub path: RepoPath,
375 /// An empty description clears it.
376 #[serde(default)]
377 pub description: Option<String>,
378 #[serde(default)]
379 pub is_private: Option<bool>,
380 #[serde(default)]
381 pub protected: Option<bool>,
382 /// Replaces its topics; an empty list clears them.
383 #[serde(default)]
384 pub topics: Option<Vec<String>>,
385 /// Its home page; an empty string clears it.
386 #[serde(default)]
387 pub website: Option<String>,
388 /// Where the request came in, for the audit log; g1t.sh when absent.
389 #[serde(default)]
390 pub surface: Option<crate::audit::Surface>,
391}
392
393/// `tree`. Returns `Outcome<TreeView>`.
394#[derive(Debug, Serialize, Deserialize)]
395#[serde(rename_all = "camelCase")]
396pub struct TreeArgs {
397 pub path: RepoPath,
398 pub viewer: Viewer,
399 /// The default branch when absent.
400 #[serde(default, rename = "ref")]
401 pub git_ref: Option<String>,
402 #[serde(default)]
403 pub tree_path: String,
404}
405
406/// `blob`. Returns `Outcome<BlobView>`.
407#[derive(Debug, Serialize, Deserialize)]
408#[serde(rename_all = "camelCase")]
409pub struct BlobArgs {
410 pub path: RepoPath,
411 pub viewer: Viewer,
412 #[serde(rename = "ref")]
413 pub git_ref: String,
414 pub file_path: String,
415}
416
417/// `log`. Returns `Outcome<Vec<Commit>>`.
418#[derive(Debug, Serialize, Deserialize)]
419pub struct LogArgs {
420 pub path: RepoPath,
421 pub viewer: Viewer,
422 #[serde(default, rename = "ref")]
423 pub git_ref: Option<String>,
424 pub limit: u32,
425}
426
427/// `fork_for_pull`: a copy-on-write copy of the source repo, hidden from
428/// listings, for one pull request to be made in. Returns `Outcome<Repo>`.
429#[derive(Debug, Serialize, Deserialize)]
430#[serde(rename_all = "camelCase")]
431pub struct ForkArgs {
432 pub source_id: String,
433 pub pull_id: String,
434 pub actor: User,
435}
436
437/// `git_access`: authorizes a git operation and says where to send it.
438/// Pushing to a repo that does not exist creates it in the pusher's own
439/// namespace. Returns `Outcome<GitAccess>`.
440#[derive(Debug, Serialize, Deserialize)]
441pub struct GitAccessArgs {
442 pub path: RepoPath,
443 pub viewer: Viewer,
444 pub service: GitService,
445}
446
447/// `land`: moves the branch a pull request merges into (the repository's
448/// default branch unless `target_branch` names another) to the head of
449/// its source. Refused with `conflict` when the source is behind, since
450/// that would discard commits. Returns `Outcome<Landed>`.
451#[derive(Debug, Serialize, Deserialize)]
452#[serde(rename_all = "camelCase")]
453pub struct LandArgs {
454 /// The repository holding the commits: a pull request's fork, or the
455 /// target itself when landing one of its own branches.
456 pub source_id: String,
457 /// The branch of the source to land. Required when the source is the
458 /// target; a fork lands its default branch.
459 #[serde(default)]
460 pub branch: Option<String>,
461 pub actor: User,
462 /// The branch of the target to land on; its default branch when absent.
463 #[serde(default)]
464 pub target_branch: Option<String>,
465}
466
467#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
468#[serde(rename_all = "lowercase")]
469pub enum FileStatus {
470 Added,
471 Modified,
472 Deleted,
473}
474
475#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
476#[serde(rename_all = "lowercase")]
477pub enum LineKind {
478 /// Unchanged, shown for context.
479 Context,
480 Add,
481 Delete,
482}
483
484#[derive(Clone, Debug, Serialize, Deserialize)]
485pub struct DiffLine {
486 pub kind: LineKind,
487 /// Line number in the old file; absent for added lines.
488 pub old: Option<u32>,
489 /// Line number in the new file; absent for deleted lines.
490 pub new: Option<u32>,
491 pub text: String,
492}
493
494/// A run of changed lines with their surrounding context.
495#[derive(Clone, Debug, Serialize, Deserialize)]
496pub struct Hunk {
497 pub lines: Vec<DiffLine>,
498}
499
500#[derive(Clone, Debug, Serialize, Deserialize)]
501pub struct FileDiff {
502 pub path: String,
503 pub status: FileStatus,
504 pub additions: u32,
505 pub deletions: u32,
506 /// True when the file is binary or too large, so no lines are shown.
507 pub binary: bool,
508 pub hunks: Vec<Hunk>,
509}
510
511/// What changed between two commits.
512#[derive(Clone, Debug, Serialize, Deserialize)]
513pub struct Comparison {
514 /// Null when the head has no earlier commit to compare against.
515 pub base: Option<String>,
516 pub head: String,
517 pub files: Vec<FileDiff>,
518 /// True when the change was too large to return in full.
519 pub truncated: bool,
520}
521
522/// `compare`: what `head` changes relative to `base`.
523///
524/// `head` is a branch or a commit, and defaults to the default branch.
525/// With no `base`, a fork is compared against the point where it and the
526/// repository it came from last agreed; a branch against the point where it
527/// left the default branch; and the default branch against its head's
528/// parent. Returns `Outcome<Comparison>`.
529#[derive(Debug, Serialize, Deserialize)]
530#[serde(rename_all = "camelCase")]
531pub struct CompareArgs {
532 pub repo_id: String,
533 pub viewer: Viewer,
534 #[serde(default)]
535 pub base: Option<String>,
536 #[serde(default)]
537 pub head: Option<String>,
538 /// With no `base`: the branch whose shared point with the head it is
539 /// compared from, instead of the default branch. A pull request into
540 /// another branch is compared this way.
541 #[serde(default)]
542 pub base_branch: Option<String>,
543}
544
545/// Lines `start` to `end` of a file, inclusive and counted from 1, last
546/// changed by `commit`.
547#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
548pub struct BlameRange {
549 pub start: u32,
550 pub end: u32,
551 pub commit: String,
552}
553
554/// Who last changed each line of a file.
555#[derive(Clone, Debug, Serialize, Deserialize)]
556pub struct Blame {
557 /// The commit the file was read at.
558 pub head: String,
559 /// Every line, in order, in runs that share a commit.
560 pub ranges: Vec<BlameRange>,
561 /// The commits the ranges name, each once.
562 pub commits: Vec<Commit>,
563 /// True when the history was too long to read in full, so the oldest
564 /// lines are given to the oldest commit read.
565 pub partial: bool,
566}
567
568/// `blame`: who last changed each line of `path` as of `ref` (the default
569/// branch if absent). Returns `Outcome<Blame>`; not found when the file is
570/// missing or is not text.
571#[derive(Debug, Serialize, Deserialize)]
572pub struct BlameArgs {
573 pub path: RepoPath,
574 pub viewer: Viewer,
575 #[serde(default, rename = "ref")]
576 pub git_ref: Option<String>,
577 #[serde(rename = "filePath")]
578 pub file_path: String,
579}
580
581/// A branch and the commit it points to.
582#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
583pub struct Branch {
584 pub name: String,
585 pub hash: String,
586}
587
588/// `last_commits`: which commit last changed each entry of a directory at
589/// `ref` (the default branch when absent). Returns `Outcome<LastCommits>`.
590#[derive(Debug, Serialize, Deserialize)]
591#[serde(rename_all = "camelCase")]
592pub struct LastCommitsArgs {
593 pub path: RepoPath,
594 pub viewer: Viewer,
595 #[serde(default, rename = "ref")]
596 pub git_ref: Option<String>,
597 #[serde(default)]
598 pub tree_path: String,
599 /// Answer within this many milliseconds with what was found, not kept;
600 /// absent, the walk runs to the end and is kept.
601 #[serde(default)]
602 pub budget_ms: Option<u64>,
603}
604
605/// An entry of a directory and the commit that last changed it.
606#[derive(Clone, Debug, Serialize, Deserialize)]
607pub struct LastCommit {
608 pub name: String,
609 pub commit: Commit,
610}
611
612/// The entries' last commits. `complete` is false when the history walked
613/// ran out before every entry was placed; those entries are left out.
614#[derive(Clone, Debug, Serialize, Deserialize)]
615pub struct LastCommits {
616 pub entries: Vec<LastCommit>,
617 pub complete: bool,
618}
619
620/// `tags`: the repository's tags, newest commit first, each with the
621/// commit it names. Returns `Outcome<Vec<Tag>>`.
622#[derive(Debug, Serialize, Deserialize)]
623pub struct TagsArgs {
624 pub path: RepoPath,
625 pub viewer: Viewer,
626}
627
628/// A tag, and its commit when it could be read.
629#[derive(Clone, Debug, Serialize, Deserialize)]
630pub struct Tag {
631 pub name: String,
632 pub commit: Option<Commit>,
633}
634
635/// `branches`: the repository's branches, default branch first.
636/// Returns `Outcome<Vec<Branch>>`.
637#[derive(Debug, Serialize, Deserialize)]
638pub struct BranchesArgs {
639 pub path: RepoPath,
640 pub viewer: Viewer,
641}
642
643/// `behind`: whether the default branch of the repository a pull request
644/// would merge into has commits its source does not. For services that
645/// have already decided the caller may see the pull request; it reveals
646/// one bit. Returns `bool`.
647#[derive(Debug, Serialize, Deserialize)]
648#[serde(rename_all = "camelCase")]
649pub struct BehindArgs {
650 /// The pull request's fork, or the repository itself for a branch.
651 pub source_id: String,
652 /// The branch of the source. A fork is compared on its default branch.
653 #[serde(default)]
654 pub branch: Option<String>,
655 /// The branch of the target it would merge into; the default branch
656 /// when absent.
657 #[serde(default)]
658 pub target_branch: Option<String>,
659}
660
661/// `divergence`: how a pull request's source and the default branch it
662/// would merge into have moved apart since they last agreed: the files each
663/// side changed. Takes `BehindArgs`. For services that have already decided
664/// the caller may see the pull request; it reveals paths, not contents.
665/// Returns `Option<Divergence>`, null when either side has no commits.
666#[derive(Clone, Debug, Default, Serialize, Deserialize)]
667#[serde(rename_all = "camelCase")]
668pub struct Divergence {
669 /// The source's commit.
670 pub head: String,
671 /// The default branch's commit.
672 pub base: String,
673 /// Where they last agreed, if that could be found.
674 pub merge_base: Option<String>,
675 /// Whether the default branch has commits the source does not.
676 pub behind: bool,
677 /// The files the source changed since the merge base.
678 pub ours: Vec<String>,
679 /// The files the default branch changed since the merge base. Empty
680 /// when it is not behind.
681 pub theirs: Vec<String>,
682 /// Whether either list was cut short.
683 pub truncated: bool,
684}
685
686/// `update_pull_branch`: brings a pull request's source up to date with the
687/// default branch it would merge into, without a sandbox, when that can be
688/// done safely: merges the default branch's head into the source's head and
689/// pushes the merge commit to the source's branch, as `actor`, only if the
690/// branch has not moved meanwhile. It applies only when the two sides
691/// changed different files since they last agreed; otherwise the answer is
692/// [`PullBranchUpdate::NeedsAgent`] and nothing is pushed. Refused unless
693/// `actor` may push to the source. Returns `Outcome<PullBranchUpdate>`.
694#[derive(Debug, Serialize, Deserialize)]
695#[serde(rename_all = "camelCase")]
696pub struct UpdatePullBranchArgs {
697 /// The pull request's fork, or the repository itself for a branch.
698 pub source_id: String,
699 /// The branch of the source. A fork is updated on its default branch.
700 #[serde(default)]
701 pub branch: Option<String>,
702 /// The pull request's number, to name it in the merge commit's message
703 /// when its branch has the same name as the default branch.
704 pub number: u32,
705 /// Who asked: the merge commit's author and committer, and the pusher.
706 pub actor: User,
707 /// The branch of the target to merge in; its default branch when absent.
708 #[serde(default)]
709 pub target_branch: Option<String>,
710}
711
712/// Why an update has to be left to a sandbox.
713#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
714#[serde(rename_all = "snake_case")]
715pub enum NeedsAgentReason {
716 /// Both sides changed some of the same files; merging them needs a
717 /// real merge, which may or may not conflict.
718 Overlap,
719 /// Merging is known to conflict.
720 Conflicting,
721 /// The update could not be worked out here, such as when the two sides
722 /// share no history g1t can see, or the change is too large to list.
723 Unsupported,
724}
725
726/// What came of `update_pull_branch` (or the work service's `catch_up_pull`).
727#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
728#[serde(tag = "outcome", rename_all = "snake_case")]
729pub enum PullBranchUpdate {
730 /// The merge commit was pushed: the branch moved from `previous` to
731 /// `commit`.
732 Updated { commit: String, previous: String },
733 /// The source already holds the default branch's head.
734 UpToDate { commit: String },
735 /// Nothing was pushed; a sandbox has to merge it. `paths` are the
736 /// files both sides changed, or that conflict, when known.
737 NeedsAgent {
738 reason: NeedsAgentReason,
739 detail: String,
740 paths: Vec<String>,
741 },
742}
743
744/// `head`: the commit a branch points to, or null. For services reacting
745/// to a push, which have no viewer; it reveals nothing but a commit hash.
746/// Returns `Option<String>`.
747#[derive(Debug, Serialize, Deserialize)]
748#[serde(rename_all = "camelCase")]
749pub struct HeadArgs {
750 pub repo_id: String,
751 /// Empty for the repository's default branch.
752 pub branch: String,
753}
754
755/// Where g1t keeps branches of its own in a repository, such as the merge
756/// queue's tested states. Only these can be removed with `delete_branch`.
757pub const G1T_BRANCH_PREFIX: &str = "g1t-";
758
759/// `delete_branch`: removes a branch g1t made for itself once it is done
760/// with it, never one of people's: the name must start with
761/// [`G1T_BRANCH_PREFIX`]. For services, which have no viewer. Returns
762/// `Outcome<bool>`: whether there was such a branch.
763#[derive(Debug, Serialize, Deserialize)]
764#[serde(rename_all = "camelCase")]
765pub struct DeleteBranchArgs {
766 pub repo_id: String,
767 pub branch: String,
768}
769
770/// `commit_file`: writes one file on a new branch made from the default
771/// branch's head, as one commit by `actor`, without a sandbox. For a change
772/// g1t proposes on someone's behalf, such as a starter workflow, which then
773/// becomes a pull request. Refused unless `actor` may push, when the branch
774/// already exists, or when the file is already there. Returns
775/// `Outcome<CommittedFile>`.
776#[derive(Debug, Serialize, Deserialize)]
777#[serde(rename_all = "camelCase")]
778pub struct CommitFileArgs {
779 pub repo: RepoPath,
780 pub actor: User,
781 /// The new branch, which must not exist yet.
782 pub branch: String,
783 /// Where the file goes, such as `.g1t/workflows/ci.yml`.
784 pub path: String,
785 pub content: String,
786 pub message: String,
787}
788
789/// The commit `commit_file` made.
790#[derive(Clone, Debug, Serialize, Deserialize)]
791#[serde(rename_all = "camelCase")]
792pub struct CommittedFile {
793 pub branch: String,
794 pub commit: String,
795}
796
797/// `readable`: of these repository ids, the repositories the viewer may
798/// read, as `get_by_id` decides; forks and unknown ids are left out. For
799/// services that hold ids and must show only what the viewer could open.
800/// At most [`MAX_READABLE`] ids are looked at. Returns `Vec<Repo>`.
801#[derive(Debug, Serialize, Deserialize)]
802pub struct ReadableArgs {
803 pub ids: Vec<String>,
804 pub viewer: Viewer,
805}
806
807/// The most ids one `readable` call looks at.
808pub const MAX_READABLE: usize = 500;
809
810/// `public_namespaces`: the workspaces in which this account made a public
811/// repository, and so a public project, which anyone can see on its page.
812/// Returns `Vec<String>` of workspace slugs.
813#[derive(Debug, Serialize, Deserialize)]
814#[serde(rename_all = "camelCase")]
815pub struct PublicNamespacesArgs {
816 pub owner_id: String,
817}
818
819/// One file on a branch, or one a change touched: its path and blob.
820#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
821pub struct FileEntry {
822 pub path: String,
823 /// The blob it holds now; null when the change deleted it.
824 pub hash: Option<String>,
825}
826
827/// Files, and whether there were more than were listed.
828#[derive(Clone, Debug, Default, Serialize, Deserialize)]
829#[serde(rename_all = "camelCase")]
830pub struct FileList {
831 /// The commit the files were read at; null for an empty repository.
832 pub commit: Option<String>,
833 pub files: Vec<FileEntry>,
834 pub truncated: bool,
835}
836
837/// `list_files`: every file on a branch (the default branch when absent),
838/// path order by level, never descending into a directory named in
839/// `skip_dirs`. For services that index a repository; no viewer, since it
840/// is only reached by g1t's own services. Returns `FileList`.
841#[derive(Debug, Default, Serialize, Deserialize)]
842#[serde(rename_all = "camelCase")]
843pub struct ListFilesArgs {
844 pub repo_id: String,
845 #[serde(default, rename = "ref")]
846 pub git_ref: Option<String>,
847 #[serde(default)]
848 pub skip_dirs: Vec<String>,
849 /// At most this many files; capped at [`MAX_LISTED_FILES`].
850 pub limit: u32,
851}
852
853/// `changed_files`: the files that differ between two commits, as
854/// `list_files` reads them. With no `base`, every file at `head`. Returns
855/// `FileList`.
856#[derive(Debug, Default, Serialize, Deserialize)]
857#[serde(rename_all = "camelCase")]
858pub struct ChangedFilesArgs {
859 pub repo_id: String,
860 #[serde(default)]
861 pub base: Option<String>,
862 pub head: String,
863 #[serde(default)]
864 pub skip_dirs: Vec<String>,
865 pub limit: u32,
866}
867
868/// The most files one `list_files` or `changed_files` call lists.
869pub const MAX_LISTED_FILES: u32 = 10_000;
870
871/// `read_blobs`: the text of these blobs of a repository, for services
872/// that index it. A blob larger than `max_bytes`, or binary, comes back
873/// with no text. Returns `Vec<BlobText>`, in the order asked.
874#[derive(Debug, Default, Serialize, Deserialize)]
875#[serde(rename_all = "camelCase")]
876pub struct ReadBlobsArgs {
877 pub repo_id: String,
878 pub hashes: Vec<String>,
879 pub max_bytes: u32,
880}
881
882/// The most blobs one `read_blobs` call reads.
883pub const MAX_READ_BLOBS: usize = 100;
884
885/// `refs`: a repository's branches and tags with the commit each points to
886/// (annotated tags peeled), for services that follow them, such as the
887/// packages service's Composer registry. No viewer: g1t's own services
888/// only. Returns `Option<RepoRefs>`, null for a fork or an unknown id.
889#[derive(Debug, Default, Serialize, Deserialize)]
890#[serde(rename_all = "camelCase")]
891pub struct RefsArgs {
892 pub repo_id: String,
893}
894
895#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
896pub struct GitRefEntry {
897 /// The full ref: `refs/heads/main`, `refs/tags/v1.0.0`.
898 pub name: String,
899 pub commit: String,
900}
901
902#[derive(Clone, Debug, Serialize, Deserialize)]
903pub struct RepoRefs {
904 pub repo: Repo,
905 pub refs: Vec<GitRefEntry>,
906}
907
908/// `raw_file`: one file's bytes at a ref or commit, base64, for g1t's own
909/// services (no viewer). Returns `Option<RawFile>`: null when the file is
910/// missing or larger than `max_bytes`.
911#[derive(Debug, Default, Serialize, Deserialize)]
912#[serde(rename_all = "camelCase")]
913pub struct RawFileArgs {
914 pub repo_id: String,
915 #[serde(rename = "ref")]
916 pub git_ref: String,
917 pub path: String,
918 pub max_bytes: u32,
919}
920
921#[derive(Clone, Debug, Serialize, Deserialize)]
922pub struct RawFile {
923 pub size: u64,
924 /// Standard base64.
925 pub data: String,
926}
927
928/// `raw_blobs`: blobs' bytes, base64, in the order asked, at most
929/// [`MAX_READ_BLOBS`]; `data` is null for one missing or larger than
930/// `max_bytes`. For g1t's own services. Returns `Vec<RawBlob>`.
931#[derive(Debug, Default, Serialize, Deserialize)]
932#[serde(rename_all = "camelCase")]
933pub struct RawBlobsArgs {
934 pub repo_id: String,
935 pub hashes: Vec<String>,
936 pub max_bytes: u32,
937}
938
939#[derive(Clone, Debug, Serialize, Deserialize)]
940pub struct RawBlob {
941 pub hash: String,
942 pub size: u64,
943 pub data: Option<String>,
944}
945
946#[derive(Clone, Debug, Serialize, Deserialize)]
947pub struct BlobText {
948 pub hash: String,
949 pub size: u64,
950 /// Null when the blob is missing, binary or larger than asked.
951 pub text: Option<String>,
952}
953
954/// `all_ids`: every repository that is not a fork, by id, a page at a
955/// time, for services that index all of them. Returns `IdPage`.
956#[derive(Debug, Default, Serialize, Deserialize)]
957pub struct AllIdsArgs {
958 /// Ids after this one.
959 #[serde(default)]
960 pub after: Option<String>,
961 pub limit: u32,
962}
963
964#[derive(Clone, Debug, Default, Serialize, Deserialize)]
965pub struct IdPage {
966 pub ids: Vec<String>,
967 /// Where the next page starts; null on the last.
968 pub next: Option<String>,
969}
970
971/// `repo_creators` takes [`AllIdsArgs`]: every repository that is not a
972/// fork, with the account that created it, a page at a time, for identity
973/// giving creators the Admin role. Returns [`CreatorPage`].
974#[derive(Clone, Debug, Default, Serialize, Deserialize)]
975pub struct CreatorPage {
976 pub repos: Vec<RepoCreator>,
977 /// Where the next page starts; null on the last.
978 pub next: Option<String>,
979}
980
981#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
982pub struct RepoCreator {
983 pub id: String,
984 /// Its workspace's slug.
985 pub namespace: String,
986 pub name: String,
987 /// The account that created it.
988 pub owner_id: String,
989}
990
991/// `visibility`: which of these repositories (`namespace/name`) are
992/// private, for billing, which pays for work on public ones from g1t's
993/// open-source pool. A pull request's working copy answers as the
994/// repository it is a copy of. Unknown paths are left out. Returns
995/// `Vec<RepoVisibility>`.
996#[derive(Debug, Default, Serialize, Deserialize)]
997pub struct VisibilityArgs {
998 pub paths: Vec<String>,
999}
1000
1001#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1002pub struct RepoVisibility {
1003 pub path: String,
1004 pub is_private: bool,
1005}
1006
1007/// `git_operations`: how many git operations (clones, fetches and pushes
1008/// through g1t's git endpoints) each workspace's repositories had in a
1009/// month, for billing's git meter. Cloudflare Artifacts charges per
1010/// operation from 2026-10-14. Pushes from agents' sandboxes go to the
1011/// store directly and are not counted here. Returns
1012/// `Vec<WorkspaceGitOperations>`.
1013#[derive(Debug, Serialize, Deserialize)]
1014pub struct GitOperationsArgs {
1015 /// YYYY-MM.
1016 pub month: String,
1017 /// Count only from this hour on, `YYYY-MM-DDTHH`, such as the day the
1018 /// provider starts charging.
1019 #[serde(default)]
1020 pub since: Option<String>,
1021 /// One workspace only; every workspace with any when absent.
1022 #[serde(default)]
1023 pub namespace: Option<String>,
1024}
1025
1026#[derive(Clone, Debug, Serialize, Deserialize)]
1027pub struct WorkspaceGitOperations {
1028 pub namespace: String,
1029 pub operations: u64,
1030}
1031
1032/// `storage`: what each workspace's private repositories hold, as far as
1033/// g1t can measure it, for billing's daily storage meter. Returns
1034/// `Vec<WorkspaceStorage>`.
1035///
1036/// The git store does not report a repository's size. What is counted is
1037/// the bytes of every pack pushed through g1t's git endpoints to the
1038/// repository or to its pull requests' working copies. Pushes made from
1039/// agents' sandboxes, which go to the store directly, and imports are not
1040/// counted, so it is a lower bound on what is stored.
1041#[derive(Debug, Default, Serialize, Deserialize)]
1042pub struct StorageArgs {}
1043
1044#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1045pub struct WorkspaceStorage {
1046 pub namespace: String,
1047 pub private_bytes: i64,
1048 pub public_bytes: i64,
1049}
1050
1051/// `transfer`: moves a repository to another workspace, keeping its name,
1052/// its id and everything kept under it. The actor must own both
1053/// workspaces. The old path keeps working as a redirect (see
1054/// `resolve_path`) until a repository is made there. Publishes
1055/// `repo.transferred`. Returns `Outcome<Repo>`, the repository at its new
1056/// path.
1057#[derive(Debug, Serialize, Deserialize)]
1058#[serde(rename_all = "camelCase")]
1059pub struct TransferArgs {
1060 pub actor: User,
1061 pub path: RepoPath,
1062 /// The destination workspace's slug.
1063 pub to: String,
1064 /// Where the request came in, for the audit log; g1t.sh when absent.
1065 #[serde(default)]
1066 pub surface: Option<crate::audit::Surface>,
1067}
1068
1069/// `resolve_path`: where a repository that was transferred away from
1070/// `path` is now, while nothing else is there. Returns `Option<RepoPath>`:
1071/// null when `path` is a repository, or never was one that moved. Callers
1072/// check the viewer may see the repository at its new path, as for any
1073/// other.
1074#[derive(Debug, Serialize, Deserialize)]
1075pub struct ResolvePathArgs {
1076 pub path: RepoPath,
1077}
1078
1079/// `namespace_count`: how many repositories (not pull request working
1080/// copies) a workspace holds, private or not, for deciding whether it can
1081/// be deleted. Returns `u32`.
1082#[derive(Debug, Serialize, Deserialize)]
1083pub struct NamespaceCountArgs {
1084 pub namespace: String,
1085}
1086
1087/// `delete`: deletes a repository. Owners of its workspace only, who type
1088/// its full name (`namespace/name`) as `confirm`. It is hidden at once,
1089/// git refuses it, and nothing runs for it; it can be restored for
1090/// [`RESTORE_DAYS`] days, then it is purged, its git data with it. Its
1091/// name stays taken until then, or until it is purged sooner from the
1092/// workspace's Recently deleted list. Publishes `repo.deleted`. Returns
1093/// `Outcome<DeletedRepo>`.
1094#[derive(Debug, Serialize, Deserialize)]
1095#[serde(rename_all = "camelCase")]
1096pub struct DeleteArgs {
1097 pub actor: User,
1098 pub path: RepoPath,
1099 #[serde(default)]
1100 pub confirm: String,
1101 #[serde(default)]
1102 pub surface: Option<crate::audit::Surface>,
1103}
1104
1105/// `deleted`: a workspace's recently deleted repositories, newest first.
1106/// Owners only; empty for anyone else. Returns `Vec<DeletedRepo>`.
1107#[derive(Debug, Serialize, Deserialize)]
1108pub struct DeletedArgs {
1109 pub viewer: Viewer,
1110 pub namespace: String,
1111}
1112
1113/// `restore` and `purge`: a deleted repository, by the path it had.
1114/// `restore` brings it back as it was, at that path (`repo.restored`).
1115/// `purge` removes it for good now, its git data with it, and frees its
1116/// name (`repo.purged`); it takes the full name typed as `confirm`.
1117/// Owners only. Return `Outcome<Repo>` and `Outcome<bool>`.
1118#[derive(Debug, Serialize, Deserialize)]
1119#[serde(rename_all = "camelCase")]
1120pub struct DeletedRepoArgs {
1121 pub actor: User,
1122 pub path: RepoPath,
1123 #[serde(default)]
1124 pub confirm: Option<String>,
1125 #[serde(default)]
1126 pub surface: Option<crate::audit::Surface>,
1127}
1128
1129/// `purge_due`: purges deleted repositories whose time has passed, at
1130/// most `limit` (25 when absent). The service's own schedule runs it.
1131/// Returns `u32`, how many were purged.
1132#[derive(Debug, Default, Serialize, Deserialize)]
1133pub struct PurgeDueArgs {
1134 #[serde(default)]
1135 pub limit: Option<u32>,
1136}
1137
1138/// `rename`: gives a repository a new name in its workspace, keeping its
1139/// id, its git data and everything kept under it. Owners only. The old
1140/// path keeps redirecting, as after a transfer, until a repository is made
1141/// there. Publishes `repo.renamed`. Returns `Outcome<Repo>`.
1142#[derive(Debug, Serialize, Deserialize)]
1143#[serde(rename_all = "camelCase")]
1144pub struct RenameArgs {
1145 pub actor: User,
1146 pub path: RepoPath,
1147 pub name: String,
1148 #[serde(default)]
1149 pub surface: Option<crate::audit::Surface>,
1150}
1151
1152/// `archive`: makes a repository read-only (`archived: true`), or writable
1153/// again. Owners only. While archived, pushes and merges are refused,
1154/// issues and pull requests are locked, and agents and workflows do not
1155/// run; deployments keep serving. Publishes `repo.archived` or
1156/// `repo.unarchived`. Returns `Outcome<Repo>`.
1157#[derive(Debug, Serialize, Deserialize)]
1158#[serde(rename_all = "camelCase")]
1159pub struct ArchiveArgs {
1160 pub actor: User,
1161 pub path: RepoPath,
1162 pub archived: bool,
1163 #[serde(default)]
1164 pub surface: Option<crate::audit::Surface>,
1165}
1166
1167/// `set_visibility`: makes a repository public or private. Owners only,
1168/// who type its full name as `confirm`. A free workspace takes a private
1169/// repository only while its private storage has room. Publishes
1170/// `repo.updated` and `repo.visibility_changed`. Returns `Outcome<Repo>`.
1171#[derive(Debug, Serialize, Deserialize)]
1172#[serde(rename_all = "camelCase")]
1173pub struct SetVisibilityArgs {
1174 pub actor: User,
1175 pub path: RepoPath,
1176 pub is_private: bool,
1177 #[serde(default)]
1178 pub confirm: String,
1179 #[serde(default)]
1180 pub surface: Option<crate::audit::Surface>,
1181}
1182
1183/// `set_default_branch`: makes another existing branch the one everything
1184/// lands on. Members of its workspace. Open pull requests then merge into
1185/// it. Publishes `repo.default_branch_changed`. Returns `Outcome<Repo>`.
1186#[derive(Debug, Serialize, Deserialize)]
1187#[serde(rename_all = "camelCase")]
1188pub struct SetDefaultBranchArgs {
1189 pub actor: User,
1190 pub path: RepoPath,
1191 pub branch: String,
1192 #[serde(default)]
1193 pub surface: Option<crate::audit::Surface>,
1194}
1195
1196/// `rename_branch`: renames a branch. Members of its workspace; only an
1197/// owner renames the default branch, which stays the default. Pull
1198/// requests from it follow, and web addresses naming the old branch
1199/// redirect until a branch of that name is made again. Publishes
1200/// `branch.renamed` (and `repo.default_branch_changed` for the default).
1201/// Returns `Outcome<Repo>`.
1202#[derive(Debug, Serialize, Deserialize)]
1203#[serde(rename_all = "camelCase")]
1204pub struct RenameBranchArgs {
1205 pub actor: User,
1206 pub path: RepoPath,
1207 pub from: String,
1208 pub to: String,
1209 #[serde(default)]
1210 pub surface: Option<crate::audit::Surface>,
1211}
1212
1213/// `resolve_branch`: what a branch renamed away from `branch` is called
1214/// now, for web addresses that name the old one; null when `branch` was
1215/// never renamed or exists again. Returns `Option<String>`.
1216#[derive(Debug, Serialize, Deserialize)]
1217#[serde(rename_all = "camelCase")]
1218pub struct ResolveBranchArgs {
1219 pub repo_id: String,
1220 pub branch: String,
1221}
1222
1223/// `status_by_id`: whether a repository is archived or deleted, for g1t's
1224/// own services deciding whether to act on it. An unknown id answers as
1225/// deleted. Returns `RepoStatus`.
1226#[derive(Debug, Serialize, Deserialize)]
1227pub struct StatusByIdArgs {
1228 pub id: String,
1229}
1230
1231#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1232pub struct RepoStatus {
1233 pub archived: bool,
1234 pub deleted: bool,
1235}
1236
1237impl RepoStatus {
1238 /// Whether work may start on it: neither archived nor deleted.
1239 pub fn active(&self) -> bool {
1240 !self.archived && !self.deleted
1241 }
1242}
1243
1244/// What a person is told when something would change an archived
1245/// repository.
1246pub fn archived_message(namespace: &str, name: &str) -> String {
1247 format!(
1248 "{namespace}/{name} is archived, so it is read-only. An owner can unarchive it in its settings."
1249 )
1250}
1251
1252/// The path a repository was transferred from, and when, as `transfer`
1253/// keeps it so old addresses redirect.
1254#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1255#[serde(rename_all = "camelCase")]
1256pub struct RepoRedirect {
1257 pub from: RepoPath,
1258 pub repo_id: String,
1259 /// RFC 3339.
1260 pub created_at: String,
1261}
1262
1263#[cfg(test)]
1264mod topic_tests {
1265 use super::*;
1266
1267 fn topics(list: &[&str]) -> Result<Vec<String>, String> {
1268 clean_topics(&list.iter().map(|t| t.to_string()).collect::<Vec<_>>())
1269 }
1270
1271 #[test]
1272 fn topics_are_tidied() {
1273 assert_eq!(topics(&["Rust", " web_server ", "rust", ""]).unwrap(), vec!["rust", "web-server"]);
1274 }
1275
1276 #[test]
1277 fn websites_are_tidied() {
1278 assert_eq!(clean_website(" example.com ").unwrap().as_deref(), Some("https://example.com"));
1279 assert_eq!(clean_website("http://a.io/x").unwrap().as_deref(), Some("http://a.io/x"));
1280 assert_eq!(clean_website("").unwrap(), None);
1281 assert!(clean_website("ftp://a.io").is_err());
1282 assert!(clean_website("localhost").is_err());
1283 assert!(clean_website("https://a b.io").is_err());
1284 }
1285
1286 #[test]
1287 fn branch_names_follow_git() {
1288 for good in ["main", "trunk", "release/1.2", "feat-x_y"] {
1289 assert!(is_valid_branch_name(good), "{good}");
1290 }
1291 for bad in ["", "-x", "a..b", "a b", "x.lock", "a/", ".hidden", "a/.b", "g1t-queue", "a~1", "a:b", "@"] {
1292 assert!(!is_valid_branch_name(bad), "{bad}");
1293 }
1294 }
1295
1296 #[test]
1297 fn odd_topics_are_refused() {
1298 assert!(topics(&["c++"]).is_err());
1299 assert!(topics(&["-lead"]).is_err());
1300 assert!(topics(&[&"a".repeat(36)]).is_err());
1301 let many: Vec<String> = (0..21).map(|i| format!("t{i}")).collect();
1302 assert!(clean_topics(&many).is_err());
1303 }
1304}
1305
1306#[cfg(test)]
1307mod tests {
1308 use super::*;
1309
1310 #[test]
1311 fn a_pull_branch_update_reads_as_the_web_expects() {
1312 let update = PullBranchUpdate::NeedsAgent {
1313 reason: NeedsAgentReason::Overlap,
1314 detail: "both".into(),
1315 paths: vec!["a.rs".into()],
1316 };
1317 assert_eq!(
1318 serde_json::to_value(&update).unwrap(),
1319 serde_json::json!({ "outcome": "needs_agent", "reason": "overlap", "detail": "both", "paths": ["a.rs"] })
1320 );
1321 let done = PullBranchUpdate::UpToDate { commit: "c".into() };
1322 assert_eq!(serde_json::to_value(&done).unwrap(), serde_json::json!({ "outcome": "up_to_date", "commit": "c" }));
1323 }
1324}