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 GithubReviewRequests {
5448 60 * 5
5549 }
5650 fn shapes ( & self ) -> & [ Shape ] {
57- SHAPES
51+ LIST_SHAPES
5852 }
5953 fn option_schemas ( & self ) -> & [ OptionSchema ] {
6054 OPTION_SCHEMAS
@@ -63,39 +57,23 @@ impl Fetcher for GithubReviewRequests {
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- "ratatui/ratatui#1234 feat: add pie chart" ,
70- Some ( "https://github.com/ratatui/ratatui/pull/1234" ) ,
71- ) ,
72- (
73- "tokio-rs/tokio#5678 fix: race in spawn" ,
74- Some ( "https://github.com/tokio-rs/tokio/pull/5678" ) ,
75- ) ,
76- ] ) ,
77- Shape :: TextBlock => samples:: text_block ( & [
78- "ratatui/ratatui#1234 feat: add pie chart" ,
79- "tokio-rs/tokio#5678 fix: race in spawn" ,
80- ] ) ,
81- Shape :: Entries => samples:: entries ( & [
82- ( "ratatui #1234" , "feat: add pie chart" ) ,
83- ( "tokio #5678" , "fix: race in spawn" ) ,
84- ] ) ,
85- Shape :: Timeline => samples:: timeline ( & [
86- (
87- 1_774_000_000 ,
88- "ratatui/ratatui#1234" ,
89- Some ( "feat: add pie chart" ) ,
90- ) ,
91- (
92- 1_773_800_000 ,
93- "tokio-rs/tokio#5678" ,
94- Some ( "fix: race in spawn" ) ,
95- ) ,
96- ] ) ,
97- _ => return None ,
98- } )
60+ let rows = sample_rows ( & [
61+ (
62+ "ratatui/ratatui#1234" ,
63+ "feat: add pie chart" ,
64+ Some ( "https://github.com/ratatui/ratatui/pull/1234" ) ,
65+ 5 ,
66+ 1_774_000_000 ,
67+ ) ,
68+ (
69+ "tokio-rs/tokio#5678" ,
70+ "fix: race in spawn" ,
71+ Some ( "https://github.com/tokio-rs/tokio/pull/5678" ) ,
72+ 2 ,
73+ 1_773_800_000 ,
74+ ) ,
75+ ] ) ;
76+ forge_items:: dispatch_sample ( & rows, shape, "to review" , "to review" )
9977 }
10078 async fn fetch ( & self , ctx : & FetchContext ) -> Result < Payload , FetchError > {
10179 let opts: Options = parse_options ( ctx. options . as_ref ( ) ) . map_err ( FetchError :: Failed ) ?;
@@ -104,11 +82,10 @@ impl Fetcher for GithubReviewRequests {
10482 "/search/issues?q=is%3Apr+is%3Aopen+review-requested%3A%40me&per_page={limit}&sort=updated"
10583 ) ;
10684 let res: SearchResult = rest_get ( & path) . await ?;
107- Ok ( payload ( render_items (
108- & res. items ,
109- ctx. shape . unwrap_or ( Shape :: LinkedTextBlock ) ,
110- true ,
111- ) ) )
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, "to review" , "to review" ) . await ;
88+ Ok ( payload ( body) )
11289 }
11390}
11491
@@ -201,12 +178,19 @@ mod tests {
201178 assert_eq ! ( fetcher. name( ) , "github_review_requests" ) ;
202179 assert_eq ! ( fetcher. safety( ) , Safety :: Safe ) ;
203180 assert ! ( fetcher. description( ) . contains( "requested reviewer" ) ) ;
204- assert_eq ! ( fetcher. shapes( ) , SHAPES ) ;
181+ assert_eq ! ( fetcher. shapes( ) , LIST_SHAPES ) ;
205182 assert_eq ! ( fetcher. default_shape( ) , Shape :: LinkedTextBlock ) ;
206183 assert_eq ! ( fetcher. option_schemas( ) . len( ) , 1 ) ;
207184 assert_eq ! ( fetcher. option_schemas( ) [ 0 ] . name, "limit" ) ;
208185 assert_eq ! ( fetcher. option_schemas( ) [ 0 ] . default , Some ( "10" ) ) ;
209186
187+ for shape in LIST_SHAPES {
188+ assert ! (
189+ fetcher. sample_body( * shape) . is_some( ) ,
190+ "missing sample for {shape:?}"
191+ ) ;
192+ }
193+
210194 let Some ( Body :: LinkedTextBlock ( linked) ) = fetcher. sample_body ( Shape :: LinkedTextBlock )
211195 else {
212196 panic ! ( "expected linked text block sample" ) ;
@@ -220,29 +204,10 @@ mod tests {
220204 Some ( "https://github.com/tokio-rs/tokio/pull/5678" )
221205 ) ;
222206
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 ] , "tokio-rs/tokio#5678 fix: race in spawn" ) ;
227-
228207 let Some ( Body :: Entries ( entries) ) = fetcher. sample_body ( Shape :: Entries ) else {
229208 panic ! ( "expected entries sample" ) ;
230209 } ;
231- assert_eq ! ( entries. items[ 0 ] . key, "ratatui #1234" ) ;
232- assert_eq ! (
233- entries. items[ 1 ] . value. as_deref( ) ,
234- Some ( "fix: race in spawn" )
235- ) ;
236-
237- let Some ( Body :: Timeline ( timeline) ) = fetcher. sample_body ( Shape :: Timeline ) else {
238- panic ! ( "expected timeline sample" ) ;
239- } ;
240- assert_eq ! ( timeline. events[ 0 ] . title, "ratatui/ratatui#1234" ) ;
241- assert_eq ! (
242- timeline. events[ 1 ] . detail. as_deref( ) ,
243- Some ( "fix: race in spawn" )
244- ) ;
245- assert ! ( fetcher. sample_body( Shape :: Text ) . is_none( ) ) ;
210+ assert_eq ! ( entries. items[ 0 ] . key, "ratatui/ratatui#1234" ) ;
246211 }
247212
248213 #[ test]
0 commit comments