Skip to content

Commit 7eed488

Browse files
unhappychoiceclaude
andcommitted
refactor(github): extend repo_issues to 9 shapes via forge_items dispatch
Same migration as `github_repo_prs`. Pull-request filtering in the fetch path is unchanged; the conversion happens after the filter, so the rows the renderer sees are still pure issues. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent a7f6c17 commit 7eed488

1 file changed

Lines changed: 34 additions & 53 deletions

File tree

‎src/fetcher/github/repo_issues.rs‎

Lines changed: 34 additions & 53 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 GithubRepoIssues {
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,29 +69,23 @@ impl Fetcher for GithubRepoIssues {
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-
"#41 meta: widget catalog & roadmap",
82-
Some("https://github.com/unhappychoice/splashboard/issues/41"),
83-
),
84-
(
85-
"#17 theme system",
86-
Some("https://github.com/unhappychoice/splashboard/issues/17"),
87-
),
88-
]),
89-
Shape::TextBlock => {
90-
samples::text_block(&["#41 meta: widget catalog & roadmap", "#17 theme system"])
91-
}
92-
Shape::Entries => {
93-
samples::entries(&[("#41", "meta: widget catalog"), ("#17", "theme system")])
94-
}
95-
Shape::Timeline => samples::timeline(&[
96-
(1_774_000_000, "#41", Some("meta: widget catalog")),
97-
(1_773_500_000, "#17", Some("theme system")),
98-
]),
99-
_ => return None,
100-
})
72+
let rows = sample_rows(&[
73+
(
74+
"#41",
75+
"meta: widget catalog & roadmap",
76+
Some("https://github.com/unhappychoice/splashboard/issues/41"),
77+
3,
78+
1_774_000_000,
79+
),
80+
(
81+
"#17",
82+
"theme system",
83+
Some("https://github.com/unhappychoice/splashboard/issues/17"),
84+
1,
85+
1_773_500_000,
86+
),
87+
]);
88+
forge_items::dispatch_sample(&rows, shape, "open issue", "open issues")
10189
}
10290
async fn fetch(&self, ctx: &FetchContext) -> Result<Payload, FetchError> {
10391
let opts: Options = parse_options(ctx.options.as_ref()).map_err(FetchError::Failed)?;
@@ -118,11 +106,10 @@ impl Fetcher for GithubRepoIssues {
118106
.take(limit as usize)
119107
.map(|i| i.inner)
120108
.collect();
121-
Ok(payload(render_items(
122-
&issues,
123-
ctx.shape.unwrap_or(Shape::LinkedTextBlock),
124-
false,
125-
)))
109+
let rows = to_forge_rows(&issues, false);
110+
let shape = ctx.shape.unwrap_or(Shape::LinkedTextBlock);
111+
let body = forge_items::dispatch_rows_async(rows, shape, "open issue", "open issues").await;
112+
Ok(payload(body))
126113
}
127114
}
128115

@@ -236,11 +223,18 @@ mod tests {
236223
assert_eq!(fetcher.name(), "github_repo_issues");
237224
assert_eq!(fetcher.safety(), Safety::Safe);
238225
assert!(fetcher.description().contains("pull requests filtered out"));
239-
assert_eq!(fetcher.shapes(), SHAPES);
226+
assert_eq!(fetcher.shapes(), LIST_SHAPES);
240227
assert_eq!(fetcher.option_schemas().len(), 2);
241228
assert_eq!(fetcher.option_schemas()[0].name, "repo");
242229
assert_eq!(fetcher.option_schemas()[1].name, "limit");
243230

231+
for shape in LIST_SHAPES {
232+
assert!(
233+
fetcher.sample_body(*shape).is_some(),
234+
"missing sample for {shape:?}"
235+
);
236+
}
237+
244238
let Some(Body::LinkedTextBlock(linked)) = fetcher.sample_body(Shape::LinkedTextBlock)
245239
else {
246240
panic!("expected linked text block sample");
@@ -251,23 +245,10 @@ mod tests {
251245
Some("https://github.com/unhappychoice/splashboard/issues/17")
252246
);
253247

254-
let Some(Body::TextBlock(text)) = fetcher.sample_body(Shape::TextBlock) else {
255-
panic!("expected text block sample");
256-
};
257-
assert_eq!(text.lines[1], "#17 theme system");
258-
259248
let Some(Body::Entries(entries)) = fetcher.sample_body(Shape::Entries) else {
260249
panic!("expected entries sample");
261250
};
262251
assert_eq!(entries.items[0].key, "#41");
263-
assert_eq!(entries.items[1].value.as_deref(), Some("theme system"));
264-
265-
let Some(Body::Timeline(timeline)) = fetcher.sample_body(Shape::Timeline) else {
266-
panic!("expected timeline sample");
267-
};
268-
assert_eq!(timeline.events[0].title, "#41");
269-
assert_eq!(timeline.events[1].detail.as_deref(), Some("theme system"));
270-
assert!(fetcher.sample_body(Shape::Text).is_none());
271252
}
272253

273254
#[test]
@@ -295,8 +276,8 @@ mod tests {
295276
.filter(|item| item.pull_request.is_none())
296277
.map(|item| item.inner)
297278
.collect();
298-
299-
let Body::TextBlock(text) = render_items(&issues, Shape::TextBlock, false) else {
279+
let rows = to_forge_rows(&issues, false);
280+
let Body::TextBlock(text) = forge_items::render_forge_rows(&rows, Shape::TextBlock) else {
300281
panic!("expected text block");
301282
};
302283
assert_eq!(text.lines, vec!["#41 Keep real issues"]);

0 commit comments

Comments
 (0)