This commit is contained in:
u80864958
2026-02-12 16:02:38 +01:00
commit 3d4d908d54
14 changed files with 885 additions and 0 deletions

43
internal/pierre/judge.go Normal file
View File

@@ -0,0 +1,43 @@
package pierre
import (
"context"
"fmt"
"io"
"bitbucket.bit.admin.ch/scm/~u80859501/pierre-bot/internal/chatter"
)
type Comment struct {
File string `json:"file"`
Line int `json:"line"`
Message string `json:"message"`
}
type ChatAdapter interface {
GenerateStructured(ctx context.Context, messages []chatter.Message, target interface{}) error
}
func JudgePR(ctx context.Context, chat ChatAdapter, diff io.Reader) (comments []Comment, err error) {
diffBytes, err := io.ReadAll(diff)
if err != nil {
return nil, fmt.Errorf("failed to read diff: %w", err)
}
err = chat.GenerateStructured(ctx, []chatter.Message{
{
Role: chatter.RoleSystem,
Content: `
You are a very strict senior software architect.
You review **only** newly added or modified lines in a unified diff (lines prefixed with “+”), together with the immediate hunk context.
You do **not** report issues that appear **solely** in deleted lines (“-”) or that have already been fixed by the change.
No comments are made on pure formatting/whitespace changes or reordering that does not alter the programs behavior.
`,
},
{
Role: chatter.RoleUser,
Content: fmt.Sprintf("Hello please review my PR.\n Here is the git diff of it: %s", string(diffBytes)),
},
}, &comments)
return
}