@@ -64,14 +64,15 @@ pub(super) async fn handle_command(
64
64
start_date. checked_add_signed ( Duration :: days ( 10 ) ) . unwrap ( ) ;
65
65
66
66
let mut current: BTreeMap < String , Option < UserStatus > > = BTreeMap :: new ( ) ;
67
- let history: BTreeMap < String , Vec < UserStatus > > = BTreeMap :: new ( ) ;
67
+ let mut history: BTreeMap < String , Vec < UserStatus > > = BTreeMap :: new ( ) ;
68
68
69
69
// TODO
70
70
// change this to be entered by the user as part of the command
71
71
// it should match the same team that we check for above when determining if the user is a member
72
72
let team = github:: get_team ( & ctx. github , & "T-lang" ) . await ?. unwrap ( ) ;
73
73
for member in team. members {
74
- current. insert ( member. name , None ) ;
74
+ current. insert ( member. name . clone ( ) , None ) ;
75
+ history. insert ( member. name . clone ( ) , Vec :: new ( ) ) ;
75
76
}
76
77
77
78
current. insert (
@@ -128,25 +129,24 @@ fn build_status_comment(
128
129
current : & BTreeMap < String , Option < UserStatus > > ,
129
130
) -> anyhow:: Result < String > {
130
131
let mut comment = "| Team member | State |\n |-------------|-------|" . to_owned ( ) ;
131
- for ( user, statuses ) in history {
132
+ for ( user, status ) in current {
132
133
let mut user_statuses = format ! ( "\n | {} |" , user) ;
133
134
134
135
// previous stasuses
135
- for status in statuses {
136
- let status_item = format ! ( " ~~{}~~ " , status. resolution) ;
137
- user_statuses. push_str ( & status_item) ;
136
+ match history. get ( user) {
137
+ Some ( statuses) => {
138
+ for status in statuses {
139
+ let status_item = format ! ( " ~~{}~~ " , status. resolution) ;
140
+ user_statuses. push_str ( & status_item) ;
141
+ }
142
+ }
143
+ None => bail ! ( "user {} not present in history statuses list" , user) ,
138
144
}
139
145
140
146
// current status
141
- let user_resolution = match current. get ( user) {
142
- Some ( current_status) => {
143
- if let Some ( status) = current_status {
144
- format ! ( "**{}**" , status. resolution)
145
- } else {
146
- "" . to_string ( )
147
- }
148
- }
149
- None => bail ! ( "user {} not present in current statuses list" , user) ,
147
+ let user_resolution = match status {
148
+ Some ( status) => format ! ( "**{}**" , status. resolution) ,
149
+ _ => "" . to_string ( ) ,
150
150
} ;
151
151
152
152
let status_item = format ! ( " {} |" , user_resolution) ;
@@ -276,7 +276,40 @@ mod tests {
276
276
let build_result = build_status_comment ( & history, & current_statuses) ;
277
277
assert_eq ! (
278
278
format!( "{}" , build_result. unwrap_err( ) ) ,
279
- "user Barbara not present in current statuses list"
279
+ "user Martin not present in history statuses list"
280
280
) ;
281
281
}
282
+
283
+ #[ test]
284
+ fn test_successfuly_build_comment_no_history ( ) {
285
+ let mut history: BTreeMap < String , Vec < UserStatus > > = BTreeMap :: new ( ) ;
286
+ let mut current_statuses: BTreeMap < String , Option < UserStatus > > = BTreeMap :: new ( ) ;
287
+
288
+ // user 1
289
+ let mut user_1_statuses: Vec < UserStatus > = Vec :: new ( ) ;
290
+ user_1_statuses. push ( create ! ( UserStatus ) ) ;
291
+ user_1_statuses. push ( create ! ( UserStatus , : hold) ) ;
292
+
293
+ current_statuses. insert ( "Niklaus" . to_string ( ) , Some ( create ! ( UserStatus ) ) ) ;
294
+ history. insert ( "Niklaus" . to_string ( ) , Vec :: new ( ) ) ;
295
+
296
+ // user 2
297
+ let mut user_2_statuses: Vec < UserStatus > = Vec :: new ( ) ;
298
+ user_2_statuses. push ( create ! ( UserStatus , : hold) ) ;
299
+ user_2_statuses. push ( create ! ( UserStatus ) ) ;
300
+
301
+ current_statuses. insert ( "Barbara" . to_string ( ) , Some ( create ! ( UserStatus ) ) ) ;
302
+ history. insert ( "Barbara" . to_string ( ) , Vec :: new ( ) ) ;
303
+
304
+ let build_result = build_status_comment ( & history, & current_statuses)
305
+ . expect ( "it shouldn't fail building the message" ) ;
306
+ let expected_comment = "| Team member | State |\n \
307
+ |-------------|-------|\n \
308
+ | Barbara | **merge** |\n \
309
+ | Niklaus | **merge** |\
310
+ "
311
+ . to_string ( ) ;
312
+
313
+ assert_eq ! ( build_result, expected_comment) ;
314
+ }
282
315
}
0 commit comments