g1t/crates/contracts/src/repos.rs

1,230 lines41,659 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.

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