Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `openIssueCount`: The number of open issues.
- `resolvedIssueSizeDistribution`: The distribution of sizes for resolved issues.
- `avgResolutionDays`: The average resolution time in days for resolved issues.
- `resolved_issue_priority_distribution`: The distribution of priorities for resolved
issues.
- Added additional fields to the `issues` GraphQL query, providing detailed
information such as comments, labels, related sub-issues, linked pull
requests, issue descriptions, timestamps, and project-related metadata.
Expand Down
94 changes: 92 additions & 2 deletions src/api/issue_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,35 @@ impl From<&str> for IssueSize {
}
}
}
#[derive(Enum, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
enum IssuePriority {
P0,
P1,
P2,
None,
}

impl From<&str> for IssuePriority {
fn from(s: &str) -> Self {
match s {
"P0" => Self::P0,
"P1" => Self::P1,
"P2" => Self::P2,
_ => Self::None,
}
}
}

#[derive(SimpleObject)]
struct IssueSizeCount {
size: IssueSize,
count: usize,
}
#[derive(SimpleObject, Debug)]
struct IssuePriorityCount {
priority: IssuePriority,
count: usize,
}

#[derive(InputObject, Debug)]
pub(crate) struct IssueStatFilter {
Expand Down Expand Up @@ -97,6 +120,9 @@ struct IssueStat {

/// The average resolution time in days for resolved issues.
avg_resolution_days: Option<f64>,

/// The distribution of priorities for resolved issues.
resolved_issue_priority_distribution: Vec<IssuePriorityCount>,
}

#[Object]
Expand Down Expand Up @@ -174,11 +200,30 @@ impl IssueStatQuery {
)
};

let resolved_issue_priority_distribution = resolved_issues
.iter()
.fold(BTreeMap::new(), |mut acc, issue| {
let priority_str = issue
.project_items
.nodes
.iter()
.find(|p| p.project_title == super::TODO_LIST_PROJECT_TITLE)
.and_then(|p| p.todo_priority.as_deref())
.unwrap_or("None");

*acc.entry(priority_str.into()).or_insert(0) += 1;
acc
})
.into_iter()
.map(|(priority, count)| IssuePriorityCount { priority, count })
.collect();

Ok(IssueStat {
open_issue_count,
resolved_issue_count,
resolved_issue_size_distribution,
avg_resolution_days,
resolved_issue_priority_distribution,
})
}
}
Expand Down Expand Up @@ -597,7 +642,6 @@ mod tests {
let schema = TestSchema::new();
let owner: &str = "aicers";
let repo = "github-dashboard-server";

let mut resolved_issues = create_resolved_issues(1..=6);
// 1 XS
resolved_issues[0]
Expand Down Expand Up @@ -692,7 +736,7 @@ mod tests {
let query = r"
{
issueStat(filter: {}) {
avgResolutionDays
avgResolutionDays
}
}";
let data = schema.execute(query).await.data.into_json().unwrap();
Expand Down Expand Up @@ -730,4 +774,50 @@ mod tests {
// The average resolution days should be 0.0, not negative.
assert_eq!(data["issueStat"]["avgResolutionDays"], 0.0);
}

#[tokio::test]
async fn resolved_issue_priority_distribution() {
let schema = TestSchema::new();
let owner: &str = "aicers";
let repo = "github-dashboard-server";

let mut resolved_issues = create_resolved_issues(1..=10);
// P0: 2
resolved_issues[0].project_items.nodes[0].todo_priority = Some("P0".to_string());
resolved_issues[1].project_items.nodes[0].todo_priority = Some("P0".to_string());
// P1: 3
resolved_issues[2].project_items.nodes[0].todo_priority = Some("P1".to_string());
resolved_issues[3].project_items.nodes[0].todo_priority = Some("P1".to_string());
resolved_issues[4].project_items.nodes[0].todo_priority = Some("P1".to_string());
// P2: 1
resolved_issues[5].project_items.nodes[0].todo_priority = Some("P2".to_string());
// None: 4

schema
.db
.insert_issues(resolved_issues, owner, repo)
.unwrap();

let query = r"
{
issueStat(filter: {}) {
resolvedIssuePriorityDistribution {
priority
count
}
}
}";
let data = schema.execute(query).await.data.into_json().unwrap();
let dist = &data["issueStat"]["resolvedIssuePriorityDistribution"];

assert_eq!(dist.as_array().unwrap().len(), 4);
assert_eq!(dist[0]["priority"], "P0");
assert_eq!(dist[0]["count"], 2);
assert_eq!(dist[1]["priority"], "P1");
assert_eq!(dist[1]["count"], 3);
assert_eq!(dist[2]["priority"], "P2");
assert_eq!(dist[2]["count"], 1);
assert_eq!(dist[3]["priority"], "NONE");
assert_eq!(dist[3]["count"], 4);
}
}
Loading