-
Notifications
You must be signed in to change notification settings - Fork 375
feat: add severity classification for review comments #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
cmd/opencodereview/output_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/open-code-review/open-code-review/internal/model" | ||
| ) | ||
|
|
||
| func TestFilterBySeverity(t *testing.T) { | ||
| comments := []model.LlmComment{ | ||
| {Path: "a.go", Content: "critical bug", Severity: model.SeverityCritical}, | ||
| {Path: "b.go", Content: "warning issue", Severity: model.SeverityWarning}, | ||
| {Path: "c.go", Content: "suggestion", Severity: model.SeveritySuggestion}, | ||
| {Path: "d.go", Content: "nitpick", Severity: model.SeverityNitpick}, | ||
| {Path: "e.go", Content: "no severity"}, | ||
| } | ||
|
|
||
| tests := []struct { | ||
| minSeverity string | ||
| wantCount int | ||
| wantPaths []string | ||
| }{ | ||
| // No filter: all comments returned. | ||
| {"", 5, []string{"a.go", "b.go", "c.go", "d.go", "e.go"}}, | ||
| // nitpick: keeps all with severity, filters out unset (rank 0 < 1). | ||
| {"nitpick", 4, []string{"a.go", "b.go", "c.go", "d.go"}}, | ||
| // suggestion: keeps critical + warning + suggestion. | ||
| {"suggestion", 3, []string{"a.go", "b.go", "c.go"}}, | ||
| // warning: keeps critical + warning. | ||
| {"warning", 2, []string{"a.go", "b.go"}}, | ||
| // critical: keeps only critical. | ||
| {"critical", 1, []string{"a.go"}}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run("min="+tt.minSeverity, func(t *testing.T) { | ||
| got := filterBySeverity(comments, tt.minSeverity) | ||
| if len(got) != tt.wantCount { | ||
| t.Fatalf("got %d comments, want %d", len(got), tt.wantCount) | ||
| } | ||
| for i, want := range tt.wantPaths { | ||
| if got[i].Path != want { | ||
| t.Errorf("got[%d].Path = %q, want %q", i, got[i].Path, want) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestFilterBySeverity_Empty(t *testing.T) { | ||
| got := filterBySeverity(nil, "warning") | ||
| if len(got) != 0 { | ||
| t.Errorf("expected empty slice, got %v", got) | ||
| } | ||
| } | ||
|
|
||
| func TestFilterBySeverity_ReturnsNonNilSlice(t *testing.T) { | ||
| // When minSeverity is set, result should always be non-nil (for JSON: [] not null). | ||
| comments := []model.LlmComment{ | ||
| {Path: "a.go", Content: "nitpick", Severity: model.SeverityNitpick}, | ||
| } | ||
| got := filterBySeverity(comments, "critical") | ||
| if got == nil { | ||
| t.Fatal("expected non-nil empty slice, got nil") | ||
| } | ||
| if len(got) != 0 { | ||
| t.Errorf("expected 0 comments, got %d", len(got)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 43 additions & 7 deletions
internal/model/review.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
internal/model/review_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package model | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestSeverity_Rank(t *testing.T) { | ||
| tests := []struct { | ||
| severity Severity | ||
| wantRank int | ||
| }{ | ||
| {SeverityCritical, 4}, | ||
| {SeverityWarning, 3}, | ||
| {SeveritySuggestion, 2}, | ||
| {SeverityNitpick, 1}, | ||
| {Severity("unknown"), 0}, | ||
| {Severity(""), 0}, | ||
| } | ||
| for _, tt := range tests { | ||
| if got := tt.severity.Rank(); got != tt.wantRank { | ||
| t.Errorf("Severity(%q).Rank() = %d, want %d", tt.severity, got, tt.wantRank) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestSeverity_Ordering(t *testing.T) { | ||
| if SeverityCritical.Rank() <= SeverityWarning.Rank() { | ||
| t.Error("critical should outrank warning") | ||
| } | ||
| if SeverityWarning.Rank() <= SeveritySuggestion.Rank() { | ||
| t.Error("warning should outrank suggestion") | ||
| } | ||
| if SeveritySuggestion.Rank() <= SeverityNitpick.Rank() { | ||
| t.Error("suggestion should outrank nitpick") | ||
| } | ||
| } | ||
|
|
||
| func TestValidSeverity(t *testing.T) { | ||
| valid := []string{"critical", "warning", "suggestion", "nitpick"} | ||
| for _, s := range valid { | ||
| if !ValidSeverity(s) { | ||
| t.Errorf("ValidSeverity(%q) = false, want true", s) | ||
| } | ||
| } | ||
| invalid := []string{"", "high", "low", "error", "Critical"} | ||
| for _, s := range invalid { | ||
| if ValidSeverity(s) { | ||
| t.Errorf("ValidSeverity(%q) = true, want false", s) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.