Mirror of github.com/getsigit/si.
Mirrored from https://github.com/getsigit/si.git
Synced Nov 24, 08:15 UTC
Add si status set and view for commit statuses
si status set reports pending, success, failure or error for a check on a commit, so CI can fill the checks tab. si status view shows the combined state and each check. Both take a SHA or any ref in the current clone, and view defaults to HEAD. The client crate gets create_status and combined_status, with the CommitStatus and CombinedStatus wire types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Seto Elkahfi committed
Oct 28, 2026 at 10:12 UTC
0cf62210fdd9c570f8e18fd3db00be245735fb0d
9 files changed
+371
-2
crates/cli/src/cli.rs
+32
@@ -42,6 +42,10 @@ pub enum Command {
42
#[command(subcommand)]
43
Code(CodeCommand),
44
45
+ /// Report and read commit statuses, the checks CI shows on a commit.
46
+ #[command(subcommand)]
47
+ Status(StatusCommand),
48
+
49
/// Manage a repository's deploy webhooks.
50
#[command(subcommand)]
51
Hook(HookCommand),
@@ -218,6 +222,34 @@ pub enum CodeCommand {
222
},
223
}
224
225
+#[derive(clap::Subcommand)]
226
+pub enum StatusCommand {
227
+ /// Report a status on a commit.
228
+ Set {
229
+ /// A commit SHA, or a branch, tag or other ref in the current repo.
230
+ sha: String,
231
+ #[arg(long, value_parser = ["pending", "success", "failure", "error"])]
232
+ state: String,
233
+ /// Which check this is, such as ci/test. Defaults to "default".
234
+ #[arg(long)]
235
+ context: Option<String>,
236
+ #[arg(long)]
237
+ description: Option<String>,
238
+ /// Where to see the details, such as a CI run.
239
+ #[arg(long)]
240
+ url: Option<String>,
241
+ #[arg(long)]
242
+ repo: Option<String>,
243
+ },
244
+ /// Show the combined status of a commit and each check behind it.
245
+ View {
246
+ /// A commit SHA or ref. Defaults to HEAD.
247
+ sha: Option<String>,
248
+ #[arg(long)]
249
+ repo: Option<String>,
250
+ },
251
+}
252
+
253
#[derive(clap::Subcommand)]
254
pub enum HookCommand {
255
/// List a repository's webhooks.
crates/cli/src/commands/mod.rs
+1
@@ -9,3 +9,4 @@ pub mod me;
9
pub mod pr;
10
pub mod repo;
11
pub mod session;
12
+pub mod status;
crates/cli/src/commands/status.rs
new
+68
@@ -0,0 +1,68 @@
1
+use {
2
+ crate::{cli::StatusCommand, context::Ctx, git, ui},
3
+ anyhow::{Context, Result},
4
+ sigit_si_api::NewStatus,
5
+};
6
+
7
+pub async fn run(ctx: &Ctx, command: StatusCommand) -> Result<()> {
8
+ ctx.require_token()?;
9
+
10
+ match command {
11
+ StatusCommand::Set {
12
+ sha,
13
+ state,
14
+ context,
15
+ description,
16
+ url,
17
+ repo,
18
+ } => set(ctx, sha, state, context, description, url, repo).await,
19
+ StatusCommand::View { sha, repo } => view(ctx, sha, repo).await,
20
+ }
21
+}
22
+
23
+fn resolve(rev: &str) -> Result<String> {
24
+ let cwd = std::env::current_dir().context("Could not read the current directory.")?;
25
+ git::resolve_sha(&cwd, rev)
26
+}
27
+
28
+async fn set(
29
+ ctx: &Ctx,
30
+ rev: String,
31
+ state: String,
32
+ context: Option<String>,
33
+ description: Option<String>,
34
+ url: Option<String>,
35
+ repo: Option<String>,
36
+) -> Result<()> {
37
+ let slug = ctx.resolve_repo(repo)?;
38
+ let sha = resolve(&rev)?;
39
+
40
+ let status = NewStatus::new(state)
41
+ .context(context)
42
+ .description(description)
43
+ .target_url(url);
44
+ let created = ctx
45
+ .client
46
+ .create_status(&slug.owner, &slug.name, &sha, &status)
47
+ .await?;
48
+
49
+ ui::emit(ctx.json, &created, |created| {
50
+ ui::success(format!(
51
+ "Reported {} for {} on {}.",
52
+ created.state,
53
+ ui::highlight(&created.context),
54
+ &created.sha[..created.sha.len().min(12)]
55
+ ));
56
+ })
57
+}
58
+
59
+async fn view(ctx: &Ctx, rev: Option<String>, repo: Option<String>) -> Result<()> {
60
+ let slug = ctx.resolve_repo(repo)?;
61
+ let sha = resolve(rev.as_deref().unwrap_or("HEAD"))?;
62
+
63
+ let combined = ctx
64
+ .client
65
+ .combined_status(&slug.owner, &slug.name, &sha)
66
+ .await?;
67
+ ui::emit(ctx.json, &combined, ui::render::combined_status)
68
+}
crates/cli/src/git.rs
+51
@@ -86,6 +86,29 @@ pub fn current_branch(dir: &Path) -> Option<String> {
86
head.shorthand().map(str::to_string)
87
}
88
89
+/// Resolve a ref (or `HEAD`) in the repository around `dir` to a full commit
90
+/// SHA. A full SHA that this checkout doesn't have is passed through, since
91
+/// the commit may only exist on the server.
92
+pub fn resolve_sha(dir: &Path, rev: &str) -> Result<String> {
93
+ let found = GitRepository::discover(dir).ok().and_then(|repository| {
94
+ let object = repository.revparse_single(rev).ok()?;
95
+ Some(object.peel_to_commit().ok()?.id().to_string())
96
+ });
97
+
98
+ match found {
99
+ Some(sha) => Ok(sha),
100
+ None if is_full_sha(rev) => Ok(rev.to_ascii_lowercase()),
101
+ None => Err(anyhow!(
102
+ "Could not resolve {rev:?} to a commit. Run this inside a clone of the repository, \
103
+ or pass the full commit SHA."
104
+ )),
105
+ }
106
+}
107
+
108
+fn is_full_sha(text: &str) -> bool {
109
+ text.len() == 40 && text.chars().all(|c| c.is_ascii_hexdigit())
110
+}
111
+
112
/// `origin` first, then `sigit`, then the rest in their configured order.
113
fn preferred_order(names: &[String]) -> Vec<String> {
114
let mut ordered = Vec::with_capacity(names.len());
@@ -220,6 +243,34 @@ mod tests {
243
assert_eq!(slug.to_string(), "seto/demo");
244
}
245
246
+ #[test]
247
+ fn a_ref_resolves_to_its_commit() {
248
+ let dir = tempfile::tempdir().unwrap();
249
+ let repository = GitRepository::init(dir.path()).unwrap();
250
+ let signature = git2::Signature::now("t", "t@example.com").unwrap();
251
+ let tree = repository
252
+ .find_tree(repository.treebuilder(None).unwrap().write().unwrap())
253
+ .unwrap();
254
+ let id = repository
255
+ .commit(Some("HEAD"), &signature, &signature, "init", &tree, &[])
256
+ .unwrap();
257
+
258
+ assert_eq!(resolve_sha(dir.path(), "HEAD").unwrap(), id.to_string());
259
+ }
260
+
261
+ #[test]
262
+ fn an_unknown_full_sha_is_passed_through() {
263
+ let dir = tempfile::tempdir().unwrap();
264
+ let sha = "A".repeat(40);
265
+ assert_eq!(resolve_sha(dir.path(), &sha).unwrap(), "a".repeat(40));
266
+ }
267
+
268
+ #[test]
269
+ fn an_unknown_ref_is_an_error() {
270
+ let dir = tempfile::tempdir().unwrap();
271
+ assert!(resolve_sha(dir.path(), "main").is_err());
272
+ }
273
+
274
#[test]
275
fn origin_is_tried_before_other_remotes() {
276
let names = vec!["upstream".to_string(), "origin".to_string()];
crates/cli/src/main.rs
+1
@@ -46,6 +46,7 @@ async fn run() -> Result<()> {
46
Command::Pr(command) => commands::pr::run(&ctx, command).await,
47
Command::Issue(command) => commands::issue::run(&ctx, command).await,
48
Command::Code(command) => commands::code::run(&ctx, command).await,
49
+ Command::Status(command) => commands::status::run(&ctx, command).await,
50
Command::Hook(command) => commands::hook::run(&ctx, command).await,
51
Command::Session(command) => commands::session::run(&ctx, command).await,
52
Command::Billing(command) => commands::billing::run(&ctx, command).await,
crates/cli/src/ui/render.rs
+43
-2
@@ -3,9 +3,10 @@
3
4
use {
5
super::{bold, dim, highlight, relative_time, state_badge},
6
+ console::style,
7
sigit_si_api::models::{
7
- Billing, CloudSession, CodeHit, Comment, Hook, Issue, IssueSummary, PullRequest,
8
- PullRequestSummary, Repository, RepositorySummary, User,
8
+ Billing, CloudSession, CodeHit, CombinedStatus, Comment, Hook, Issue, IssueSummary,
9
+ PullRequest, PullRequestSummary, Repository, RepositorySummary, User,
10
},
11
tabled::{builder::Builder, settings::Style},
12
};
@@ -360,6 +361,46 @@ pub fn session_detail(session: &CloudSession) {
361
}
362
}
363
364
+// ── Commit statuses ─────────────────────────────────────────────────────────
365
+
366
+fn status_badge(state: &str) -> String {
367
+ match state {
368
+ "success" => style("success").green().to_string(),
369
+ "failure" | "error" => style(state).red().to_string(),
370
+ "pending" => style("pending").yellow().to_string(),
371
+ other => style(other).dim().to_string(),
372
+ }
373
+}
374
+
375
+pub fn combined_status(combined: &CombinedStatus) {
376
+ println!();
377
+ println!(
378
+ " {} {}",
379
+ highlight(&combined.sha[..combined.sha.len().min(12)]),
380
+ status_badge(&combined.state)
381
+ );
382
+ println!();
383
+
384
+ let rows = combined
385
+ .statuses
386
+ .iter()
387
+ .map(|status| {
388
+ vec![
389
+ status.context.clone(),
390
+ status_badge(&status.state),
391
+ truncate(status.description.as_deref().unwrap_or("—"), 48),
392
+ relative_time(status.updated_at),
393
+ ]
394
+ })
395
+ .collect();
396
+
397
+ table(
398
+ &["Check", "State", "Description", "Updated"],
399
+ rows,
400
+ "No statuses have been reported on this commit.",
401
+ );
402
+}
403
+
404
// ── Billing ─────────────────────────────────────────────────────────────────
405
406
pub fn billing(billing: &Billing) {
crates/sigit-si-api/src/lib.rs
+3
@@ -53,6 +53,8 @@ pub mod pulls;
53
pub mod repos;
54
#[cfg(feature = "client")]
55
pub mod sessions;
56
+#[cfg(feature = "client")]
57
+pub mod statuses;
58
59
/// Request header a client uses to name itself. [`client::ClientBuilder::client_name`]
60
/// sends it on every request.
@@ -66,4 +68,5 @@ pub use {
68
error::{ApiError, Result},
69
issues::State,
70
repos::NewRepository,
71
+ statuses::NewStatus,
72
};
crates/sigit-si-api/src/models.rs
+27
@@ -139,6 +139,33 @@ pub struct GitCredential {
139
pub expires_at: DateTime<Utc>,
140
}
141
142
+// ── Commit statuses ─────────────────────────────────────────────────────────
143
+
144
+/// One reported status on a commit, from `POST …/statuses/:sha` and the
145
+/// `statuses` list of the combined status.
146
+#[derive(Debug, Clone, Deserialize, Serialize)]
147
+pub struct CommitStatus {
148
+ pub id: i64,
149
+ pub sha: String,
150
+ /// `pending`, `success`, `failure` or `error`.
151
+ pub state: String,
152
+ pub context: String,
153
+ pub description: Option<String>,
154
+ pub target_url: Option<String>,
155
+ pub created_at: DateTime<Utc>,
156
+ pub updated_at: DateTime<Utc>,
157
+}
158
+
159
+/// `GET …/commits/:sha/status` — every context on a commit and the state they
160
+/// add up to.
161
+#[derive(Debug, Clone, Deserialize, Serialize)]
162
+pub struct CombinedStatus {
163
+ pub sha: String,
164
+ pub state: String,
165
+ pub total_count: u32,
166
+ pub statuses: Vec<CommitStatus>,
167
+}
168
+
169
// ── MCP-backed resources ────────────────────────────────────────────────────
170
//
171
// Issues, pull requests, and code search have no REST surface; they are served
crates/sigit-si-api/src/statuses.rs
new
+145
@@ -0,0 +1,145 @@
1
+//! Commit statuses — how CI reports pass or fail onto a commit.
2
+
3
+use {
4
+ crate::{
5
+ client::Client,
6
+ error::Result,
7
+ models::{CombinedStatus, CommitStatus},
8
+ },
9
+ reqwest::{Method, RequestBuilder},
10
+};
11
+
12
+/// Fields accepted by `POST /api/v1/repos/:owner/:repo/statuses/:sha`.
13
+#[derive(Debug, Clone, serde::Serialize)]
14
+pub struct NewStatus {
15
+ /// `pending`, `success`, `failure` or `error`.
16
+ pub state: String,
17
+ /// Which check this is. The server uses `default` when it is left out.
18
+ #[serde(skip_serializing_if = "Option::is_none")]
19
+ pub context: Option<String>,
20
+ #[serde(skip_serializing_if = "Option::is_none")]
21
+ pub description: Option<String>,
22
+ #[serde(skip_serializing_if = "Option::is_none")]
23
+ pub target_url: Option<String>,
24
+}
25
+
26
+impl NewStatus {
27
+ pub fn new(state: impl Into<String>) -> Self {
28
+ Self {
29
+ state: state.into(),
30
+ context: None,
31
+ description: None,
32
+ target_url: None,
33
+ }
34
+ }
35
+
36
+ pub fn context(mut self, context: Option<String>) -> Self {
37
+ self.context = context.filter(|c| !c.trim().is_empty());
38
+ self
39
+ }
40
+
41
+ pub fn description(mut self, description: Option<String>) -> Self {
42
+ self.description = description.filter(|d| !d.trim().is_empty());
43
+ self
44
+ }
45
+
46
+ pub fn target_url(mut self, target_url: Option<String>) -> Self {
47
+ self.target_url = target_url.filter(|u| !u.trim().is_empty());
48
+ self
49
+ }
50
+}
51
+
52
+impl Client {
53
+ /// `POST /api/v1/repos/:owner/:repo/statuses/:sha` — report a status on a
54
+ /// commit. Owner only. Reporting the same context again replaces it.
55
+ pub async fn create_status(
56
+ &self,
57
+ owner: &str,
58
+ repo: &str,
59
+ sha: &str,
60
+ status: &NewStatus,
61
+ ) -> Result<CommitStatus> {
62
+ self.send(self.create_status_request(owner, repo, sha, status))
63
+ .await
64
+ }
65
+
66
+ /// `GET /api/v1/repos/:owner/:repo/commits/:sha/status` — the combined
67
+ /// state of a commit and every context behind it.
68
+ pub async fn combined_status(
69
+ &self,
70
+ owner: &str,
71
+ repo: &str,
72
+ sha: &str,
73
+ ) -> Result<CombinedStatus> {
74
+ self.get(&format!("repos/{owner}/{repo}/commits/{sha}/status"))
75
+ .await
76
+ }
77
+
78
+ fn create_status_request(
79
+ &self,
80
+ owner: &str,
81
+ repo: &str,
82
+ sha: &str,
83
+ status: &NewStatus,
84
+ ) -> RequestBuilder {
85
+ self.request(
86
+ Method::POST,
87
+ &format!("repos/{owner}/{repo}/statuses/{sha}"),
88
+ )
89
+ .json(status)
90
+ }
91
+}
92
+
93
+#[cfg(test)]
94
+mod tests {
95
+ use {super::*, crate::Environment};
96
+
97
+ fn client() -> Client {
98
+ Client::builder(Environment::Production)
99
+ .base_url("https://sigit.si")
100
+ .token("tok")
101
+ .build()
102
+ .unwrap()
103
+ }
104
+
105
+ #[test]
106
+ fn a_status_is_posted_to_the_commit() {
107
+ let status = NewStatus::new("success").context(Some("ci/test".into()));
108
+ let request = client()
109
+ .create_status_request("seto", "demo", "abc123", &status)
110
+ .build()
111
+ .unwrap();
112
+
113
+ assert_eq!(request.method(), Method::POST);
114
+ assert_eq!(
115
+ request.url().as_str(),
116
+ "https://sigit.si/api/v1/repos/seto/demo/statuses/abc123"
117
+ );
118
+ let body = request.body().and_then(|b| b.as_bytes()).unwrap();
119
+ let body: serde_json::Value = serde_json::from_slice(body).unwrap();
120
+ assert_eq!(body["state"], "success");
121
+ assert_eq!(body["context"], "ci/test");
122
+ assert!(body.get("description").is_none());
123
+ assert!(body.get("target_url").is_none());
124
+ }
125
+
126
+ #[test]
127
+ fn blank_optional_fields_are_left_out() {
128
+ let status = NewStatus::new("pending")
129
+ .context(Some(" ".into()))
130
+ .description(Some(String::new()))
131
+ .target_url(None);
132
+ let json = serde_json::to_value(&status).unwrap();
133
+ assert_eq!(json, serde_json::json!({ "state": "pending" }));
134
+ }
135
+
136
+ #[test]
137
+ fn a_combined_status_parses() {
138
+ let body = r#"{"sha":"abc","state":"success","total_count":1,"statuses":[
139
+ {"id":1,"sha":"abc","state":"success","context":"ci","description":null,
140
+ "target_url":null,"created_at":"2026-10-01T10:00:00Z","updated_at":"2026-10-01T10:00:00Z"}]}"#;
141
+ let combined: CombinedStatus = serde_json::from_str(body).unwrap();
142
+ assert_eq!(combined.total_count, 1);
143
+ assert_eq!(combined.statuses[0].context, "ci");
144
+ }
145
+}