Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 600f68f

Browse files
committed
Add resolved_issue_priority_distribution
Close #196
1 parent a4d6075 commit 600f68f

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1212
`resolvedIssueCount` is added, indicating the number of resolved issues.
1313
Currently, an issue is defined to be resolved if and only if (1) it is
1414
"Closed" and (2) status of project item "to-do list" is "Done".
15+
- Added `resolved_issue_priority_distribution` field to `issueStat` query,
16+
which shows the distribution of priorities for resolved issues.
1517
- Tracing with a filter set by `RUST_LOG` environment variable.
1618
- Added support for passing the SSH passphrase through the `SSH_PASSPHRASE`
1719
environment variable.

src/api/issue_stat.rs

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,35 @@ impl From<&str> for IssueSize {
3131
}
3232
}
3333
}
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+
}
3452

3553
#[derive(SimpleObject)]
3654
struct IssueSizeCount {
3755
size: IssueSize,
3856
count: usize,
3957
}
58+
#[derive(SimpleObject, Debug)]
59+
struct IssuePriorityCount {
60+
priority: IssuePriority,
61+
count: usize,
62+
}
4063

4164
#[derive(InputObject, Debug)]
4265
pub(crate) struct IssueStatFilter {
@@ -91,6 +114,9 @@ struct IssueStat {
91114

92115
/// The distribution of resolved issues by size.
93116
resolved_issue_size_distribution: Vec<IssueSizeCount>,
117+
118+
/// The distribution of priorities for resolved issues.
119+
resolved_issue_priority_distribution: Vec<IssuePriorityCount>,
94120
}
95121

96122
#[Object]
@@ -132,10 +158,29 @@ impl IssueStatQuery {
132158
.map(|(size, count)| IssueSizeCount { size, count })
133159
.collect();
134160

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+
135179
Ok(IssueStat {
136180
open_issue_count,
137181
resolved_issue_count,
138182
resolved_issue_size_distribution,
183+
resolved_issue_priority_distribution,
139184
})
140185
}
141186
}
@@ -555,7 +600,6 @@ mod tests {
555600
let schema = TestSchema::new();
556601
let owner: &str = "aicers";
557602
let repo = "github-dashboard-server";
558-
559603
let mut resolved_issues = create_resolved_issues(1..=6);
560604
// 1 XS
561605
resolved_issues[0]
@@ -624,4 +668,50 @@ mod tests {
624668
])
625669
);
626670
}
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+
}
627717
}

0 commit comments

Comments
 (0)