Skip to content
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
1 change: 1 addition & 0 deletions ai/prreview/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func RunGate(ctx context.Context, cfg GateConfig) error {
if err != nil {
return fail("Gemini review failed: could not fetch diff", err)
}
diff = DropGeneratedFiles(diff)
if strings.TrimSpace(diff) == "" {
return fail("Gemini review inconclusive: empty diff", nil)
}
Expand Down
17 changes: 17 additions & 0 deletions ai/prreview/prreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ func FetchFailingChecks(ctx context.Context, token, owner, repo, sha string) ([]
return failing, nil
}

// DropGeneratedFiles removes per-file sections for build output that is
// regenerated from source (the compiled Tailwind stylesheets), so a one-line
// minified file does not push a small change over the size limit.
func DropGeneratedFiles(diff string) string {
var out strings.Builder
skip := false
for _, line := range strings.SplitAfter(diff, "\n") {
if strings.HasPrefix(line, "diff --git ") {
skip = strings.HasSuffix(strings.TrimSpace(line), "/tailwind.css")
}
if !skip {
out.WriteString(line)
}
}
return out.String()
}

// TruncateDiff caps diff at maxBytes so the Gemini request stays within the
// model's input token budget. It reports whether truncation happened.
func TruncateDiff(diff string, maxBytes int) (string, bool) {
Expand Down
9 changes: 9 additions & 0 deletions ai/prreview/prreview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,12 @@ func TestPostCommentSuccess(t *testing.T) {
t.Fatalf("PostComment returned an unexpected error: %v", err)
}
}

func TestDropGeneratedFiles(t *testing.T) {
diff := "diff --git a/demo/tailwind.css b/demo/tailwind.css\n+minified\ndiff --git a/demo/index.html b/demo/index.html\n+<p>\n"
got := DropGeneratedFiles(diff)
want := "diff --git a/demo/index.html b/demo/index.html\n+<p>\n"
if got != want {
t.Fatalf("got %q, want %q", got, want)
}
}
Loading