mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor: add services layer on the Gitea Go SDK (#1125)
- `internal/services`: typed Gitea workflows built on `gitea.dev/sdk`, independent of CLI flags and terminal I/O: issues, pull requests, reviews, comments, labels, milestones, releases and assets, repositories, branches, wiki, Actions (workflows, runs, jobs, logs, artifacts, secrets, variables), organizations, teams, webhooks, notifications, SSH keys, tracked time, admin users, search and status. - SDK types are mapped to tea's own output types, so `--json` stays a stable contract. Requests the SDK cannot express yet (e.g. pull list filters, multi-status run lists, org label archiving) go through small raw helpers, each marked `TODO(sdk)` with the missing SDK piece. - Targets Gitea 28 or newer: no version or API-schema probing. List helpers fill pages capped by `MAX_RESPONSE_ITEMS`. Nothing imports this package yet. Reviewed-on: https://gitea.com/gitea/tea/pulls/1125 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
This commit is contained in:
1 parent
faea86cd94
commit
12e415a7a7
80 files changed
+9512
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
"gitea.dev/tea/internal/transport"
|
||||
)
|
||||
|
||||
// IssueReference identifies an issue that may live in another repository.
|
||||
// Number is zero for issues the account cannot read.
|
||||
type IssueReference struct {
|
||||
Repository string
|
||||
Number int64
|
||||
}
|
||||
|
||||
// IssueDependencies lists the issues blocking one issue and the issues it blocks.
|
||||
type IssueDependencies struct {
|
||||
BlockedBy, Blocks []IssueReference
|
||||
}
|
||||
|
||||
func issueReferenceFrom(issue *gitea.Issue) IssueReference {
|
||||
reference := IssueReference{Number: issue.Index}
|
||||
if issue.Repository != nil {
|
||||
reference.Repository = issue.Repository.FullName
|
||||
}
|
||||
return reference
|
||||
}
|
||||
|
||||
// Dependencies reads both dependency directions; servers or repositories without
|
||||
// dependency support report none.
|
||||
func (s Issues) Dependencies(ctx context.Context, number int64) (IssueDependencies, error) {
|
||||
owner, repo, err := splitRepository(s.Repository)
|
||||
if err != nil {
|
||||
return IssueDependencies{}, err
|
||||
}
|
||||
result := IssueDependencies{}
|
||||
for _, list := range []struct {
|
||||
fetch func(ctx context.Context, c *gitea.Client, opts gitea.ListOptions) ([]*gitea.Issue, *gitea.Response, error)
|
||||
dest *[]IssueReference
|
||||
}{
|
||||
{func(ctx context.Context, c *gitea.Client, opts gitea.ListOptions) ([]*gitea.Issue, *gitea.Response, error) {
|
||||
return c.Issues.ListIssueDependencies(ctx, owner, repo, number, gitea.ListIssueDependenciesOptions{ListOptions: opts})
|
||||
}, &result.BlockedBy},
|
||||
{func(ctx context.Context, c *gitea.Client, opts gitea.ListOptions) ([]*gitea.Issue, *gitea.Response, error) {
|
||||
return c.Issues.ListIssueBlocks(ctx, owner, repo, number, gitea.ListIssueBlocksOptions{ListOptions: opts})
|
||||
}, &result.Blocks},
|
||||
} {
|
||||
items, err := listAll(func(page int) ([]IssueReference, error) {
|
||||
issues, _, err := call(ctx, s.Client, func(ctx context.Context, c *gitea.Client) ([]*gitea.Issue, *gitea.Response, error) {
|
||||
return list.fetch(ctx, c, listOptions(50, page))
|
||||
})
|
||||
return convertAll(issues, issueReferenceFrom), err
|
||||
})
|
||||
if api, ok := errors.AsType[*transport.APIError](err); ok && api.Status == http.StatusNotFound {
|
||||
return IssueDependencies{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return IssueDependencies{}, err
|
||||
}
|
||||
*list.dest = items
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in new issue
Block a user