Skip to content

Commit e2bc30a

Browse files
unhappychoiceclaude
andcommitted
fix(fetcher): preserve requested shape in github_action_status no-runs path
`github_action_status` advertises Badge / Text / Entries, but when the `workflow_runs` list came back empty the fetcher always returned a `Body::Badge` with `"no runs"`, regardless of `ctx.shape`. Consumers asking for Text or Entries got a shape mismatch and the runtime fell through to the placeholder. Extract a `no_runs_body(shape)` helper that mirrors the populated `render_body` shape selection so each advertised shape stays consistent across the "have runs" and "no runs" branches. Adds a unit test covering all three shapes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 9ede219 commit e2bc30a

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

‎src/fetcher/github/action_status.rs‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,30 @@ impl Fetcher for GithubActionStatus {
9595
path.push_str(&format!("&branch={branch}"));
9696
}
9797
let res: RunsResponse = rest_get(&path).await?;
98+
let shape = ctx.shape.unwrap_or(Shape::Badge);
9899
let Some(run) = res.workflow_runs.into_iter().next() else {
99-
return Ok(payload(Body::Badge(BadgeData {
100-
status: Status::Warn,
101-
label: "no runs".into(),
102-
})));
100+
return Ok(payload(no_runs_body(shape)));
103101
};
104-
Ok(payload(render_body(
105-
&run,
106-
ctx.shape.unwrap_or(Shape::Badge),
107-
)))
102+
Ok(payload(render_body(&run, shape)))
103+
}
104+
}
105+
106+
fn no_runs_body(shape: Shape) -> Body {
107+
match shape {
108+
Shape::Text => Body::Text(TextData {
109+
value: "no runs".into(),
110+
}),
111+
Shape::Entries => Body::Entries(EntriesData {
112+
items: vec![
113+
entry("status", Some(Status::Warn), "no runs"),
114+
entry("branch", None, "?"),
115+
entry("conclusion", None, "?"),
116+
],
117+
}),
118+
_ => Body::Badge(BadgeData {
119+
status: Status::Warn,
120+
label: "no runs".into(),
121+
}),
108122
}
109123
}
110124

@@ -335,6 +349,25 @@ mod tests {
335349
assert_eq!(badge.label, "main · cancelled");
336350
}
337351

352+
#[test]
353+
fn no_runs_body_respects_each_advertised_shape() {
354+
// Empty workflow_runs used to always degrade to Badge regardless of `ctx.shape`,
355+
// breaking shape consistency once Entries was advertised in #243.
356+
let Body::Badge(b) = no_runs_body(Shape::Badge) else {
357+
panic!("expected badge");
358+
};
359+
assert_eq!(b.label, "no runs");
360+
let Body::Text(t) = no_runs_body(Shape::Text) else {
361+
panic!("expected text");
362+
};
363+
assert_eq!(t.value, "no runs");
364+
let Body::Entries(e) = no_runs_body(Shape::Entries) else {
365+
panic!("expected entries");
366+
};
367+
assert_eq!(e.items[0].value.as_deref(), Some("no runs"));
368+
assert_eq!(e.items[0].status, Some(Status::Warn));
369+
}
370+
338371
#[test]
339372
fn render_text_falls_back_to_question_mark_for_missing_branch() {
340373
let body = render_body(

0 commit comments

Comments
 (0)