@@ -3,10 +3,16 @@ use std::fmt;
33use anyhow:: Context as AnyhowContext ;
44use async_graphql:: {
55 connection:: { query, Connection , EmptyFields } ,
6- Context , Object , Result , SimpleObject ,
6+ scalar , Context , Object , Result , SimpleObject ,
77} ;
88
9- use crate :: database:: { self , Database , TryFromKeyValue } ;
9+ use crate :: {
10+ database:: { self , Database , TryFromKeyValue } ,
11+ github:: { issues:: IssueState , GitHubIssue } ,
12+ graphql:: DateTimeUtc ,
13+ } ;
14+
15+ scalar ! ( IssueState ) ;
1016
1117#[ derive( SimpleObject ) ]
1218pub ( crate ) struct Issue {
@@ -15,19 +21,32 @@ pub(crate) struct Issue {
1521 pub ( crate ) number : i32 ,
1622 pub ( crate ) title : String ,
1723 pub ( crate ) author : String ,
24+ pub ( crate ) created_at : DateTimeUtc ,
25+ pub ( crate ) state : IssueState ,
26+ pub ( crate ) assignees : Vec < String > ,
1827}
1928
2029impl TryFromKeyValue for Issue {
2130 fn try_from_key_value ( key : & [ u8 ] , value : & [ u8 ] ) -> anyhow:: Result < Self > {
2231 let ( owner, repo, number) = database:: parse_key ( key)
2332 . with_context ( || format ! ( "invalid key in database: {key:02x?}" ) ) ?;
24- let ( title, author, _) = bincode:: deserialize :: < ( String , String , Option < String > ) > ( value) ?;
33+ let GitHubIssue {
34+ title,
35+ author,
36+ created_at,
37+ state,
38+ assignees,
39+ ..
40+ } = bincode:: deserialize :: < GitHubIssue > ( value) ?;
2541 let issue = Issue {
2642 title,
2743 author,
2844 owner,
2945 repo,
3046 number : i32:: try_from ( number) . unwrap_or ( i32:: MAX ) ,
47+ created_at : DateTimeUtc ( created_at) ,
48+ state,
49+ assignees,
3150 } ;
3251 Ok ( issue)
3352 }
@@ -69,6 +88,15 @@ impl IssueQuery {
6988mod tests {
7089 use crate :: { github:: GitHubIssue , graphql:: TestSchema } ;
7190
91+ fn create_issues ( n : usize ) -> Vec < GitHubIssue > {
92+ ( 1 ..=n)
93+ . map ( |i| GitHubIssue {
94+ number : i64:: try_from ( i) . unwrap ( ) ,
95+ ..Default :: default ( )
96+ } )
97+ . collect ( )
98+ }
99+
72100 #[ tokio:: test]
73101 async fn issues_empty ( ) {
74102 let schema = TestSchema :: new ( ) ;
@@ -89,26 +117,7 @@ mod tests {
89117 #[ tokio:: test]
90118 async fn issues_first ( ) {
91119 let schema = TestSchema :: new ( ) ;
92- let issues = vec ! [
93- GitHubIssue {
94- number: 1 ,
95- title: "issue 1" . to_string( ) ,
96- author: "author 1" . to_string( ) ,
97- closed_at: None ,
98- } ,
99- GitHubIssue {
100- number: 2 ,
101- title: "issue 2" . to_string( ) ,
102- author: "author 2" . to_string( ) ,
103- closed_at: None ,
104- } ,
105- GitHubIssue {
106- number: 3 ,
107- title: "issue 3" . to_string( ) ,
108- author: "author 3" . to_string( ) ,
109- closed_at: None ,
110- } ,
111- ] ;
120+ let issues = create_issues ( 3 ) ;
112121 schema. db . insert_issues ( issues, "owner" , "name" ) . unwrap ( ) ;
113122
114123 let query = r"
@@ -148,26 +157,7 @@ mod tests {
148157 #[ tokio:: test]
149158 async fn issues_last ( ) {
150159 let schema = TestSchema :: new ( ) ;
151- let issues = vec ! [
152- GitHubIssue {
153- number: 1 ,
154- title: "issue 1" . to_string( ) ,
155- author: "author 1" . to_string( ) ,
156- closed_at: None ,
157- } ,
158- GitHubIssue {
159- number: 2 ,
160- title: "issue 2" . to_string( ) ,
161- author: "author 2" . to_string( ) ,
162- closed_at: None ,
163- } ,
164- GitHubIssue {
165- number: 3 ,
166- title: "issue 3" . to_string( ) ,
167- author: "author 3" . to_string( ) ,
168- closed_at: None ,
169- } ,
170- ] ;
160+ let issues = create_issues ( 3 ) ;
171161 schema. db . insert_issues ( issues, "owner" , "name" ) . unwrap ( ) ;
172162
173163 let query = r"
0 commit comments