* feat(gitea): add Gitea Go SDK integration and CLI commands Add `code.gitea.io/sdk/gitea` and create `pkg/gitea/` package for connecting to self-hosted Gitea instances. Wire into CLI as `core gitea` command group with repo, issue, PR, mirror, and sync subcommands. pkg/gitea/: - client.go: thin wrapper around SDK with config-based auth - config.go: env → config file → flags resolution - repos.go: list/get/create/delete repos, create mirrors - issues.go: list/get/create issues and pull requests - meta.go: pipeline MetaReader for structural + content signals internal/cmd/gitea/: - config: set URL/token, test connection - repos: list repos with table output - issues: list/create issues - prs: list pull requests - mirror: create GitHub→Gitea mirrors with auth - sync: upstream/main branch strategy (--setup + ongoing sync) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style(gitea): fix gofmt formatting Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(gitea): address Copilot review feedback - Use os.UserHomeDir() instead of sh -c "echo $HOME" for home dir expansion - Distinguish "already exists" from real errors in createMainFromUpstream - Fix package docs to match actual config resolution order - Guard token masking against short tokens (< 8 chars) - Paginate ListIssueComments in GetPRMeta and GetCommentBodies - Rename loop variable to avoid shadowing receiver in GetCommentBodies - Move gitea SDK to direct require block in go.mod Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
109 lines
2.6 KiB
Go
109 lines
2.6 KiB
Go
package gitea
|
|
|
|
import (
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"github.com/host-uk/core/pkg/log"
|
|
)
|
|
|
|
// ListIssuesOpts configures issue listing.
|
|
type ListIssuesOpts struct {
|
|
State string // "open", "closed", "all"
|
|
Page int
|
|
Limit int
|
|
}
|
|
|
|
// ListIssues returns issues for the given repository.
|
|
func (c *Client) ListIssues(owner, repo string, opts ListIssuesOpts) ([]*gitea.Issue, error) {
|
|
state := gitea.StateOpen
|
|
switch opts.State {
|
|
case "closed":
|
|
state = gitea.StateClosed
|
|
case "all":
|
|
state = gitea.StateAll
|
|
}
|
|
|
|
limit := opts.Limit
|
|
if limit == 0 {
|
|
limit = 50
|
|
}
|
|
|
|
page := opts.Page
|
|
if page == 0 {
|
|
page = 1
|
|
}
|
|
|
|
issues, _, err := c.api.ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
|
ListOptions: gitea.ListOptions{Page: page, PageSize: limit},
|
|
State: state,
|
|
Type: gitea.IssueTypeIssue,
|
|
})
|
|
if err != nil {
|
|
return nil, log.E("gitea.ListIssues", "failed to list issues", err)
|
|
}
|
|
|
|
return issues, nil
|
|
}
|
|
|
|
// GetIssue returns a single issue by number.
|
|
func (c *Client) GetIssue(owner, repo string, number int64) (*gitea.Issue, error) {
|
|
issue, _, err := c.api.GetIssue(owner, repo, number)
|
|
if err != nil {
|
|
return nil, log.E("gitea.GetIssue", "failed to get issue", err)
|
|
}
|
|
|
|
return issue, nil
|
|
}
|
|
|
|
// CreateIssue creates a new issue in the given repository.
|
|
func (c *Client) CreateIssue(owner, repo string, opts gitea.CreateIssueOption) (*gitea.Issue, error) {
|
|
issue, _, err := c.api.CreateIssue(owner, repo, opts)
|
|
if err != nil {
|
|
return nil, log.E("gitea.CreateIssue", "failed to create issue", err)
|
|
}
|
|
|
|
return issue, nil
|
|
}
|
|
|
|
// ListPullRequests returns pull requests for the given repository.
|
|
func (c *Client) ListPullRequests(owner, repo string, state string) ([]*gitea.PullRequest, error) {
|
|
st := gitea.StateOpen
|
|
switch state {
|
|
case "closed":
|
|
st = gitea.StateClosed
|
|
case "all":
|
|
st = gitea.StateAll
|
|
}
|
|
|
|
var all []*gitea.PullRequest
|
|
page := 1
|
|
|
|
for {
|
|
prs, resp, err := c.api.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
|
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
|
State: st,
|
|
})
|
|
if err != nil {
|
|
return nil, log.E("gitea.ListPullRequests", "failed to list pull requests", err)
|
|
}
|
|
|
|
all = append(all, prs...)
|
|
|
|
if resp == nil || page >= resp.LastPage {
|
|
break
|
|
}
|
|
page++
|
|
}
|
|
|
|
return all, nil
|
|
}
|
|
|
|
// GetPullRequest returns a single pull request by number.
|
|
func (c *Client) GetPullRequest(owner, repo string, number int64) (*gitea.PullRequest, error) {
|
|
pr, _, err := c.api.GetPullRequest(owner, repo, number)
|
|
if err != nil {
|
|
return nil, log.E("gitea.GetPullRequest", "failed to get pull request", err)
|
|
}
|
|
|
|
return pr, nil
|
|
}
|