Skip to content

Commit a7f6c17

Browse files
unhappychoiceclaude
andcommitted
refactor(github): extend repo_prs to 9 shapes via forge_items dispatch
Same migration as the user-scope fetchers, but with `include_repo = false` so the row label stays the bare `#54` rather than the full `#54`. Badge noun pair is ("open PR", "open PRs"). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent e6c4a47 commit a7f6c17

1 file changed

Lines changed: 32 additions & 63 deletions

File tree

‎src/fetcher/github/repo_prs.rs‎

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44
use async_trait::async_trait;
55
use serde::Deserialize;
66

7+
use crate::fetcher::forge_items::{self, LIST_SHAPES};
78
use crate::options::OptionSchema;
89
use crate::payload::{Body, Payload};
910
use crate::render::Shape;
10-
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};
15-
use super::items::{IssueItem, render_items};
15+
use super::items::{IssueItem, sample_rows, to_forge_rows};
1616

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

2519
const OPTION_SCHEMAS: &[OptionSchema] = &[
@@ -65,7 +59,7 @@ impl Fetcher for GithubRepoPrs {
6559
60 * 10
6660
}
6761
fn shapes(&self) -> &[Shape] {
68-
SHAPES
62+
LIST_SHAPES
6963
}
7064
fn option_schemas(&self) -> &[OptionSchema] {
7165
OPTION_SCHEMAS
@@ -75,35 +69,23 @@ impl Fetcher for GithubRepoPrs {
7569
cache_key(self.name(), ctx, &extra)
7670
}
7771
fn sample_body(&self, shape: Shape) -> Option<Body> {
78-
Some(match shape {
79-
Shape::LinkedTextBlock => samples::linked_text_block(&[
80-
(
81-
"#54 feat(docs): generate widget catalogue",
82-
Some("https://github.com/unhappychoice/splashboard/pull/54"),
83-
),
84-
(
85-
"#51 feat(fetcher): split clock options",
86-
Some("https://github.com/unhappychoice/splashboard/pull/51"),
87-
),
88-
]),
89-
Shape::TextBlock => samples::text_block(&[
90-
"#54 feat(docs): generate widget catalogue",
91-
"#51 feat(fetcher): split clock options",
92-
]),
93-
Shape::Entries => samples::entries(&[
94-
("#54", "feat(docs): widget catalogue"),
95-
("#51", "feat(fetcher): split clock options"),
96-
]),
97-
Shape::Timeline => samples::timeline(&[
98-
(1_774_000_000, "#54", Some("feat(docs): widget catalogue")),
99-
(
100-
1_773_800_000,
101-
"#51",
102-
Some("feat(fetcher): split clock options"),
103-
),
104-
]),
105-
_ => return None,
106-
})
72+
let rows = sample_rows(&[
73+
(
74+
"#54",
75+
"feat(docs): generate widget catalogue",
76+
Some("https://github.com/unhappychoice/splashboard/pull/54"),
77+
7,
78+
1_774_000_000,
79+
),
80+
(
81+
"#51",
82+
"feat(fetcher): split clock options",
83+
Some("https://github.com/unhappychoice/splashboard/pull/51"),
84+
2,
85+
1_773_800_000,
86+
),
87+
]);
88+
forge_items::dispatch_sample(&rows, shape, "open PR", "open PRs")
10789
}
10890
async fn fetch(&self, ctx: &FetchContext) -> Result<Payload, FetchError> {
10991
let opts: Options = parse_options(ctx.options.as_ref()).map_err(FetchError::Failed)?;
@@ -114,11 +96,10 @@ impl Fetcher for GithubRepoPrs {
11496
slug.owner, slug.name
11597
);
11698
let items: Vec<IssueItem> = rest_get(&path).await?;
117-
Ok(payload(render_items(
118-
&items,
119-
ctx.shape.unwrap_or(Shape::LinkedTextBlock),
120-
false,
121-
)))
99+
let rows = to_forge_rows(&items, false);
100+
let shape = ctx.shape.unwrap_or(Shape::LinkedTextBlock);
101+
let body = forge_items::dispatch_rows_async(rows, shape, "open PR", "open PRs").await;
102+
Ok(payload(body))
122103
}
123104
}
124105

@@ -224,11 +205,18 @@ mod tests {
224205
assert_eq!(fetcher.name(), "github_repo_prs");
225206
assert_eq!(fetcher.safety(), Safety::Safe);
226207
assert!(fetcher.description().contains("target repo"));
227-
assert_eq!(fetcher.shapes(), SHAPES);
208+
assert_eq!(fetcher.shapes(), LIST_SHAPES);
228209
assert_eq!(fetcher.option_schemas().len(), 2);
229210
assert_eq!(fetcher.option_schemas()[0].name, "repo");
230211
assert_eq!(fetcher.option_schemas()[1].name, "limit");
231212

213+
for shape in LIST_SHAPES {
214+
assert!(
215+
fetcher.sample_body(*shape).is_some(),
216+
"missing sample for {shape:?}"
217+
);
218+
}
219+
232220
let Some(Body::LinkedTextBlock(linked)) = fetcher.sample_body(Shape::LinkedTextBlock)
233221
else {
234222
panic!("expected linked text block sample");
@@ -242,29 +230,10 @@ mod tests {
242230
Some("https://github.com/unhappychoice/splashboard/pull/51")
243231
);
244232

245-
let Some(Body::TextBlock(text)) = fetcher.sample_body(Shape::TextBlock) else {
246-
panic!("expected text block sample");
247-
};
248-
assert_eq!(text.lines[1], "#51 feat(fetcher): split clock options");
249-
250233
let Some(Body::Entries(entries)) = fetcher.sample_body(Shape::Entries) else {
251234
panic!("expected entries sample");
252235
};
253236
assert_eq!(entries.items[0].key, "#54");
254-
assert_eq!(
255-
entries.items[1].value.as_deref(),
256-
Some("feat(fetcher): split clock options")
257-
);
258-
259-
let Some(Body::Timeline(timeline)) = fetcher.sample_body(Shape::Timeline) else {
260-
panic!("expected timeline sample");
261-
};
262-
assert_eq!(timeline.events[0].title, "#54");
263-
assert_eq!(
264-
timeline.events[1].detail.as_deref(),
265-
Some("feat(fetcher): split clock options")
266-
);
267-
assert!(fetcher.sample_body(Shape::Text).is_none());
268237
}
269238

270239
#[test]

0 commit comments

Comments
 (0)