44use async_trait:: async_trait;
55use serde:: Deserialize ;
66
7+ use crate :: fetcher:: forge_items:: { self , LIST_SHAPES } ;
78use crate :: options:: OptionSchema ;
89use crate :: payload:: { Body , Payload } ;
910use crate :: render:: Shape ;
10- use crate :: samples;
1111
1212use super :: super :: { FetchContext , FetchError , Fetcher , Safety } ;
1313use super :: client:: rest_get;
1414use super :: common:: { cache_key, parse_options, payload} ;
15- use super :: items:: { SearchResult , render_items } ;
15+ use super :: items:: { SearchResult , sample_rows , to_forge_rows } ;
1616
17- const SHAPES : & [ Shape ] = & [
18- Shape :: LinkedTextBlock ,
19- Shape :: TextBlock ,
20- Shape :: Entries ,
21- Shape :: Timeline ,
22- ] ;
2317const DEFAULT_LIMIT : u32 = 10 ;
2418
2519const OPTION_SCHEMAS : & [ OptionSchema ] = & [ OptionSchema {
@@ -54,7 +48,7 @@ impl Fetcher for GithubAssignedIssues {
5448 60 * 10
5549 }
5650 fn shapes ( & self ) -> & [ Shape ] {
57- SHAPES
51+ LIST_SHAPES
5852 }
5953 fn option_schemas ( & self ) -> & [ OptionSchema ] {
6054 OPTION_SCHEMAS
@@ -63,35 +57,23 @@ impl Fetcher for GithubAssignedIssues {
6357 cache_key ( self . name ( ) , ctx, "" )
6458 }
6559 fn sample_body ( & self , shape : Shape ) -> Option < Body > {
66- Some ( match shape {
67- Shape :: LinkedTextBlock => samples:: linked_text_block ( & [
68- (
69- "unhappychoice/splashboard#41 meta: widget catalog & roadmap" ,
70- Some ( "https://github.com/unhappychoice/splashboard/issues/41" ) ,
71- ) ,
72- (
73- "unhappychoice/splashboard#17 theme system" ,
74- Some ( "https://github.com/unhappychoice/splashboard/issues/17" ) ,
75- ) ,
76- ] ) ,
77- Shape :: TextBlock => samples:: text_block ( & [
78- "unhappychoice/splashboard#41 meta: widget catalog & roadmap" ,
79- "unhappychoice/splashboard#17 theme system" ,
80- ] ) ,
81- Shape :: Entries => samples:: entries ( & [
82- ( "splashboard #41" , "meta: widget catalog" ) ,
83- ( "splashboard #17" , "theme system" ) ,
84- ] ) ,
85- Shape :: Timeline => samples:: timeline ( & [
86- (
87- 1_774_000_000 ,
88- "splashboard#41" ,
89- Some ( "meta: widget catalog" ) ,
90- ) ,
91- ( 1_773_500_000 , "splashboard#17" , Some ( "theme system" ) ) ,
92- ] ) ,
93- _ => return None ,
94- } )
60+ let rows = sample_rows ( & [
61+ (
62+ "unhappychoice/splashboard#41" ,
63+ "meta: widget catalog & roadmap" ,
64+ Some ( "https://github.com/unhappychoice/splashboard/issues/41" ) ,
65+ 3 ,
66+ 1_774_000_000 ,
67+ ) ,
68+ (
69+ "unhappychoice/splashboard#17" ,
70+ "theme system" ,
71+ Some ( "https://github.com/unhappychoice/splashboard/issues/17" ) ,
72+ 1 ,
73+ 1_773_500_000 ,
74+ ) ,
75+ ] ) ;
76+ forge_items:: dispatch_sample ( & rows, shape, "open issue" , "open issues" )
9577 }
9678 async fn fetch ( & self , ctx : & FetchContext ) -> Result < Payload , FetchError > {
9779 let opts: Options = parse_options ( ctx. options . as_ref ( ) ) . map_err ( FetchError :: Failed ) ?;
@@ -100,11 +82,10 @@ impl Fetcher for GithubAssignedIssues {
10082 "/search/issues?q=is%3Aissue+is%3Aopen+assignee%3A%40me&per_page={limit}&sort=updated"
10183 ) ;
10284 let res: SearchResult = rest_get ( & path) . await ?;
103- Ok ( payload ( render_items (
104- & res. items ,
105- ctx. shape . unwrap_or ( Shape :: LinkedTextBlock ) ,
106- true ,
107- ) ) )
85+ let rows = to_forge_rows ( & res. items , true ) ;
86+ let shape = ctx. shape . unwrap_or ( Shape :: LinkedTextBlock ) ;
87+ let body = forge_items:: dispatch_rows_async ( rows, shape, "open issue" , "open issues" ) . await ;
88+ Ok ( payload ( body) )
10889 }
10990}
11091
@@ -201,12 +182,19 @@ mod tests {
201182 . description( )
202183 . contains( "assigned to the authenticated user" )
203184 ) ;
204- assert_eq ! ( fetcher. shapes( ) , SHAPES ) ;
185+ assert_eq ! ( fetcher. shapes( ) , LIST_SHAPES ) ;
205186 assert_eq ! ( fetcher. default_shape( ) , Shape :: LinkedTextBlock ) ;
206187 assert_eq ! ( fetcher. option_schemas( ) . len( ) , 1 ) ;
207188 assert_eq ! ( fetcher. option_schemas( ) [ 0 ] . name, "limit" ) ;
208189 assert_eq ! ( fetcher. option_schemas( ) [ 0 ] . default , Some ( "10" ) ) ;
209190
191+ for shape in LIST_SHAPES {
192+ assert ! (
193+ fetcher. sample_body( * shape) . is_some( ) ,
194+ "missing sample for {shape:?}"
195+ ) ;
196+ }
197+
210198 let Some ( Body :: LinkedTextBlock ( linked) ) = fetcher. sample_body ( Shape :: LinkedTextBlock )
211199 else {
212200 panic ! ( "expected linked text block sample" ) ;
@@ -220,23 +208,10 @@ mod tests {
220208 Some ( "https://github.com/unhappychoice/splashboard/issues/17" )
221209 ) ;
222210
223- let Some ( Body :: TextBlock ( text) ) = fetcher. sample_body ( Shape :: TextBlock ) else {
224- panic ! ( "expected text block sample" ) ;
225- } ;
226- assert_eq ! ( text. lines[ 1 ] , "unhappychoice/splashboard#17 theme system" ) ;
227-
228211 let Some ( Body :: Entries ( entries) ) = fetcher. sample_body ( Shape :: Entries ) else {
229212 panic ! ( "expected entries sample" ) ;
230213 } ;
231- assert_eq ! ( entries. items[ 0 ] . key, "splashboard #41" ) ;
232- assert_eq ! ( entries. items[ 1 ] . value. as_deref( ) , Some ( "theme system" ) ) ;
233-
234- let Some ( Body :: Timeline ( timeline) ) = fetcher. sample_body ( Shape :: Timeline ) else {
235- panic ! ( "expected timeline sample" ) ;
236- } ;
237- assert_eq ! ( timeline. events[ 0 ] . title, "splashboard#41" ) ;
238- assert_eq ! ( timeline. events[ 1 ] . detail. as_deref( ) , Some ( "theme system" ) ) ;
239- assert ! ( fetcher. sample_body( Shape :: Text ) . is_none( ) ) ;
214+ assert_eq ! ( entries. items[ 0 ] . key, "unhappychoice/splashboard#41" ) ;
240215 }
241216
242217 #[ test]
0 commit comments