Mirror of github.com/getsigit/si.
Mirrored from https://github.com/getsigit/si.git
Synced Nov 24, 08:15 UTC
Add si site to publish a repository as a static site
si site view shows the address and state. si site publish starts a publish, and with --wait it polls every two seconds for up to about 90 seconds until the site is live or has failed. A rate-limited publish shows the server's message. si site unpublish takes it offline after a confirmation. The client crate gets site, publish_site and unpublish_site, with the Site type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Seto Elkahfi committed
Oct 28, 2026 at 10:13 UTC
ec293c0a0a94c269a04e127a47cf6bb71471107a
8 files changed
+265
-1
crates/cli/src/cli.rs
+29
@@ -46,6 +46,10 @@ pub enum Command {
46
#[command(subcommand)]
47
Run(RunCommand),
48
49
+ /// Publish a repository's default branch as a static site.
50
+ #[command(subcommand)]
51
+ Site(SiteCommand),
52
+
53
/// Report and read commit statuses, the checks CI shows on a commit.
54
#[command(subcommand)]
55
Status(StatusCommand),
@@ -248,6 +252,31 @@ pub enum RunCommand {
252
Handoff { id: i64 },
253
}
254
255
+#[derive(clap::Subcommand)]
256
+pub enum SiteCommand {
257
+ /// Show a repository's site: its address and whether it is live.
258
+ View {
259
+ #[arg(long)]
260
+ repo: Option<String>,
261
+ },
262
+ /// Publish the default branch, or publish it again.
263
+ Publish {
264
+ /// Wait until the site is live or the publish has failed.
265
+ #[arg(long)]
266
+ wait: bool,
267
+ #[arg(long)]
268
+ repo: Option<String>,
269
+ },
270
+ /// Take the site offline.
271
+ Unpublish {
272
+ #[arg(long)]
273
+ repo: Option<String>,
274
+ /// Skip the confirmation prompt.
275
+ #[arg(short, long)]
276
+ yes: bool,
277
+ },
278
+}
279
+
280
#[derive(clap::Subcommand)]
281
pub enum StatusCommand {
282
/// Report a status on a commit.
crates/cli/src/commands/mod.rs
+1
@@ -10,4 +10,5 @@ pub mod pr;
10
pub mod repo;
11
pub mod run;
12
pub mod session;
13
+pub mod site;
14
pub mod status;
crates/cli/src/commands/site.rs
new
+115
@@ -0,0 +1,115 @@
1
+use {
2
+ crate::{
3
+ cli::SiteCommand,
4
+ context::Ctx,
5
+ ui::{self, prompt},
6
+ },
7
+ anyhow::{anyhow, Result},
8
+ sigit_si_api::models::Site,
9
+ std::time::Duration,
10
+};
11
+
12
+/// How often `publish --wait` asks, and how many times: about 90 seconds.
13
+const POLL_INTERVAL: Duration = Duration::from_secs(2);
14
+const POLL_ATTEMPTS: u32 = 45;
15
+
16
+pub async fn run(ctx: &Ctx, command: SiteCommand) -> Result<()> {
17
+ ctx.require_token()?;
18
+
19
+ match command {
20
+ SiteCommand::View { repo } => view(ctx, repo).await,
21
+ SiteCommand::Publish { wait, repo } => publish(ctx, wait, repo).await,
22
+ SiteCommand::Unpublish { repo, yes } => unpublish(ctx, repo, yes).await,
23
+ }
24
+}
25
+
26
+async fn view(ctx: &Ctx, repo: Option<String>) -> Result<()> {
27
+ let slug = ctx.resolve_repo(repo)?;
28
+ let site = ctx.client.site(&slug.owner, &slug.name).await?;
29
+ ui::emit(ctx.json, &site, ui::render::site)
30
+}
31
+
32
+async fn publish(ctx: &Ctx, wait: bool, repo: Option<String>) -> Result<()> {
33
+ let slug = ctx.resolve_repo(repo)?;
34
+ let mut site = ctx.client.publish_site(&slug.owner, &slug.name).await?;
35
+
36
+ if wait {
37
+ ui::note("Publishing…");
38
+ for _ in 0..POLL_ATTEMPTS {
39
+ if is_settled(&site) {
40
+ break;
41
+ }
42
+ tokio::time::sleep(POLL_INTERVAL).await;
43
+ site = ctx.client.site(&slug.owner, &slug.name).await?;
44
+ }
45
+ if !is_settled(&site) {
46
+ return Err(anyhow!(
47
+ "The site is still publishing. Check on it with `si site view`."
48
+ ));
49
+ }
50
+ }
51
+
52
+ let failed = site.state == "failed";
53
+ ui::emit(ctx.json, &site, |site| {
54
+ if failed {
55
+ ui::render::site(site);
56
+ } else if site.state == "live" {
57
+ ui::success(format!("Published {}.", ui::highlight(&site.url)));
58
+ } else {
59
+ ui::success(format!("Publishing {}.", ui::highlight(&site.url)));
60
+ ui::note("Check on it with `si site view`.");
61
+ }
62
+ })?;
63
+
64
+ if failed {
65
+ return Err(anyhow!(
66
+ "Publishing failed: {}",
67
+ site.error.as_deref().unwrap_or("no reason given.")
68
+ ));
69
+ }
70
+ Ok(())
71
+}
72
+
73
+async fn unpublish(ctx: &Ctx, repo: Option<String>, yes: bool) -> Result<()> {
74
+ let slug = ctx.resolve_repo(repo)?;
75
+ if !yes && !prompt::confirm(&format!("Take the site for {slug} offline?"), false)? {
76
+ ui::note("Cancelled.");
77
+ return Ok(());
78
+ }
79
+
80
+ ctx.client.unpublish_site(&slug.owner, &slug.name).await?;
81
+ ui::success(format!("Taking the site for {slug} offline."));
82
+ Ok(())
83
+}
84
+
85
+fn is_settled(site: &Site) -> bool {
86
+ matches!(site.state.as_str(), "live" | "failed")
87
+}
88
+
89
+#[cfg(test)]
90
+mod tests {
91
+ use super::*;
92
+
93
+ fn site(state: &str) -> Site {
94
+ serde_json::from_value(serde_json::json!({
95
+ "url": "https://demo.example",
96
+ "state": state,
97
+ "error": null,
98
+ "last_published_at": null,
99
+ "files": 0,
100
+ "bytes": 0,
101
+ }))
102
+ .unwrap()
103
+ }
104
+
105
+ #[test]
106
+ fn live_and_failed_end_the_wait() {
107
+ assert!(is_settled(&site("live")));
108
+ assert!(is_settled(&site("failed")));
109
+ }
110
+
111
+ #[test]
112
+ fn publishing_keeps_the_wait_going() {
113
+ assert!(!is_settled(&site("publishing")));
114
+ }
115
+}
crates/cli/src/main.rs
+1
@@ -47,6 +47,7 @@ async fn run() -> Result<()> {
47
Command::Issue(command) => commands::issue::run(&ctx, command).await,
48
Command::Code(command) => commands::code::run(&ctx, command).await,
49
Command::Run(command) => commands::run::run(&ctx, command).await,
50
+ Command::Site(command) => commands::site::run(&ctx, command).await,
51
Command::Status(command) => commands::status::run(&ctx, command).await,
52
Command::Hook(command) => commands::hook::run(&ctx, command).await,
53
Command::Session(command) => commands::session::run(&ctx, command).await,
crates/cli/src/ui/render.rs
+26
-1
@@ -6,7 +6,7 @@ use {
6
console::style,
7
sigit_si_api::models::{
8
AgentRun, Billing, CloudSession, CodeHit, CombinedStatus, Comment, Hook, Issue,
9
- IssueSummary, PullRequest, PullRequestSummary, Repository, RepositorySummary, User,
9
+ IssueSummary, PullRequest, PullRequestSummary, Repository, RepositorySummary, Site, User,
10
},
11
tabled::{builder::Builder, settings::Style},
12
};
@@ -468,6 +468,31 @@ pub fn agent_run_detail(run: &AgentRun) {
468
}
469
}
470
471
+// ── Sites ───────────────────────────────────────────────────────────────────
472
+
473
+pub fn site(site: &Site) {
474
+ let state = match site.state.as_str() {
475
+ "live" => style("live").green().to_string(),
476
+ "failed" => style("failed").red().to_string(),
477
+ "publishing" => style("publishing").yellow().to_string(),
478
+ other => style(other).dim().to_string(),
479
+ };
480
+ println!();
481
+ println!(" {} {}", highlight(&site.url), state);
482
+ field("Error", site.error.as_deref());
483
+ field(
484
+ "Published",
485
+ site.last_published_at.map(relative_time).as_deref(),
486
+ );
487
+ if site.files > 0 {
488
+ field(
489
+ "Size",
490
+ Some(&format!("{} files, {} bytes", site.files, site.bytes)),
491
+ );
492
+ }
493
+ println!();
494
+}
495
+
496
// ── Billing ─────────────────────────────────────────────────────────────────
497
498
pub fn billing(billing: &Billing) {
crates/sigit-si-api/src/lib.rs
+2
@@ -56,6 +56,8 @@ pub mod repos;
56
#[cfg(feature = "client")]
57
pub mod sessions;
58
#[cfg(feature = "client")]
59
+pub mod sites;
60
+#[cfg(feature = "client")]
61
pub mod statuses;
62
63
/// Request header a client uses to name itself. [`client::ClientBuilder::client_name`]
crates/sigit-si-api/src/models.rs
+16
@@ -194,6 +194,22 @@ pub struct AgentRun {
194
pub transcript_tail: Option<String>,
195
}
196
197
+// ── Sites ───────────────────────────────────────────────────────────────────
198
+
199
+/// A repository's published static site.
200
+#[derive(Debug, Clone, Deserialize, Serialize)]
201
+pub struct Site {
202
+ pub url: String,
203
+ /// `publishing`, `live` or `failed`.
204
+ pub state: String,
205
+ pub error: Option<String>,
206
+ pub last_published_at: Option<DateTime<Utc>>,
207
+ #[serde(default)]
208
+ pub files: i64,
209
+ #[serde(default)]
210
+ pub bytes: i64,
211
+}
212
+
213
// ── MCP-backed resources ────────────────────────────────────────────────────
214
//
215
// Issues, pull requests, and code search have no REST surface; they are served
crates/sigit-si-api/src/sites.rs
new
+75
@@ -0,0 +1,75 @@
1
+//! A repository's default branch, published as a static site.
2
+
3
+use {
4
+ crate::{client::Client, error::Result, models::Site},
5
+ reqwest::{Method, RequestBuilder},
6
+};
7
+
8
+impl Client {
9
+ /// `GET /api/v1/repos/:owner/:repo/site` — `404` when the repository has no
10
+ /// site.
11
+ pub async fn site(&self, owner: &str, repo: &str) -> Result<Site> {
12
+ self.get(&site_path(owner, repo)).await
13
+ }
14
+
15
+ /// `POST /api/v1/repos/:owner/:repo/site` — publishes the site, or
16
+ /// publishes it again. Owner only. Publishing runs in the background, so
17
+ /// the answer has state `publishing`; poll [`Client::site`] for `live` or
18
+ /// `failed`. Publishing too often answers `429`.
19
+ pub async fn publish_site(&self, owner: &str, repo: &str) -> Result<Site> {
20
+ self.send(self.publish_site_request(owner, repo)).await
21
+ }
22
+
23
+ /// `DELETE /api/v1/repos/:owner/:repo/site` — takes the site offline. The
24
+ /// server does it in the background.
25
+ pub async fn unpublish_site(&self, owner: &str, repo: &str) -> Result<()> {
26
+ self.delete(&site_path(owner, repo)).await
27
+ }
28
+
29
+ fn publish_site_request(&self, owner: &str, repo: &str) -> RequestBuilder {
30
+ self.request(Method::POST, &site_path(owner, repo))
31
+ .json(&serde_json::json!({}))
32
+ }
33
+}
34
+
35
+fn site_path(owner: &str, repo: &str) -> String {
36
+ format!("repos/{owner}/{repo}/site")
37
+}
38
+
39
+#[cfg(test)]
40
+mod tests {
41
+ use {super::*, crate::Environment};
42
+
43
+ #[test]
44
+ fn publishing_posts_to_the_site_path() {
45
+ let client = Client::builder(Environment::Production)
46
+ .base_url("https://sigit.si")
47
+ .token("tok")
48
+ .build()
49
+ .unwrap();
50
+ let request = client.publish_site_request("seto", "demo").build().unwrap();
51
+
52
+ assert_eq!(request.method(), Method::POST);
53
+ assert_eq!(
54
+ request.url().as_str(),
55
+ "https://sigit.si/api/v1/repos/seto/demo/site"
56
+ );
57
+ }
58
+
59
+ #[test]
60
+ fn a_site_parses() {
61
+ let body = r#"{"url":"https://demo.example","state":"live","error":null,
62
+ "last_published_at":"2026-10-01T10:00:00Z","files":4,"bytes":2048}"#;
63
+ let site: Site = serde_json::from_str(body).unwrap();
64
+ assert_eq!(site.state, "live");
65
+ assert_eq!(site.files, 4);
66
+ }
67
+
68
+ #[test]
69
+ fn a_site_still_publishing_has_no_timestamp_yet() {
70
+ let body = r#"{"url":"https://demo.example","state":"publishing","error":null,
71
+ "last_published_at":null,"files":0,"bytes":0}"#;
72
+ let site: Site = serde_json::from_str(body).unwrap();
73
+ assert!(site.last_published_at.is_none());
74
+ }
75
+}