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

@@ -0,0 +1,31 @@
package baseadapter
import (
"fmt"
"io"
"net/http"
"net/url"
)
type Rest struct {
baseURL string
bearerToken string
}
func (b *Rest) createRequest(method string, body io.Reader, path ...string) (r *http.Request, err error) {
target, err := url.JoinPath(b.baseURL, path...)
if err != nil {
err = fmt.Errorf("can not parse path: %w", err)
return
}
req, err := http.NewRequest(method, target, body)
if err != nil {
return nil, err
}
if b.bearerToken != "" {
req.Header.Set("Authorization", "Bearer "+b.bearerToken)
}
return req, nil
}

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"io"
"net/http"
"bitbucket.bit.admin.ch/scm/~u80859501/pierre-bot/internal/pierre"
)
type BitbucketAdapter struct {
@@ -36,3 +38,9 @@ func (b *BitbucketAdapter) GetDiff(projectKey, repositorySlug string, pullReques
diff = response.Body
return
}
func (b *BitbucketAdapter) AddComment(projectKey, repositorySlug string, pullRequestID int, comment pierre.Comment) error {
fmt.Printf("[MOCK BITBUCKET] Adding comment to PR %s/%s #%d: %s at %s:%d\n",
projectKey, repositorySlug, pullRequestID, comment.Message, comment.File, comment.Line)
return nil
}

View File

@@ -0,0 +1,46 @@
package gitea
import (
"bytes"
"io"
"bitbucket.bit.admin.ch/scm/~u80859501/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
}

View File

@@ -1 +0,0 @@
package gitadapters