11use std:: collections:: { HashMap , HashSet } ;
22
33use super :: {
4- Category , Comment , CommentStatus , MergeReadiness , ReviewSummary , ReviewVerificationState ,
5- ReviewVerificationSummary , Severity ,
4+ Category , Comment , CommentStatus , MergeReadiness , ReviewCompletenessSummary , ReviewSummary ,
5+ ReviewVerificationState , ReviewVerificationSummary , Severity ,
66} ;
77
88pub ( super ) fn generate_summary ( comments : & [ Comment ] ) -> ReviewSummary {
@@ -65,6 +65,12 @@ pub(super) fn generate_summary(comments: &[Comment]) -> ReviewSummary {
6565 resolved_comments,
6666 dismissed_comments,
6767 open_blockers,
68+ completeness : build_completeness_summary (
69+ comments. len ( ) ,
70+ resolved_comments,
71+ dismissed_comments,
72+ 0 ,
73+ ) ,
6874 merge_readiness : default_merge_readiness ( open_blockers) ,
6975 verification : ReviewVerificationSummary :: default ( ) ,
7076 readiness_reasons : Vec :: new ( ) ,
@@ -93,6 +99,17 @@ pub(super) fn apply_review_runtime_state(
9399 mut summary : ReviewSummary ,
94100 stale_review : bool ,
95101) -> ReviewSummary {
102+ summary. completeness = build_completeness_summary (
103+ summary. total_comments ,
104+ summary. resolved_comments ,
105+ summary. dismissed_comments ,
106+ if stale_review {
107+ summary. open_comments
108+ } else {
109+ 0
110+ } ,
111+ ) ;
112+
96113 let mut reasons = Vec :: new ( ) ;
97114 if matches ! (
98115 summary. verification. state,
@@ -112,6 +129,20 @@ pub(super) fn apply_review_runtime_state(
112129 summary
113130}
114131
132+ fn build_completeness_summary (
133+ total_findings : usize ,
134+ resolved_comments : usize ,
135+ dismissed_comments : usize ,
136+ stale_findings : usize ,
137+ ) -> ReviewCompletenessSummary {
138+ ReviewCompletenessSummary {
139+ total_findings,
140+ acknowledged_findings : resolved_comments + dismissed_comments,
141+ fixed_findings : resolved_comments,
142+ stale_findings,
143+ }
144+ }
145+
115146fn default_merge_readiness ( open_blockers : usize ) -> MergeReadiness {
116147 if open_blockers == 0 {
117148 MergeReadiness :: Ready
@@ -238,6 +269,10 @@ mod tests {
238269 assert_eq ! ( summary. resolved_comments, 1 ) ;
239270 assert_eq ! ( summary. dismissed_comments, 1 ) ;
240271 assert_eq ! ( summary. open_blockers, 1 ) ;
272+ assert_eq ! ( summary. completeness. total_findings, 3 ) ;
273+ assert_eq ! ( summary. completeness. acknowledged_findings, 2 ) ;
274+ assert_eq ! ( summary. completeness. fixed_findings, 1 ) ;
275+ assert_eq ! ( summary. completeness. stale_findings, 0 ) ;
241276 assert_eq ! ( summary. open_by_severity. get( "Error" ) , Some ( & 1 ) ) ;
242277 assert_eq ! ( summary. merge_readiness, MergeReadiness :: NeedsAttention ) ;
243278 assert_eq ! (
@@ -344,9 +379,34 @@ mod tests {
344379 let summary = apply_review_runtime_state ( generate_summary ( & comments) , true ) ;
345380 assert_eq ! ( summary. open_blockers, 0 ) ;
346381 assert_eq ! ( summary. merge_readiness, MergeReadiness :: NeedsReReview ) ;
382+ assert_eq ! ( summary. completeness. stale_findings, 0 ) ;
347383 assert_eq ! (
348384 summary. readiness_reasons,
349385 vec![ "new commits landed after this review" . to_string( ) ]
350386 ) ;
351387 }
388+
389+ #[ test]
390+ fn stale_review_counts_open_findings_in_completeness ( ) {
391+ let comments = vec ! [
392+ make_comment(
393+ "open-warning" ,
394+ Severity :: Warning ,
395+ Category :: Bug ,
396+ CommentStatus :: Open ,
397+ ) ,
398+ make_comment(
399+ "resolved-info" ,
400+ Severity :: Info ,
401+ Category :: Documentation ,
402+ CommentStatus :: Resolved ,
403+ ) ,
404+ ] ;
405+
406+ let summary = apply_review_runtime_state ( generate_summary ( & comments) , true ) ;
407+ assert_eq ! ( summary. completeness. total_findings, 2 ) ;
408+ assert_eq ! ( summary. completeness. acknowledged_findings, 1 ) ;
409+ assert_eq ! ( summary. completeness. fixed_findings, 1 ) ;
410+ assert_eq ! ( summary. completeness. stale_findings, 1 ) ;
411+ }
352412}
0 commit comments