Skip to content

Commit 97a493a

Browse files
unhappychoiceclaude
andcommitted
fix(fetcher): preserve requested shape in gitlab_pipeline_status no-runs path
Same shape-consistency fix as the github_action_status sibling: when the `pipelines` list comes back empty the fetcher used to always emit a `Body::Badge`, dropping the shape advertised in `ctx.shape`. Extract a `no_runs_body(shape)` helper so Text and Entries consumers keep the right variant. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent e2bc30a commit 97a493a

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

‎src/fetcher/gitlab/pipeline_status.rs‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,32 @@ impl Fetcher for GitlabPipelineStatus {
106106
let pipelines: Vec<Pipeline> = rest_get(&host, &path).await?;
107107
let shape = ctx.shape.unwrap_or(Shape::Badge);
108108
let Some(latest) = pipelines.into_iter().next() else {
109-
return Ok(payload(Body::Badge(BadgeData {
110-
status: Status::Warn,
111-
label: "no runs".into(),
112-
})));
109+
return Ok(payload(no_runs_body(shape)));
113110
};
114111
Ok(payload(render_body(&latest, shape)))
115112
}
116113
}
117114

115+
fn no_runs_body(shape: Shape) -> Body {
116+
match shape {
117+
Shape::Text => Body::Text(TextData {
118+
value: "no runs".into(),
119+
}),
120+
Shape::Entries => Body::Entries(EntriesData {
121+
items: vec![
122+
entry("status", Some(Status::Warn), "no runs"),
123+
entry("branch", None, "?"),
124+
entry("sha", None, "?"),
125+
entry("duration", None, "?"),
126+
],
127+
}),
128+
_ => Body::Badge(BadgeData {
129+
status: Status::Warn,
130+
label: "no runs".into(),
131+
}),
132+
}
133+
}
134+
118135
#[derive(Debug, Deserialize)]
119136
struct Pipeline {
120137
#[serde(default)]
@@ -315,6 +332,26 @@ mod tests {
315332
assert_eq!(format_duration(None), "?");
316333
}
317334

335+
#[test]
336+
fn no_runs_body_respects_each_advertised_shape() {
337+
// Empty pipeline list used to always degrade to Badge regardless of `ctx.shape`,
338+
// breaking shape consistency for Text / Entries consumers.
339+
let Body::Badge(b) = no_runs_body(Shape::Badge) else {
340+
panic!("expected badge");
341+
};
342+
assert_eq!(b.label, "no runs");
343+
let Body::Text(t) = no_runs_body(Shape::Text) else {
344+
panic!("expected text");
345+
};
346+
assert_eq!(t.value, "no runs");
347+
let Body::Entries(e) = no_runs_body(Shape::Entries) else {
348+
panic!("expected entries");
349+
};
350+
assert_eq!(e.items.len(), 4);
351+
assert_eq!(e.items[0].value.as_deref(), Some("no runs"));
352+
assert_eq!(e.items[0].status, Some(Status::Warn));
353+
}
354+
318355
#[test]
319356
fn sample_entries_carries_the_four_rollup_rows() {
320357
let Some(Body::Entries(e)) = GitlabPipelineStatus.sample_body(Shape::Entries) else {

0 commit comments

Comments
 (0)