@@ -31,12 +31,35 @@ impl From<&str> for IssueSize {
31
31
}
32
32
}
33
33
}
34
+ #[ derive( Enum , Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Debug ) ]
35
+ enum IssuePriority {
36
+ P0 ,
37
+ P1 ,
38
+ P2 ,
39
+ None ,
40
+ }
41
+
42
+ impl From < & str > for IssuePriority {
43
+ fn from ( s : & str ) -> Self {
44
+ match s {
45
+ "P0" => Self :: P0 ,
46
+ "P1" => Self :: P1 ,
47
+ "P2" => Self :: P2 ,
48
+ _ => Self :: None ,
49
+ }
50
+ }
51
+ }
34
52
35
53
#[ derive( SimpleObject ) ]
36
54
struct IssueSizeCount {
37
55
size : IssueSize ,
38
56
count : usize ,
39
57
}
58
+ #[ derive( SimpleObject , Debug ) ]
59
+ struct IssuePriorityCount {
60
+ priority : IssuePriority ,
61
+ count : usize ,
62
+ }
40
63
41
64
#[ derive( InputObject , Debug ) ]
42
65
pub ( crate ) struct IssueStatFilter {
@@ -91,6 +114,9 @@ struct IssueStat {
91
114
92
115
/// The distribution of resolved issues by size.
93
116
resolved_issue_size_distribution : Vec < IssueSizeCount > ,
117
+
118
+ /// The distribution of priorities for resolved issues.
119
+ resolved_issue_priority_distribution : Vec < IssuePriorityCount > ,
94
120
}
95
121
96
122
#[ Object ]
@@ -132,10 +158,29 @@ impl IssueStatQuery {
132
158
. map ( |( size, count) | IssueSizeCount { size, count } )
133
159
. collect ( ) ;
134
160
161
+ let resolved_issue_priority_distribution = resolved_issues
162
+ . iter ( )
163
+ . fold ( BTreeMap :: new ( ) , |mut acc, issue| {
164
+ let priority_str = issue
165
+ . project_items
166
+ . nodes
167
+ . iter ( )
168
+ . find ( |p| p. project_title == super :: issue:: TODO_LIST_PROJECT_TITLE )
169
+ . and_then ( |p| p. todo_priority . as_deref ( ) )
170
+ . unwrap_or ( "None" ) ;
171
+
172
+ * acc. entry ( priority_str. into ( ) ) . or_insert ( 0 ) += 1 ;
173
+ acc
174
+ } )
175
+ . into_iter ( )
176
+ . map ( |( priority, count) | IssuePriorityCount { priority, count } )
177
+ . collect ( ) ;
178
+
135
179
Ok ( IssueStat {
136
180
open_issue_count,
137
181
resolved_issue_count,
138
182
resolved_issue_size_distribution,
183
+ resolved_issue_priority_distribution,
139
184
} )
140
185
}
141
186
}
@@ -555,7 +600,6 @@ mod tests {
555
600
let schema = TestSchema :: new ( ) ;
556
601
let owner: & str = "aicers" ;
557
602
let repo = "github-dashboard-server" ;
558
-
559
603
let mut resolved_issues = create_resolved_issues ( 1 ..=6 ) ;
560
604
// 1 XS
561
605
resolved_issues[ 0 ]
@@ -624,4 +668,50 @@ mod tests {
624
668
] )
625
669
) ;
626
670
}
671
+
672
+ #[ tokio:: test]
673
+ async fn resolved_issue_priority_distribution ( ) {
674
+ let schema = TestSchema :: new ( ) ;
675
+ let owner: & str = "aicers" ;
676
+ let repo = "github-dashboard-server" ;
677
+
678
+ let mut resolved_issues = create_resolved_issues ( 1 ..=10 ) ;
679
+ // P0: 2
680
+ resolved_issues[ 0 ] . project_items . nodes [ 0 ] . todo_priority = Some ( "P0" . to_string ( ) ) ;
681
+ resolved_issues[ 1 ] . project_items . nodes [ 0 ] . todo_priority = Some ( "P0" . to_string ( ) ) ;
682
+ // P1: 3
683
+ resolved_issues[ 2 ] . project_items . nodes [ 0 ] . todo_priority = Some ( "P1" . to_string ( ) ) ;
684
+ resolved_issues[ 3 ] . project_items . nodes [ 0 ] . todo_priority = Some ( "P1" . to_string ( ) ) ;
685
+ resolved_issues[ 4 ] . project_items . nodes [ 0 ] . todo_priority = Some ( "P1" . to_string ( ) ) ;
686
+ // P2: 1
687
+ resolved_issues[ 5 ] . project_items . nodes [ 0 ] . todo_priority = Some ( "P2" . to_string ( ) ) ;
688
+ // None: 4
689
+
690
+ schema
691
+ . db
692
+ . insert_issues ( resolved_issues, owner, repo)
693
+ . unwrap ( ) ;
694
+
695
+ let query = r"
696
+ {
697
+ issueStat(filter: {}) {
698
+ resolvedIssuePriorityDistribution {
699
+ priority
700
+ count
701
+ }
702
+ }
703
+ }" ;
704
+ let data = schema. execute ( query) . await . data . into_json ( ) . unwrap ( ) ;
705
+ let dist = & data[ "issueStat" ] [ "resolvedIssuePriorityDistribution" ] ;
706
+
707
+ assert_eq ! ( dist. as_array( ) . unwrap( ) . len( ) , 4 ) ;
708
+ assert_eq ! ( dist[ 0 ] [ "priority" ] , "P0" ) ;
709
+ assert_eq ! ( dist[ 0 ] [ "count" ] , 2 ) ;
710
+ assert_eq ! ( dist[ 1 ] [ "priority" ] , "P1" ) ;
711
+ assert_eq ! ( dist[ 1 ] [ "count" ] , 3 ) ;
712
+ assert_eq ! ( dist[ 2 ] [ "priority" ] , "P2" ) ;
713
+ assert_eq ! ( dist[ 2 ] [ "count" ] , 1 ) ;
714
+ assert_eq ! ( dist[ 3 ] [ "priority" ] , "NONE" ) ;
715
+ assert_eq ! ( dist[ 3 ] [ "count" ] , 4 ) ;
716
+ }
627
717
}
0 commit comments