feat(tools): pr_create with identity footer

This commit is contained in:
Mathias Bergqvist
2026-05-04 22:20:33 +02:00
parent 5af8addc26
commit 9972dcd94e
5 changed files with 360 additions and 0 deletions

66
internal/gitea/pulls.go Normal file
View File

@@ -0,0 +1,66 @@
package gitea
import (
"context"
"encoding/json"
"fmt"
)
type PullRequest struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
HTMLURL string `json:"html_url"`
State string `json:"state"`
Draft bool `json:"draft"`
Head struct {
Ref string `json:"ref"`
} `json:"head"`
Base struct {
Ref string `json:"ref"`
} `json:"base"`
}
type CreatePullRequestArgs struct {
Title string `json:"title"`
Body string `json:"body"`
Head string `json:"head"`
Base string `json:"base"`
Draft bool `json:"draft"`
}
func (c *Client) CreatePullRequest(ctx context.Context, owner, repo string, args CreatePullRequestArgs) (*PullRequest, error) {
p := fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner, repo)
payload, err := json.Marshal(args)
if err != nil {
return nil, err
}
body, status, err := c.PostJSON(ctx, p, payload)
if err != nil {
return nil, err
}
if err := MapStatus(status, body); err != nil {
return nil, err
}
var pr PullRequest
if err := json.Unmarshal(body, &pr); err != nil {
return nil, err
}
return &pr, nil
}
func (c *Client) GetPullRequest(ctx context.Context, owner, repo string, index int) (*PullRequest, error) {
p := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", owner, repo, index)
body, status, err := c.GetJSON(ctx, p)
if err != nil {
return nil, err
}
if err := MapStatus(status, body); err != nil {
return nil, err
}
var pr PullRequest
if err := json.Unmarshal(body, &pr); err != nil {
return nil, err
}
return &pr, nil
}