g1t/crates/contracts/src/repos.rs

1,288 lines43,618 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
Repositories shard across git store namespaces, move between them, and can keep to the EU; a namespace can be served read-only from the self-hosted git store, rebuilt from the nightly backups (#20, #25)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
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look59/// 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,
Search across all of g1t, Explore, and a command palette78}
79
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look80/// 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
Search across all of g1t, Explore, and a command palette136/// 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)
Rust repos service with shipping; pull requests kept in the model173}
174
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API175#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Rust repos service with shipping; pull requests kept in the model176pub 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>,
RFC 3339 timestamps in identity and repos195 /// RFC 3339.
196 pub authored_at: String,
Rust repos service with shipping; pull requests kept in the model197}
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
Issues and pull requests replace intents and attempts261/// The result of landing a pull request.
Rust repos service with shipping; pull requests kept in the model262#[derive(Clone, Debug, Serialize, Deserialize)]
263pub struct Landed {
Diffs on attempts; hosted agent presented as the g1t agent264 /// The commit the branch points to now.
Rust repos service with shipping; pull requests kept in the model265 pub commit: String,
Diffs on attempts; hosted agent presented as the g1t agent266 /// The commit it pointed to before, if it had one. Comparing against
Issues and pull requests replace intents and attempts267 /// this shows what the pull request changed.
Diffs on attempts; hosted agent presented as the g1t agent268 pub previous: Option<String>,
Rust repos service with shipping; pull requests kept in the model269}
270
271/// `get`. Returns `Outcome<Repo>`.
272#[derive(Debug, Serialize, Deserialize)]
273pub struct GetArgs {
274 pub path: RepoPath,
275 pub viewer: Viewer,
276}
277
Automations: rules in .g1t/automations that act when something happens278/// `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
Rust repos service with shipping; pull requests kept in the model287/// `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)]
Workspaces own repositories296#[serde(rename_all = "camelCase")]
Rust repos service with shipping; pull requests kept in the model297pub struct ListArgs {
298 pub viewer: Viewer,
299 #[serde(default)]
300 pub query: Option<String>,
Workspaces own repositories301 /// Only repos in this workspace.
Rust repos service with shipping; pull requests kept in the model302 #[serde(default)]
303 pub namespace: Option<String>,
Workspaces own repositories304 /// Only repos in workspaces the viewer belongs to.
305 #[serde(default)]
306 pub member_only: bool,
Rust repos service with shipping; pull requests kept in the model307}
308
309/// `create`. Returns `Outcome<Repo>`.
310#[derive(Debug, Serialize, Deserialize)]
311#[serde(rename_all = "camelCase")]
312pub struct CreateArgs {
Workspaces own repositories313 /// Who is creating it; they must belong to the workspace.
Rust repos service with shipping; pull requests kept in the model314 pub owner: User,
Workspaces own repositories315 /// The workspace it is created in.
316 pub namespace: String,
Rust repos service with shipping; pull requests kept in the model317 pub name: String,
318 #[serde(default)]
319 pub description: Option<String>,
320 #[serde(default)]
321 pub is_private: bool,
Agents as a team: lifecycle, merge queue, billing and a new shell322 /// 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>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look326 /// 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>,
Rust repos service with shipping; pull requests kept in the model331}
332
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look333/// `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
Agents as a team: lifecycle, merge queue, billing and a new shell368/// `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>,
Search across all of g1t, Explore, and a command palette382 /// Replaces its topics; an empty list clears them.
383 #[serde(default)]
384 pub topics: Option<Vec<String>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look385 /// 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>,
Agents as a team: lifecycle, merge queue, billing and a new shell391}
392
Rust repos service with shipping; pull requests kept in the model393/// `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
Issues and pull requests replace intents and attempts427/// `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>`.
Rust repos service with shipping; pull requests kept in the model429#[derive(Debug, Serialize, Deserialize)]
430#[serde(rename_all = "camelCase")]
431pub struct ForkArgs {
432 pub source_id: String,
Issues and pull requests replace intents and attempts433 pub pull_id: String,
Rust repos service with shipping; pull requests kept in the model434 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
Pull requests from branches447/// `land`: moves a repository's default branch to the head of a pull
448/// request's source. Refused with `conflict` when the source is behind,
449/// since that would discard commits. Returns `Outcome<Landed>`.
Rust repos service with shipping; pull requests kept in the model450#[derive(Debug, Serialize, Deserialize)]
451#[serde(rename_all = "camelCase")]
452pub struct LandArgs {
Pull requests from branches453 /// The repository holding the commits: a pull request's fork, or the
454 /// target itself when landing one of its own branches.
455 pub source_id: String,
456 /// The branch of the source to land. Required when the source is the
457 /// target; a fork lands its default branch.
458 #[serde(default)]
459 pub branch: Option<String>,
Rust repos service with shipping; pull requests kept in the model460 pub actor: User,
461}
Diffs on attempts; hosted agent presented as the g1t agent462
463#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
464#[serde(rename_all = "lowercase")]
465pub enum FileStatus {
466 Added,
467 Modified,
468 Deleted,
469}
470
471#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
472#[serde(rename_all = "lowercase")]
473pub enum LineKind {
474 /// Unchanged, shown for context.
475 Context,
476 Add,
477 Delete,
478}
479
480#[derive(Clone, Debug, Serialize, Deserialize)]
481pub struct DiffLine {
482 pub kind: LineKind,
483 /// Line number in the old file; absent for added lines.
484 pub old: Option<u32>,
485 /// Line number in the new file; absent for deleted lines.
486 pub new: Option<u32>,
487 pub text: String,
488}
489
490/// A run of changed lines with their surrounding context.
491#[derive(Clone, Debug, Serialize, Deserialize)]
492pub struct Hunk {
493 pub lines: Vec<DiffLine>,
494}
495
496#[derive(Clone, Debug, Serialize, Deserialize)]
497pub struct FileDiff {
498 pub path: String,
499 pub status: FileStatus,
500 pub additions: u32,
501 pub deletions: u32,
502 /// True when the file is binary or too large, so no lines are shown.
503 pub binary: bool,
504 pub hunks: Vec<Hunk>,
505}
506
507/// What changed between two commits.
508#[derive(Clone, Debug, Serialize, Deserialize)]
509pub struct Comparison {
510 /// Null when the head has no earlier commit to compare against.
511 pub base: Option<String>,
512 pub head: String,
513 pub files: Vec<FileDiff>,
514 /// True when the change was too large to return in full.
515 pub truncated: bool,
516}
517
Pull requests from branches518/// `compare`: what `head` changes relative to `base`.
Diffs on attempts; hosted agent presented as the g1t agent519///
Pull requests from branches520/// `head` is a branch or a commit, and defaults to the default branch.
521/// With no `base`, a fork is compared against the point where it and the
522/// repository it came from last agreed; a branch against the point where it
523/// left the default branch; and the default branch against its head's
524/// parent. Returns `Outcome<Comparison>`.
Diffs on attempts; hosted agent presented as the g1t agent525#[derive(Debug, Serialize, Deserialize)]
526#[serde(rename_all = "camelCase")]
527pub struct CompareArgs {
528 pub repo_id: String,
529 pub viewer: Viewer,
530 #[serde(default)]
531 pub base: Option<String>,
Pull requests from branches532 #[serde(default)]
533 pub head: Option<String>,
534}
535
Agents as a team: lifecycle, merge queue, billing and a new shell536/// Lines `start` to `end` of a file, inclusive and counted from 1, last
537/// changed by `commit`.
538#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
539pub struct BlameRange {
540 pub start: u32,
541 pub end: u32,
542 pub commit: String,
543}
544
545/// Who last changed each line of a file.
546#[derive(Clone, Debug, Serialize, Deserialize)]
547pub struct Blame {
548 /// The commit the file was read at.
549 pub head: String,
550 /// Every line, in order, in runs that share a commit.
551 pub ranges: Vec<BlameRange>,
552 /// The commits the ranges name, each once.
553 pub commits: Vec<Commit>,
554 /// True when the history was too long to read in full, so the oldest
555 /// lines are given to the oldest commit read.
556 pub partial: bool,
557}
558
559/// `blame`: who last changed each line of `path` as of `ref` (the default
560/// branch if absent). Returns `Outcome<Blame>`; not found when the file is
561/// missing or is not text.
562#[derive(Debug, Serialize, Deserialize)]
563pub struct BlameArgs {
564 pub path: RepoPath,
565 pub viewer: Viewer,
566 #[serde(default, rename = "ref")]
567 pub git_ref: Option<String>,
568 #[serde(rename = "filePath")]
569 pub file_path: String,
570}
571
Pull requests from branches572/// A branch and the commit it points to.
573#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
574pub struct Branch {
575 pub name: String,
576 pub hash: String,
577}
578
Branches and Tags pages, each file's last commit, and the branch menu on files579/// `last_commits`: which commit last changed each entry of a directory at
580/// `ref` (the default branch when absent). Returns `Outcome<LastCommits>`.
581#[derive(Debug, Serialize, Deserialize)]
582#[serde(rename_all = "camelCase")]
583pub struct LastCommitsArgs {
584 pub path: RepoPath,
585 pub viewer: Viewer,
586 #[serde(default, rename = "ref")]
587 pub git_ref: Option<String>,
588 #[serde(default)]
589 pub tree_path: String,
A last-commits walk runs to the end unless asked for a budget; the page bounds its own wait590 /// Answer within this many milliseconds with what was found, not kept;
591 /// absent, the walk runs to the end and is kept.
592 #[serde(default)]
593 pub budget_ms: Option<u64>,
Branches and Tags pages, each file's last commit, and the branch menu on files594}
595
596/// An entry of a directory and the commit that last changed it.
597#[derive(Clone, Debug, Serialize, Deserialize)]
598pub struct LastCommit {
599 pub name: String,
600 pub commit: Commit,
601}
602
603/// The entries' last commits. `complete` is false when the history walked
604/// ran out before every entry was placed; those entries are left out.
605#[derive(Clone, Debug, Serialize, Deserialize)]
606pub struct LastCommits {
607 pub entries: Vec<LastCommit>,
608 pub complete: bool,
609}
610
611/// `tags`: the repository's tags, newest commit first, each with the
612/// commit it names. Returns `Outcome<Vec<Tag>>`.
613#[derive(Debug, Serialize, Deserialize)]
614pub struct TagsArgs {
615 pub path: RepoPath,
616 pub viewer: Viewer,
617}
618
619/// A tag, and its commit when it could be read.
620#[derive(Clone, Debug, Serialize, Deserialize)]
621pub struct Tag {
622 pub name: String,
623 pub commit: Option<Commit>,
624}
625
Pull requests from branches626/// `branches`: the repository's branches, default branch first.
627/// Returns `Outcome<Vec<Branch>>`.
628#[derive(Debug, Serialize, Deserialize)]
629pub struct BranchesArgs {
630 pub path: RepoPath,
631 pub viewer: Viewer,
632}
633
Agents as a team: lifecycle, merge queue, billing and a new shell634/// `behind`: whether the default branch of the repository a pull request
635/// would merge into has commits its source does not. For services that
636/// have already decided the caller may see the pull request; it reveals
637/// one bit. Returns `bool`.
638#[derive(Debug, Serialize, Deserialize)]
639#[serde(rename_all = "camelCase")]
640pub struct BehindArgs {
641 /// The pull request's fork, or the repository itself for a branch.
642 pub source_id: String,
643 /// The branch of the source. A fork is compared on its default branch.
644 #[serde(default)]
645 pub branch: Option<String>,
646}
647
Agents and memory, checks and conflicts, profiles, slug renames, custom domains648/// `divergence`: how a pull request's source and the default branch it
649/// would merge into have moved apart since they last agreed: the files each
650/// side changed. Takes `BehindArgs`. For services that have already decided
651/// the caller may see the pull request; it reveals paths, not contents.
652/// Returns `Option<Divergence>`, null when either side has no commits.
653#[derive(Clone, Debug, Default, Serialize, Deserialize)]
654#[serde(rename_all = "camelCase")]
655pub struct Divergence {
656 /// The source's commit.
657 pub head: String,
658 /// The default branch's commit.
659 pub base: String,
660 /// Where they last agreed, if that could be found.
661 pub merge_base: Option<String>,
662 /// Whether the default branch has commits the source does not.
663 pub behind: bool,
664 /// The files the source changed since the merge base.
665 pub ours: Vec<String>,
666 /// The files the default branch changed since the merge base. Empty
667 /// when it is not behind.
668 pub theirs: Vec<String>,
669 /// Whether either list was cut short.
670 pub truncated: bool,
671}
672
Catching up with main takes seconds when the two sides touched different files673/// `update_pull_branch`: brings a pull request's source up to date with the
674/// default branch it would merge into, without a sandbox, when that can be
675/// done safely: merges the default branch's head into the source's head and
676/// pushes the merge commit to the source's branch, as `actor`, only if the
677/// branch has not moved meanwhile. It applies only when the two sides
678/// changed different files since they last agreed; otherwise the answer is
679/// [`PullBranchUpdate::NeedsAgent`] and nothing is pushed. Refused unless
680/// `actor` may push to the source. Returns `Outcome<PullBranchUpdate>`.
681#[derive(Debug, Serialize, Deserialize)]
682#[serde(rename_all = "camelCase")]
683pub struct UpdatePullBranchArgs {
684 /// The pull request's fork, or the repository itself for a branch.
685 pub source_id: String,
686 /// The branch of the source. A fork is updated on its default branch.
687 #[serde(default)]
688 pub branch: Option<String>,
689 /// The pull request's number, to name it in the merge commit's message
690 /// when its branch has the same name as the default branch.
691 pub number: u32,
692 /// Who asked: the merge commit's author and committer, and the pusher.
693 pub actor: User,
694}
695
696/// Why an update has to be left to a sandbox.
697#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
698#[serde(rename_all = "snake_case")]
699pub enum NeedsAgentReason {
700 /// Both sides changed some of the same files; merging them needs a
701 /// real merge, which may or may not conflict.
702 Overlap,
703 /// Merging is known to conflict.
704 Conflicting,
705 /// The update could not be worked out here, such as when the two sides
706 /// share no history g1t can see, or the change is too large to list.
707 Unsupported,
708}
709
710/// What came of `update_pull_branch` (or the work service's `catch_up_pull`).
711#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
712#[serde(tag = "outcome", rename_all = "snake_case")]
713pub enum PullBranchUpdate {
714 /// The merge commit was pushed: the branch moved from `previous` to
715 /// `commit`.
716 Updated { commit: String, previous: String },
717 /// The source already holds the default branch's head.
718 UpToDate { commit: String },
719 /// Nothing was pushed; a sandbox has to merge it. `paths` are the
720 /// files both sides changed, or that conflict, when known.
721 NeedsAgent {
722 reason: NeedsAgentReason,
723 detail: String,
724 paths: Vec<String>,
725 },
726}
727
Pull requests from branches728/// `head`: the commit a branch points to, or null. For services reacting
729/// to a push, which have no viewer; it reveals nothing but a commit hash.
730/// Returns `Option<String>`.
731#[derive(Debug, Serialize, Deserialize)]
732#[serde(rename_all = "camelCase")]
733pub struct HeadArgs {
734 pub repo_id: String,
Workflows run when an agent's pull request is marked ready735 /// Empty for the repository's default branch.
Pull requests from branches736 pub branch: String,
Diffs on attempts; hosted agent presented as the g1t agent737}
Merge queue: tested states are deleted once their entry leaves738
739/// Where g1t keeps branches of its own in a repository, such as the merge
740/// queue's tested states. Only these can be removed with `delete_branch`.
741pub const G1T_BRANCH_PREFIX: &str = "g1t-";
742
743/// `delete_branch`: removes a branch g1t made for itself once it is done
744/// with it, never one of people's: the name must start with
745/// [`G1T_BRANCH_PREFIX`]. For services, which have no viewer. Returns
746/// `Outcome<bool>`: whether there was such a branch.
747#[derive(Debug, Serialize, Deserialize)]
748#[serde(rename_all = "camelCase")]
749pub struct DeleteBranchArgs {
750 pub repo_id: String,
751 pub branch: String,
752}
Agents and memory, checks and conflicts, profiles, slug renames, custom domains753
Fast pages, required checks on the branch, self-hosted runners, honest incidents754/// `commit_file`: writes one file on a new branch made from the default
755/// branch's head, as one commit by `actor`, without a sandbox. For a change
756/// g1t proposes on someone's behalf, such as a starter workflow, which then
757/// becomes a pull request. Refused unless `actor` may push, when the branch
758/// already exists, or when the file is already there. Returns
759/// `Outcome<CommittedFile>`.
760#[derive(Debug, Serialize, Deserialize)]
761#[serde(rename_all = "camelCase")]
762pub struct CommitFileArgs {
763 pub repo: RepoPath,
764 pub actor: User,
765 /// The new branch, which must not exist yet.
766 pub branch: String,
767 /// Where the file goes, such as `.g1t/workflows/ci.yml`.
768 pub path: String,
769 pub content: String,
770 pub message: String,
771}
772
773/// The commit `commit_file` made.
774#[derive(Clone, Debug, Serialize, Deserialize)]
775#[serde(rename_all = "camelCase")]
776pub struct CommittedFile {
777 pub branch: String,
778 pub commit: String,
779}
780
Agents and memory, checks and conflicts, profiles, slug renames, custom domains781/// `readable`: of these repository ids, the repositories the viewer may
782/// read, as `get_by_id` decides; forks and unknown ids are left out. For
783/// services that hold ids and must show only what the viewer could open.
784/// At most [`MAX_READABLE`] ids are looked at. Returns `Vec<Repo>`.
785#[derive(Debug, Serialize, Deserialize)]
786pub struct ReadableArgs {
787 pub ids: Vec<String>,
788 pub viewer: Viewer,
789}
790
791/// The most ids one `readable` call looks at.
792pub const MAX_READABLE: usize = 500;
793
794/// `public_namespaces`: the workspaces in which this account made a public
795/// repository, and so a public project, which anyone can see on its page.
796/// Returns `Vec<String>` of workspace slugs.
797#[derive(Debug, Serialize, Deserialize)]
798#[serde(rename_all = "camelCase")]
799pub struct PublicNamespacesArgs {
800 pub owner_id: String,
801}
Search across all of g1t, Explore, and a command palette802
803/// One file on a branch, or one a change touched: its path and blob.
804#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
805pub struct FileEntry {
806 pub path: String,
807 /// The blob it holds now; null when the change deleted it.
808 pub hash: Option<String>,
809}
810
811/// Files, and whether there were more than were listed.
812#[derive(Clone, Debug, Default, Serialize, Deserialize)]
813#[serde(rename_all = "camelCase")]
814pub struct FileList {
815 /// The commit the files were read at; null for an empty repository.
816 pub commit: Option<String>,
817 pub files: Vec<FileEntry>,
818 pub truncated: bool,
819}
820
821/// `list_files`: every file on a branch (the default branch when absent),
822/// path order by level, never descending into a directory named in
823/// `skip_dirs`. For services that index a repository; no viewer, since it
824/// is only reached by g1t's own services. Returns `FileList`.
825#[derive(Debug, Default, Serialize, Deserialize)]
826#[serde(rename_all = "camelCase")]
827pub struct ListFilesArgs {
828 pub repo_id: String,
829 #[serde(default, rename = "ref")]
830 pub git_ref: Option<String>,
831 #[serde(default)]
832 pub skip_dirs: Vec<String>,
833 /// At most this many files; capped at [`MAX_LISTED_FILES`].
834 pub limit: u32,
835}
836
837/// `changed_files`: the files that differ between two commits, as
838/// `list_files` reads them. With no `base`, every file at `head`. Returns
839/// `FileList`.
840#[derive(Debug, Default, Serialize, Deserialize)]
841#[serde(rename_all = "camelCase")]
842pub struct ChangedFilesArgs {
843 pub repo_id: String,
844 #[serde(default)]
845 pub base: Option<String>,
846 pub head: String,
847 #[serde(default)]
848 pub skip_dirs: Vec<String>,
849 pub limit: u32,
850}
851
852/// The most files one `list_files` or `changed_files` call lists.
853pub const MAX_LISTED_FILES: u32 = 10_000;
854
855/// `read_blobs`: the text of these blobs of a repository, for services
856/// that index it. A blob larger than `max_bytes`, or binary, comes back
857/// with no text. Returns `Vec<BlobText>`, in the order asked.
858#[derive(Debug, Default, Serialize, Deserialize)]
859#[serde(rename_all = "camelCase")]
860pub struct ReadBlobsArgs {
861 pub repo_id: String,
862 pub hashes: Vec<String>,
863 pub max_bytes: u32,
864}
865
866/// The most blobs one `read_blobs` call reads.
867pub const MAX_READ_BLOBS: usize = 100;
868
Composer from the workspace's own repositories, and go get from g1t.sh869/// `refs`: a repository's branches and tags with the commit each points to
870/// (annotated tags peeled), for services that follow them, such as the
871/// packages service's Composer registry. No viewer: g1t's own services
872/// only. Returns `Option<RepoRefs>`, null for a fork or an unknown id.
873#[derive(Debug, Default, Serialize, Deserialize)]
874#[serde(rename_all = "camelCase")]
875pub struct RefsArgs {
876 pub repo_id: String,
877}
878
879#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
880pub struct GitRefEntry {
881 /// The full ref: `refs/heads/main`, `refs/tags/v1.0.0`.
882 pub name: String,
883 pub commit: String,
884}
885
886#[derive(Clone, Debug, Serialize, Deserialize)]
887pub struct RepoRefs {
888 pub repo: Repo,
889 pub refs: Vec<GitRefEntry>,
890}
891
892/// `raw_file`: one file's bytes at a ref or commit, base64, for g1t's own
893/// services (no viewer). Returns `Option<RawFile>`: null when the file is
894/// missing or larger than `max_bytes`.
895#[derive(Debug, Default, Serialize, Deserialize)]
896#[serde(rename_all = "camelCase")]
897pub struct RawFileArgs {
898 pub repo_id: String,
899 #[serde(rename = "ref")]
900 pub git_ref: String,
901 pub path: String,
902 pub max_bytes: u32,
903}
904
905#[derive(Clone, Debug, Serialize, Deserialize)]
906pub struct RawFile {
907 pub size: u64,
908 /// Standard base64.
909 pub data: String,
910}
911
912/// `raw_blobs`: blobs' bytes, base64, in the order asked, at most
913/// [`MAX_READ_BLOBS`]; `data` is null for one missing or larger than
914/// `max_bytes`. For g1t's own services. Returns `Vec<RawBlob>`.
915#[derive(Debug, Default, Serialize, Deserialize)]
916#[serde(rename_all = "camelCase")]
917pub struct RawBlobsArgs {
918 pub repo_id: String,
919 pub hashes: Vec<String>,
920 pub max_bytes: u32,
921}
922
923#[derive(Clone, Debug, Serialize, Deserialize)]
924pub struct RawBlob {
925 pub hash: String,
926 pub size: u64,
927 pub data: Option<String>,
928}
929
Search across all of g1t, Explore, and a command palette930#[derive(Clone, Debug, Serialize, Deserialize)]
931pub struct BlobText {
932 pub hash: String,
933 pub size: u64,
934 /// Null when the blob is missing, binary or larger than asked.
935 pub text: Option<String>,
936}
937
938/// `all_ids`: every repository that is not a fork, by id, a page at a
939/// time, for services that index all of them. Returns `IdPage`.
940#[derive(Debug, Default, Serialize, Deserialize)]
941pub struct AllIdsArgs {
942 /// Ids after this one.
943 #[serde(default)]
944 pub after: Option<String>,
945 pub limit: u32,
946}
947
948#[derive(Clone, Debug, Default, Serialize, Deserialize)]
949pub struct IdPage {
950 pub ids: Vec<String>,
951 /// Where the next page starts; null on the last.
952 pub next: Option<String>,
953}
954
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put955/// `visibility`: which of these repositories (`namespace/name`) are
956/// private, for billing, which pays for work on public ones from g1t's
957/// open-source pool. A pull request's working copy answers as the
958/// repository it is a copy of. Unknown paths are left out. Returns
959/// `Vec<RepoVisibility>`.
960#[derive(Debug, Default, Serialize, Deserialize)]
961pub struct VisibilityArgs {
962 pub paths: Vec<String>,
963}
964
965#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
966pub struct RepoVisibility {
967 pub path: String,
968 pub is_private: bool,
969}
970
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look971/// `git_operations`: how many git operations (clones, fetches and pushes
972/// through g1t's git endpoints) each workspace's repositories had in a
973/// month, for billing's git meter. Cloudflare Artifacts charges per
974/// operation from 2026-10-14. Pushes from agents' sandboxes go to the
975/// store directly and are not counted here. Returns
976/// `Vec<WorkspaceGitOperations>`.
977#[derive(Debug, Serialize, Deserialize)]
978pub struct GitOperationsArgs {
979 /// YYYY-MM.
980 pub month: String,
981 /// Count only from this hour on, `YYYY-MM-DDTHH`, such as the day the
982 /// provider starts charging.
983 #[serde(default)]
984 pub since: Option<String>,
985 /// One workspace only; every workspace with any when absent.
986 #[serde(default)]
987 pub namespace: Option<String>,
988}
989
990#[derive(Clone, Debug, Serialize, Deserialize)]
991pub struct WorkspaceGitOperations {
992 pub namespace: String,
993 pub operations: u64,
994}
995
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put996/// `storage`: what each workspace's private repositories hold, as far as
997/// g1t can measure it, for billing's daily storage meter. Returns
998/// `Vec<WorkspaceStorage>`.
999///
1000/// The git store does not report a repository's size. What is counted is
1001/// the bytes of every pack pushed through g1t's git endpoints to the
1002/// repository or to its pull requests' working copies. Pushes made from
1003/// agents' sandboxes, which go to the store directly, and imports are not
1004/// counted, so it is a lower bound on what is stored.
1005#[derive(Debug, Default, Serialize, Deserialize)]
1006pub struct StorageArgs {}
1007
1008#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1009pub struct WorkspaceStorage {
1010 pub namespace: String,
1011 pub private_bytes: i64,
1012 pub public_bytes: i64,
1013}
1014
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1015/// `transfer`: moves a repository to another workspace, keeping its name,
1016/// its id and everything kept under it. The actor must own both
1017/// workspaces. The old path keeps working as a redirect (see
1018/// `resolve_path`) until a repository is made there. Publishes
1019/// `repo.transferred`. Returns `Outcome<Repo>`, the repository at its new
1020/// path.
1021#[derive(Debug, Serialize, Deserialize)]
1022#[serde(rename_all = "camelCase")]
1023pub struct TransferArgs {
1024 pub actor: User,
1025 pub path: RepoPath,
1026 /// The destination workspace's slug.
1027 pub to: String,
1028 /// Where the request came in, for the audit log; g1t.sh when absent.
1029 #[serde(default)]
1030 pub surface: Option<crate::audit::Surface>,
1031}
1032
1033/// `resolve_path`: where a repository that was transferred away from
1034/// `path` is now, while nothing else is there. Returns `Option<RepoPath>`:
1035/// null when `path` is a repository, or never was one that moved. Callers
1036/// check the viewer may see the repository at its new path, as for any
1037/// other.
1038#[derive(Debug, Serialize, Deserialize)]
1039pub struct ResolvePathArgs {
1040 pub path: RepoPath,
1041}
1042
1043/// `namespace_count`: how many repositories (not pull request working
1044/// copies) a workspace holds, private or not, for deciding whether it can
1045/// be deleted. Returns `u32`.
1046#[derive(Debug, Serialize, Deserialize)]
1047pub struct NamespaceCountArgs {
1048 pub namespace: String,
1049}
1050
1051/// `delete`: deletes a repository. Owners of its workspace only, who type
1052/// its full name (`namespace/name`) as `confirm`. It is hidden at once,
1053/// git refuses it, and nothing runs for it; it can be restored for
1054/// [`RESTORE_DAYS`] days, then it is purged, its git data with it. Its
1055/// name stays taken until then, or until it is purged sooner from the
1056/// workspace's Recently deleted list. Publishes `repo.deleted`. Returns
1057/// `Outcome<DeletedRepo>`.
1058#[derive(Debug, Serialize, Deserialize)]
1059#[serde(rename_all = "camelCase")]
1060pub struct DeleteArgs {
1061 pub actor: User,
1062 pub path: RepoPath,
1063 #[serde(default)]
1064 pub confirm: String,
1065 #[serde(default)]
1066 pub surface: Option<crate::audit::Surface>,
1067}
1068
1069/// `deleted`: a workspace's recently deleted repositories, newest first.
1070/// Owners only; empty for anyone else. Returns `Vec<DeletedRepo>`.
1071#[derive(Debug, Serialize, Deserialize)]
1072pub struct DeletedArgs {
1073 pub viewer: Viewer,
1074 pub namespace: String,
1075}
1076
1077/// `restore` and `purge`: a deleted repository, by the path it had.
1078/// `restore` brings it back as it was, at that path (`repo.restored`).
1079/// `purge` removes it for good now, its git data with it, and frees its
1080/// name (`repo.purged`); it takes the full name typed as `confirm`.
1081/// Owners only. Return `Outcome<Repo>` and `Outcome<bool>`.
1082#[derive(Debug, Serialize, Deserialize)]
1083#[serde(rename_all = "camelCase")]
1084pub struct DeletedRepoArgs {
1085 pub actor: User,
1086 pub path: RepoPath,
1087 #[serde(default)]
1088 pub confirm: Option<String>,
1089 #[serde(default)]
1090 pub surface: Option<crate::audit::Surface>,
1091}
1092
1093/// `purge_due`: purges deleted repositories whose time has passed, at
1094/// most `limit` (25 when absent). The service's own schedule runs it.
1095/// Returns `u32`, how many were purged.
1096#[derive(Debug, Default, Serialize, Deserialize)]
1097pub struct PurgeDueArgs {
1098 #[serde(default)]
1099 pub limit: Option<u32>,
1100}
1101
1102/// `rename`: gives a repository a new name in its workspace, keeping its
1103/// id, its git data and everything kept under it. Owners only. The old
1104/// path keeps redirecting, as after a transfer, until a repository is made
1105/// there. Publishes `repo.renamed`. Returns `Outcome<Repo>`.
1106#[derive(Debug, Serialize, Deserialize)]
1107#[serde(rename_all = "camelCase")]
1108pub struct RenameArgs {
1109 pub actor: User,
1110 pub path: RepoPath,
1111 pub name: String,
1112 #[serde(default)]
1113 pub surface: Option<crate::audit::Surface>,
1114}
1115
1116/// `archive`: makes a repository read-only (`archived: true`), or writable
1117/// again. Owners only. While archived, pushes and merges are refused,
1118/// issues and pull requests are locked, and agents and workflows do not
1119/// run; deployments keep serving. Publishes `repo.archived` or
1120/// `repo.unarchived`. Returns `Outcome<Repo>`.
1121#[derive(Debug, Serialize, Deserialize)]
1122#[serde(rename_all = "camelCase")]
1123pub struct ArchiveArgs {
1124 pub actor: User,
1125 pub path: RepoPath,
1126 pub archived: bool,
1127 #[serde(default)]
1128 pub surface: Option<crate::audit::Surface>,
1129}
1130
1131/// `set_visibility`: makes a repository public or private. Owners only,
1132/// who type its full name as `confirm`. A free workspace takes a private
1133/// repository only while its private storage has room. Publishes
1134/// `repo.updated` and `repo.visibility_changed`. Returns `Outcome<Repo>`.
1135#[derive(Debug, Serialize, Deserialize)]
1136#[serde(rename_all = "camelCase")]
1137pub struct SetVisibilityArgs {
1138 pub actor: User,
1139 pub path: RepoPath,
1140 pub is_private: bool,
1141 #[serde(default)]
1142 pub confirm: String,
1143 #[serde(default)]
1144 pub surface: Option<crate::audit::Surface>,
1145}
1146
1147/// `set_default_branch`: makes another existing branch the one everything
1148/// lands on. Members of its workspace. Open pull requests then merge into
1149/// it. Publishes `repo.default_branch_changed`. Returns `Outcome<Repo>`.
1150#[derive(Debug, Serialize, Deserialize)]
1151#[serde(rename_all = "camelCase")]
1152pub struct SetDefaultBranchArgs {
1153 pub actor: User,
1154 pub path: RepoPath,
1155 pub branch: String,
1156 #[serde(default)]
1157 pub surface: Option<crate::audit::Surface>,
1158}
1159
1160/// `rename_branch`: renames a branch. Members of its workspace; only an
1161/// owner renames the default branch, which stays the default. Pull
1162/// requests from it follow, and web addresses naming the old branch
1163/// redirect until a branch of that name is made again. Publishes
1164/// `branch.renamed` (and `repo.default_branch_changed` for the default).
1165/// Returns `Outcome<Repo>`.
1166#[derive(Debug, Serialize, Deserialize)]
1167#[serde(rename_all = "camelCase")]
1168pub struct RenameBranchArgs {
1169 pub actor: User,
1170 pub path: RepoPath,
1171 pub from: String,
1172 pub to: String,
1173 #[serde(default)]
1174 pub surface: Option<crate::audit::Surface>,
1175}
1176
1177/// `resolve_branch`: what a branch renamed away from `branch` is called
1178/// now, for web addresses that name the old one; null when `branch` was
1179/// never renamed or exists again. Returns `Option<String>`.
1180#[derive(Debug, Serialize, Deserialize)]
1181#[serde(rename_all = "camelCase")]
1182pub struct ResolveBranchArgs {
1183 pub repo_id: String,
1184 pub branch: String,
1185}
1186
1187/// `status_by_id`: whether a repository is archived or deleted, for g1t's
1188/// own services deciding whether to act on it. An unknown id answers as
1189/// deleted. Returns `RepoStatus`.
1190#[derive(Debug, Serialize, Deserialize)]
1191pub struct StatusByIdArgs {
1192 pub id: String,
1193}
1194
1195#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1196pub struct RepoStatus {
1197 pub archived: bool,
1198 pub deleted: bool,
1199}
1200
1201impl RepoStatus {
1202 /// Whether work may start on it: neither archived nor deleted.
1203 pub fn active(&self) -> bool {
1204 !self.archived && !self.deleted
1205 }
1206}
1207
1208/// What a person is told when something would change an archived
1209/// repository.
1210pub fn archived_message(namespace: &str, name: &str) -> String {
1211 format!(
1212 "{namespace}/{name} is archived, so it is read-only. An owner can unarchive it in its settings."
1213 )
1214}
1215
1216/// The path a repository was transferred from, and when, as `transfer`
1217/// keeps it so old addresses redirect.
1218#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1219#[serde(rename_all = "camelCase")]
1220pub struct RepoRedirect {
1221 pub from: RepoPath,
1222 pub repo_id: String,
1223 /// RFC 3339.
1224 pub created_at: String,
1225}
1226
Search across all of g1t, Explore, and a command palette1227#[cfg(test)]
1228mod topic_tests {
1229 use super::*;
1230
1231 fn topics(list: &[&str]) -> Result<Vec<String>, String> {
1232 clean_topics(&list.iter().map(|t| t.to_string()).collect::<Vec<_>>())
1233 }
1234
1235 #[test]
1236 fn topics_are_tidied() {
1237 assert_eq!(topics(&["Rust", " web_server ", "rust", ""]).unwrap(), vec!["rust", "web-server"]);
1238 }
1239
1240 #[test]
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1241 fn websites_are_tidied() {
1242 assert_eq!(clean_website(" example.com ").unwrap().as_deref(), Some("https://example.com"));
1243 assert_eq!(clean_website("http://a.io/x").unwrap().as_deref(), Some("http://a.io/x"));
1244 assert_eq!(clean_website("").unwrap(), None);
1245 assert!(clean_website("ftp://a.io").is_err());
1246 assert!(clean_website("localhost").is_err());
1247 assert!(clean_website("https://a b.io").is_err());
1248 }
1249
1250 #[test]
1251 fn branch_names_follow_git() {
1252 for good in ["main", "trunk", "release/1.2", "feat-x_y"] {
1253 assert!(is_valid_branch_name(good), "{good}");
1254 }
1255 for bad in ["", "-x", "a..b", "a b", "x.lock", "a/", ".hidden", "a/.b", "g1t-queue", "a~1", "a:b", "@"] {
1256 assert!(!is_valid_branch_name(bad), "{bad}");
1257 }
1258 }
1259
1260 #[test]
Search across all of g1t, Explore, and a command palette1261 fn odd_topics_are_refused() {
1262 assert!(topics(&["c++"]).is_err());
1263 assert!(topics(&["-lead"]).is_err());
1264 assert!(topics(&[&"a".repeat(36)]).is_err());
1265 let many: Vec<String> = (0..21).map(|i| format!("t{i}")).collect();
1266 assert!(clean_topics(&many).is_err());
1267 }
1268}
Catching up with main takes seconds when the two sides touched different files1269
1270#[cfg(test)]
1271mod tests {
1272 use super::*;
1273
1274 #[test]
1275 fn a_pull_branch_update_reads_as_the_web_expects() {
1276 let update = PullBranchUpdate::NeedsAgent {
1277 reason: NeedsAgentReason::Overlap,
1278 detail: "both".into(),
1279 paths: vec!["a.rs".into()],
1280 };
1281 assert_eq!(
1282 serde_json::to_value(&update).unwrap(),
1283 serde_json::json!({ "outcome": "needs_agent", "reason": "overlap", "detail": "both", "paths": ["a.rs"] })
1284 );
1285 let done = PullBranchUpdate::UpToDate { commit: "c".into() };
1286 assert_eq!(serde_json::to_value(&done).unwrap(), serde_json::json!({ "outcome": "up_to_date", "commit": "c" }));
1287 }
1288}