feat: gitea client

This commit is contained in:
2026-02-12 20:58:55 +01:00
parent 8583ab48ce
commit 9d49d94eff
13 changed files with 334 additions and 54 deletions

View File

@@ -0,0 +1,46 @@
package gitea
import (
"bytes"
"io"
"git.schreifuchs.ch/schreifuchs/pierre-bot/internal/pierre"
"code.gitea.io/sdk/gitea"
)
type Adapter struct {
client *gitea.Client
}
func New(baseURL, token string) (*Adapter, error) {
client, err := gitea.NewClient(baseURL, gitea.SetToken(token))
if err != nil {
return nil, err
}
return &Adapter{
client: client,
}, nil
}
func (g *Adapter) GetDiff(owner, repo string, prID int) (io.Reader, error) {
diff, _, err := g.client.GetPullRequestDiff(owner, repo, int64(prID), gitea.PullRequestDiffOptions{})
if err != nil {
return nil, err
}
return bytes.NewReader(diff), nil
}
func (g *Adapter) AddComment(owner, repo string, prID int, comment pierre.Comment) error {
opts := gitea.CreatePullReviewOptions{
State: gitea.ReviewStateComment,
Comments: []gitea.CreatePullReviewComment{
{
Path: comment.File,
Body: comment.Message,
NewLineNum: int64(comment.Line),
},
},
}
_, _, err := g.client.CreatePullReview(owner, repo, int64(prID), opts)
return err
}