feat: gitea client

This commit is contained in:
2026-02-12 20:58:55 +01:00
parent 8583ab48ce
commit 9bd7d363ba
1693 changed files with 653995 additions and 49 deletions

View File

@@ -14,28 +14,24 @@ type Comment struct {
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) {
func (s *Service) judgePR(ctx context.Context, 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{
err = s.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 review **only** newly added or modified lines in a unified diff, 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)),
Content: fmt.Sprintf("Hello please review my PR. Write comments where improvements are necessary in new lines.\n Here is the git diff of it: %s", string(diffBytes)),
},
}, &comments)

View File

@@ -0,0 +1,29 @@
package pierre
import (
"context"
"io"
"bitbucket.bit.admin.ch/scm/~u80859501/pierre-bot/internal/chatter"
)
type Service struct {
git GitAdapter
chat ChatAdapter
}
func New(chat ChatAdapter, git GitAdapter) *Service {
return &Service{
git: git,
chat: chat,
}
}
type GitAdapter interface {
GetDiff(owner, repo string, prID int) (io.Reader, error)
AddComment(owner, repo string, prID int, comment Comment) error
}
type ChatAdapter interface {
GenerateStructured(ctx context.Context, messages []chatter.Message, target interface{}) error
}

34
internal/pierre/review.go Normal file
View File

@@ -0,0 +1,34 @@
package pierre
import (
"context"
"fmt"
"log"
)
func (s *Service) MakeReview(ctx context.Context, organisation string, repo string, prID int) error {
// Fetch Diff using positional args from shared RepoArgs
diff, err := s.git.GetDiff(organisation, repo, prID)
if err != nil {
log.Fatalf("Error fetching diff: %v", err)
}
// Run Logic
comments, err := s.judgePR(context.Background(), diff)
if err != nil {
log.Fatalf("Error judging PR: %v", err)
}
fmt.Printf("Analysis complete. Found %d issues.\n---\n", len(comments))
for _, c := range comments {
fmt.Printf("File: %s\nLine: %d\nMessage: %s\n%s\n",
c.File, c.Line, c.Message, "---")
if err := s.git.AddComment(organisation, repo, prID, c); err != nil {
log.Printf("Failed to add comment: %v", err)
}
}
return nil
}