From ec7d12458ad51afa481f83f5ceb837a8d2eec2d4 Mon Sep 17 00:00:00 2001 From: sreallymatt <106555974+sreallymatt@users.noreply.github.com> Date: Mon, 8 Sep 2025 15:34:27 -0600 Subject: [PATCH 1/3] add better filtering for reviews and review comments --- cli/cmds_prs.go | 2 +- lib/gh/pr_gql.go | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cli/cmds_prs.go b/cli/cmds_prs.go index ca65b7a..8323dd8 100644 --- a/cli/cmds_prs.go +++ b/cli/cmds_prs.go @@ -144,7 +144,7 @@ func CmdPRs(_ *cobra.Command, _ []string) error { {Name: "user", FieldID: p.FieldIDs["User"], Type: gh.ItemValueTypeText, Value: pr.Author}, {Name: "daysOpen", FieldID: p.FieldIDs["Open Days"], Type: gh.ItemValueTypeNumber, Value: daysOpen}, {Name: "daysWait", FieldID: p.FieldIDs["Waiting Days"], Type: gh.ItemValueTypeNumber, Value: daysWaiting}, - {Name: "commentCount", FieldID: p.FieldIDs["Comment Count"], Type: gh.ItemValueTypeNumber, Value: pr.TotalCommentsCount}, + {Name: "commentCount", FieldID: p.FieldIDs["Comment Count"], Type: gh.ItemValueTypeNumber, Value: pr.TotalCommentCount}, {Name: "reviewCount", FieldID: p.FieldIDs["Review Count"], Type: gh.ItemValueTypeNumber, Value: pr.TotalReviewCount}, } diff --git a/lib/gh/pr_gql.go b/lib/gh/pr_gql.go index 1c8d85c..fe0c9a5 100644 --- a/lib/gh/pr_gql.go +++ b/lib/gh/pr_gql.go @@ -8,20 +8,22 @@ import ( ) type PullRequest struct { - NodeID string - Author string - Number int - Title string - State string - ReviewDecision string - CreatedAt time.Time - UpdatedAt time.Time - ClosedAt time.Time - Draft bool - Milestone string - TotalCommentsCount int - TotalReviewCount int - FilteredReviewCount int + NodeID string + Author string + Number int + Title string + State string + ReviewDecision string + CreatedAt time.Time + UpdatedAt time.Time + ClosedAt time.Time + Draft bool + Milestone string + TotalCommentCount int + TotalReviewCount int + ReviewCommentCount int + FilteredReviewCount int + FilteredReviewCommentCount int Assignees []string AssociatedLabels map[string]bool @@ -68,6 +70,10 @@ type pullRequestsQuery struct { Author struct { Login string } + Comments struct { + TotalCount int + } + State string } } `graphql:"reviews(first: 100)"` @@ -143,7 +149,7 @@ func (q pullRequestsQuery) flatten(reviewers map[string]struct{}) []PullRequest ClosedAt: pullRequest.ClosedAt, Draft: pullRequest.IsDraft, Milestone: pullRequest.Milestone.Title, - TotalCommentsCount: pullRequest.TotalCommentsCount, + TotalCommentCount: pullRequest.TotalCommentsCount, AssociatedLabels: make(map[string]bool), AssociatedProjectNumbers: make(map[int]bool), } @@ -161,14 +167,21 @@ func (q pullRequestsQuery) flatten(reviewers map[string]struct{}) []PullRequest } for _, review := range pullRequest.Reviews.Nodes { + // We're only interested in `APPROVED`, `CHANGES_REQUESTED`, and `DISMISSED` states. + if review.State == string(githubv4.PullRequestReviewStateCommented) || review.State == string(githubv4.PullRequestReviewStatePending) { + continue + } pr.TotalReviewCount++ + pr.ReviewCommentCount += review.Comments.TotalCount // Only add filtered review count if `reviewers` filter was provided if _, ok := reviewers[review.Author.Login]; ok { pr.FilteredReviewCount++ + pr.FilteredReviewCommentCount += review.Comments.TotalCount } } + result = append(result, pr) } From 3267146fdee88b780cb176f879267833f6708a56 Mon Sep 17 00:00:00 2001 From: sreallymatt <106555974+sreallymatt@users.noreply.github.com> Date: Mon, 8 Sep 2025 15:36:43 -0600 Subject: [PATCH 2/3] gofmt --- lib/gh/pr_gql.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/gh/pr_gql.go b/lib/gh/pr_gql.go index fe0c9a5..c48c1c9 100644 --- a/lib/gh/pr_gql.go +++ b/lib/gh/pr_gql.go @@ -181,7 +181,6 @@ func (q pullRequestsQuery) flatten(reviewers map[string]struct{}) []PullRequest } } - result = append(result, pr) } From 220c38b2603db470fb78a8415664e491e7d53f34 Mon Sep 17 00:00:00 2001 From: sreallymatt <106555974+sreallymatt@users.noreply.github.com> Date: Mon, 8 Sep 2025 15:41:27 -0600 Subject: [PATCH 3/3] add new fields to projectItemField slice --- cli/cmds_prs.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/cmds_prs.go b/cli/cmds_prs.go index 8323dd8..f8702e0 100644 --- a/cli/cmds_prs.go +++ b/cli/cmds_prs.go @@ -146,10 +146,12 @@ func CmdPRs(_ *cobra.Command, _ []string) error { {Name: "daysWait", FieldID: p.FieldIDs["Waiting Days"], Type: gh.ItemValueTypeNumber, Value: daysWaiting}, {Name: "commentCount", FieldID: p.FieldIDs["Comment Count"], Type: gh.ItemValueTypeNumber, Value: pr.TotalCommentCount}, {Name: "reviewCount", FieldID: p.FieldIDs["Review Count"], Type: gh.ItemValueTypeNumber, Value: pr.TotalReviewCount}, + {Name: "reviewCommentCount", FieldID: p.FieldIDs["Review Comment Count"], Type: gh.ItemValueTypeNumber, Value: pr.ReviewCommentCount}, } if pr.FilteredReviewCount > 0 { fields = append(fields, gh.ProjectItemField{Name: "filteredReviewCount", FieldID: p.FieldIDs["Filtered Review Count"], Type: gh.ItemValueTypeNumber, Value: pr.FilteredReviewCount}) + fields = append(fields, gh.ProjectItemField{Name: "filteredReviewCommentCount", FieldID: p.FieldIDs["Filtered Review Comment Count"], Type: gh.ItemValueTypeNumber, Value: pr.FilteredReviewCommentCount}) } err = p.UpdateItem(*iid, fields)