Skip to content

Commit a15b6dd

Browse files
unhappychoiceclaude
andcommitted
refactor(github): add Entries shape to action_status
Adds `Shape::Entries` to the SHAPES catalog with a status / branch / conclusion rollup. Pairs nicely with `grid_table` for an at-a-glance "why is CI flaky" view that the Badge / Text variants can't carry. Known limitation: the `no runs` branch always returns Badge regardless of `ctx.shape`. Follow-up commit on this branch reconciles that. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 17c687f commit a15b6dd

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

‎src/fetcher/github/action_status.rs‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use async_trait::async_trait;
55
use serde::Deserialize;
66

77
use crate::options::OptionSchema;
8-
use crate::payload::{BadgeData, Body, Payload, Status, TextData};
8+
use crate::payload::{BadgeData, Body, EntriesData, Entry, Payload, Status, TextData};
99
use crate::render::Shape;
1010
use crate::samples;
1111

1212
use super::super::{FetchContext, FetchError, Fetcher, Safety};
1313
use super::client::rest_get;
1414
use super::common::{RepoSlug, cache_key, parse_options, payload, resolve_repo};
1515

16-
const SHAPES: &[Shape] = &[Shape::Badge, Shape::Text];
16+
const SHAPES: &[Shape] = &[Shape::Badge, Shape::Text, Shape::Entries];
1717

1818
const OPTION_SCHEMAS: &[OptionSchema] = &[
1919
OptionSchema {
@@ -74,6 +74,13 @@ impl Fetcher for GithubActionStatus {
7474
Some(match shape {
7575
Shape::Badge => samples::badge(Status::Ok, "ci passing"),
7676
Shape::Text => samples::text("main · passing"),
77+
Shape::Entries => Body::Entries(EntriesData {
78+
items: vec![
79+
entry("status", Some(Status::Ok), "passing"),
80+
entry("branch", None, "main"),
81+
entry("conclusion", None, "success"),
82+
],
83+
}),
7784
_ => return None,
7885
})
7986
}
@@ -119,23 +126,33 @@ struct WorkflowRun {
119126

120127
fn render_body(run: &WorkflowRun, shape: Shape) -> Body {
121128
let (status, label_word) = classify(run);
129+
let branch = run.head_branch.as_deref().unwrap_or("?");
122130
match shape {
123131
Shape::Text => Body::Text(TextData {
124-
value: format!(
125-
"{} · {label_word}",
126-
run.head_branch.as_deref().unwrap_or("?")
127-
),
132+
value: format!("{branch} · {label_word}"),
133+
}),
134+
Shape::Entries => Body::Entries(EntriesData {
135+
items: vec![
136+
entry("status", Some(status), label_word),
137+
entry("branch", None, branch),
138+
entry("conclusion", None, run.conclusion.as_deref().unwrap_or("?")),
139+
],
128140
}),
129141
_ => Body::Badge(BadgeData {
130142
status,
131-
label: format!(
132-
"{} · {label_word}",
133-
run.head_branch.as_deref().unwrap_or("?")
134-
),
143+
label: format!("{branch} · {label_word}"),
135144
}),
136145
}
137146
}
138147

148+
fn entry(key: &str, status: Option<Status>, value: &str) -> Entry {
149+
Entry {
150+
key: key.into(),
151+
value: Some(value.into()),
152+
status,
153+
}
154+
}
155+
139156
fn classify(run: &WorkflowRun) -> (Status, &'static str) {
140157
if run.status == "completed" {
141158
match run.conclusion.as_deref() {
@@ -242,7 +259,13 @@ mod tests {
242259
panic!("expected text sample");
243260
};
244261
assert_eq!(text.value, "main · passing");
245-
assert!(fetcher.sample_body(Shape::Entries).is_none());
262+
263+
let Some(Body::Entries(e)) = fetcher.sample_body(Shape::Entries) else {
264+
panic!("expected entries sample");
265+
};
266+
let keys: Vec<&str> = e.items.iter().map(|i| i.key.as_str()).collect();
267+
assert_eq!(keys, vec!["status", "branch", "conclusion"]);
268+
assert!(fetcher.sample_body(Shape::Timeline).is_none());
246269
}
247270

248271
#[test]

0 commit comments

Comments
 (0)