Skip to content

Commit 0543473

Browse files
unhappychoiceclaude
andcommitted
refactor(github): extend my_prs to 9 shapes via forge_items dispatch
Replaces the local 4-element SHAPES const with the shared `LIST_SHAPES` (LinkedTextBlock / TextBlock / MarkdownTextBlock / ImageLinkedList / Entries / Text / Bars / Badge / Timeline). `fetch` routes through `forge_items::dispatch_rows_async` so `ImageLinkedList` resolves author avatars through the thumbnails cache and `Badge` produces the `"N open PRs"` count-pill. Entries key convention changes from "splashboard #54" to "#54" so the row label stays consistent across every shape variant. Repo-scope fetchers (which already used `#54`) are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent d87ecf1 commit 0543473

1 file changed

Lines changed: 37 additions & 67 deletions

File tree

‎src/fetcher/github/my_prs.rs‎

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
use async_trait::async_trait;
66
use serde::Deserialize;
77

8+
use crate::fetcher::forge_items::{self, LIST_SHAPES};
89
use crate::options::OptionSchema;
910
use crate::payload::{Body, Payload};
1011
use crate::render::Shape;
11-
use crate::samples;
1212

1313
use super::super::{FetchContext, FetchError, Fetcher, Safety};
1414
use super::client::rest_get;
1515
use super::common::{cache_key, parse_options, payload};
16-
use super::items::{SearchResult, render_items};
16+
use super::items::{SearchResult, sample_rows, to_forge_rows};
1717

18-
const SHAPES: &[Shape] = &[
19-
Shape::LinkedTextBlock,
20-
Shape::TextBlock,
21-
Shape::Entries,
22-
Shape::Timeline,
23-
];
2418
const DEFAULT_LIMIT: u32 = 10;
2519

2620
const OPTION_SCHEMAS: &[OptionSchema] = &[OptionSchema {
@@ -55,7 +49,7 @@ impl Fetcher for GithubMyPrs {
5549
60 * 5
5650
}
5751
fn shapes(&self) -> &[Shape] {
58-
SHAPES
52+
LIST_SHAPES
5953
}
6054
fn option_schemas(&self) -> &[OptionSchema] {
6155
OPTION_SCHEMAS
@@ -64,39 +58,23 @@ impl Fetcher for GithubMyPrs {
6458
cache_key(self.name(), ctx, "")
6559
}
6660
fn sample_body(&self, shape: Shape) -> Option<Body> {
67-
Some(match shape {
68-
Shape::LinkedTextBlock => samples::linked_text_block(&[
69-
(
70-
"unhappychoice/splashboard#54 feat(docs): generate widget catalogue",
71-
Some("https://github.com/unhappychoice/splashboard/pull/54"),
72-
),
73-
(
74-
"unhappychoice/splashboard#51 feat(fetcher): split clock options",
75-
Some("https://github.com/unhappychoice/splashboard/pull/51"),
76-
),
77-
]),
78-
Shape::TextBlock => samples::text_block(&[
79-
"unhappychoice/splashboard#54 feat(docs): generate widget catalogue",
80-
"unhappychoice/splashboard#51 feat(fetcher): split clock options",
81-
]),
82-
Shape::Entries => samples::entries(&[
83-
("splashboard #54", "feat(docs): widget catalogue"),
84-
("splashboard #51", "feat(fetcher): split clock options"),
85-
]),
86-
Shape::Timeline => samples::timeline(&[
87-
(
88-
1_774_000_000,
89-
"splashboard#54",
90-
Some("feat(docs): widget catalogue"),
91-
),
92-
(
93-
1_773_800_000,
94-
"splashboard#51",
95-
Some("feat(fetcher): split clock options"),
96-
),
97-
]),
98-
_ => return None,
99-
})
61+
let rows = sample_rows(&[
62+
(
63+
"unhappychoice/splashboard#54",
64+
"feat(docs): generate widget catalogue",
65+
Some("https://github.com/unhappychoice/splashboard/pull/54"),
66+
7,
67+
1_774_000_000,
68+
),
69+
(
70+
"unhappychoice/splashboard#51",
71+
"feat(fetcher): split clock options",
72+
Some("https://github.com/unhappychoice/splashboard/pull/51"),
73+
2,
74+
1_773_800_000,
75+
),
76+
]);
77+
forge_items::dispatch_sample(&rows, shape, "open PR", "open PRs")
10078
}
10179
async fn fetch(&self, ctx: &FetchContext) -> Result<Payload, FetchError> {
10280
let opts: Options = parse_options(ctx.options.as_ref()).map_err(FetchError::Failed)?;
@@ -105,11 +83,10 @@ impl Fetcher for GithubMyPrs {
10583
"/search/issues?q=is%3Apr+is%3Aopen+author%3A%40me&per_page={limit}&sort=updated"
10684
);
10785
let res: SearchResult = rest_get(&path).await?;
108-
Ok(payload(render_items(
109-
&res.items,
110-
ctx.shape.unwrap_or(Shape::LinkedTextBlock),
111-
true,
112-
)))
86+
let rows = to_forge_rows(&res.items, true);
87+
let shape = ctx.shape.unwrap_or(Shape::LinkedTextBlock);
88+
let body = forge_items::dispatch_rows_async(rows, shape, "open PR", "open PRs").await;
89+
Ok(payload(body))
11390
}
11491
}
11592

@@ -203,12 +180,22 @@ mod tests {
203180
assert_eq!(fetcher.name(), "github_my_prs");
204181
assert_eq!(fetcher.safety(), Safety::Safe);
205182
assert!(fetcher.description().contains("authenticated user"));
206-
assert_eq!(fetcher.shapes(), SHAPES);
183+
assert_eq!(fetcher.shapes(), LIST_SHAPES);
207184
assert_eq!(fetcher.option_schemas().len(), 1);
208185
assert_eq!(fetcher.option_schemas()[0].name, "limit");
209186
assert_eq!(fetcher.option_schemas()[0].default, Some("10"));
210187
assert_eq!(fetcher.default_shape(), Shape::LinkedTextBlock);
211188

189+
// Every shape in LIST_SHAPES gets a sample so the docs / catalog generators don't
190+
// have to special-case the user-scope fetchers.
191+
for shape in LIST_SHAPES {
192+
assert!(
193+
fetcher.sample_body(*shape).is_some(),
194+
"missing sample for {shape:?}"
195+
);
196+
}
197+
assert!(fetcher.sample_body(Shape::Ratio).is_none());
198+
212199
let Some(Body::LinkedTextBlock(linked)) = fetcher.sample_body(Shape::LinkedTextBlock)
213200
else {
214201
panic!("expected linked text block sample");
@@ -222,32 +209,15 @@ mod tests {
222209
Some("https://github.com/unhappychoice/splashboard/pull/51")
223210
);
224211

225-
let Some(Body::TextBlock(text)) = fetcher.sample_body(Shape::TextBlock) else {
226-
panic!("expected text block sample");
227-
};
228-
assert_eq!(
229-
text.lines[1],
230-
"unhappychoice/splashboard#51 feat(fetcher): split clock options"
231-
);
232-
233212
let Some(Body::Entries(entries)) = fetcher.sample_body(Shape::Entries) else {
234213
panic!("expected entries sample");
235214
};
236-
assert_eq!(entries.items[0].key, "splashboard #54");
237-
assert_eq!(
238-
entries.items[1].value.as_deref(),
239-
Some("feat(fetcher): split clock options")
240-
);
215+
assert_eq!(entries.items[0].key, "unhappychoice/splashboard#54");
241216

242217
let Some(Body::Timeline(timeline)) = fetcher.sample_body(Shape::Timeline) else {
243218
panic!("expected timeline sample");
244219
};
245-
assert_eq!(timeline.events[0].title, "splashboard#54");
246-
assert_eq!(
247-
timeline.events[1].detail.as_deref(),
248-
Some("feat(fetcher): split clock options")
249-
);
250-
assert!(fetcher.sample_body(Shape::Text).is_none());
220+
assert_eq!(timeline.events[0].title, "unhappychoice/splashboard#54");
251221
}
252222

253223
#[test]

0 commit comments

Comments
 (0)