Skip to content

Commit f4e2706

Browse files
committed
Dedicated ReviewCount vs KeepCount fields
1 parent ac638ac commit f4e2706

6 files changed

Lines changed: 38 additions & 9 deletions

client/cmd/code_scanning_apply.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"os"
77
"time"
88

9-
gh "github.com/advanced-security/codeql-development-mcp-server/client/internal/github"
109
"github.com/spf13/cobra"
10+
11+
gh "github.com/advanced-security/codeql-development-mcp-server/client/internal/github"
1112
)
1213

1314
// ---------------------------------------------------------------------------

client/cmd/code_scanning_assess.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type assessSummary struct {
3737
KeepDismissed int `json:"keepDismissedCount"`
3838
KeepFixed int `json:"keepFixedCount"`
3939
DiscardCount int `json:"discardCount"`
40+
ReviewCount int `json:"reviewCount"`
4041
ChurnRiskCount int `json:"churnRiskCount"`
4142
OverlapPairCount int `json:"overlapPairCount"`
4243
}
@@ -147,7 +148,7 @@ func buildAssessReport(baseReport codeScanningReport, assessed []assessedAlert)
147148
case "discard":
148149
summary.DiscardCount++
149150
case "review":
150-
summary.KeepCount++ // counted as keep until user decides
151+
summary.ReviewCount++
151152
}
152153
if a.ChurnRisk != "" {
153154
summary.ChurnRiskCount++

client/cmd/code_scanning_assess_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,29 @@ func TestBuildAssessReport_Summary(t *testing.T) {
129129
t.Error("expected at least 1 keep recommendation")
130130
}
131131
}
132+
133+
func TestBuildAssessReport_ReviewCountSeparateFromKeep(t *testing.T) {
134+
// Alert 1 is open with an overlap to a dismissed alert -> "review"
135+
// Alert 2 is dismissed -> "keep-dismissed"
136+
// Alert 3 is open, no overlaps -> "keep"
137+
alerts := []alertEntry{
138+
{Number: 1, State: "open", Rule: ruleEntry{ID: "js/sql-injection-v2"}, Location: locationEntry{Path: "src/db.js", StartLine: 42}},
139+
{Number: 2, State: "dismissed", Rule: ruleEntry{ID: "js/sql-injection"}, Location: locationEntry{Path: "src/db.js", StartLine: 42},
140+
DismissedReason: strPtr("false positive")},
141+
{Number: 3, State: "open", Rule: ruleEntry{ID: "js/xss"}, Location: locationEntry{Path: "src/views.js", StartLine: 30}},
142+
}
143+
144+
report := buildReport("test/repo", nil, alerts)
145+
assessed := assessAlerts(alerts)
146+
assessReport := buildAssessReport(report, assessed)
147+
148+
if assessReport.Summary.ReviewCount != 1 {
149+
t.Errorf("reviewCount = %d, want 1", assessReport.Summary.ReviewCount)
150+
}
151+
if assessReport.Summary.KeepCount != 1 {
152+
t.Errorf("keepCount = %d, want 1 (only pure keep, not review)", assessReport.Summary.KeepCount)
153+
}
154+
if assessReport.Summary.KeepDismissed != 1 {
155+
t.Errorf("keepDismissedCount = %d, want 1", assessReport.Summary.KeepDismissed)
156+
}
157+
}

client/cmd/code_scanning_report.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"sort"
99
"time"
1010

11-
gh "github.com/advanced-security/codeql-development-mcp-server/client/internal/github"
1211
"github.com/spf13/cobra"
12+
13+
gh "github.com/advanced-security/codeql-development-mcp-server/client/internal/github"
1314
)
1415

1516
// ---------------------------------------------------------------------------
@@ -179,7 +180,7 @@ func init() {
179180
f.StringVar(&reportFlags.repo, "repo", "", "Repository in owner/repo format (required)")
180181
f.StringVar(&reportFlags.ref, "ref", "", "Git ref to filter by (e.g. refs/heads/main)")
181182
f.StringVar(&reportFlags.toolName, "tool-name", "", "Tool name to filter by (e.g. CodeQL)")
182-
f.StringVar(&reportFlags.state, "state", "", "Alert state filter: open, closed, dismissed, fixed")
183+
f.StringVar(&reportFlags.state, "state", "", "Alert state filter: open, dismissed, fixed")
183184
f.StringVar(&reportFlags.output, "output", "", "Output file path (default: <owner>_<repo>.cs-report.json)")
184185
f.BoolVar(&reportFlags.includeSarif, "include-sarif", false, "Also download SARIF files for each analysis")
185186
f.IntVar(&reportFlags.perPage, "per-page", 100, "Results per page for API calls (max 100)")

client/cmd/code_scanning_report_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,3 @@ func TestBuildReport_JSONRoundTripWithDismissal(t *testing.T) {
228228
t.Error("dismissedBy lost in JSON roundtrip")
229229
}
230230
}
231-
232-
// strPtr returns a pointer to s.
233-
func strPtr(s string) *string {
234-
return &s
235-
}

client/cmd/helpers_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ func TestParseRepo_Invalid(t *testing.T) {
2929
}
3030
}
3131
}
32+
33+
// strPtr returns a pointer to s.
34+
func strPtr(s string) *string {
35+
return &s
36+
}

0 commit comments

Comments
 (0)