mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11: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,52 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// IssueTemplate is a repository issue template used to seed create forms.
|
||||
type IssueTemplate struct {
|
||||
Name, About, Title, Content string
|
||||
Form bool
|
||||
}
|
||||
|
||||
type issueTemplateResponse struct {
|
||||
Name string `json:"name"`
|
||||
About string `json:"about"`
|
||||
Title string `json:"title"`
|
||||
MarkdownContent string `json:"content"`
|
||||
Form []any `json:"body"`
|
||||
}
|
||||
|
||||
// IssueTemplates lists repository issue templates; null responses become an empty list.
|
||||
func (s Issues) IssueTemplates(ctx context.Context) ([]IssueTemplate, error) {
|
||||
var response []issueTemplateResponse
|
||||
// TODO(sdk): IssueFormElementAttributes.Options is []string, so GetIssueTemplates fails on checkbox options, which are objects.
|
||||
if err := getJSON(ctx, s.Client, "repos/"+s.Repository+"/issue_templates", &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]IssueTemplate, 0, len(response))
|
||||
for _, r := range response {
|
||||
result = append(result, IssueTemplate{Name: r.Name, About: r.About, Title: r.Title, Content: r.MarkdownContent, Form: r.Form != nil})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// IssueCreateSelectables adds repository issue templates to the create form choices.
|
||||
type IssueCreateSelectables struct {
|
||||
CreateSelectables
|
||||
Templates []IssueTemplate
|
||||
}
|
||||
|
||||
// CreateSelectables loads templates and, when the user can push, assignees/milestones/labels.
|
||||
func (s Issues) CreateSelectables(ctx context.Context) (IssueCreateSelectables, error) {
|
||||
choices, err := loadCreateSelectables(ctx, s.Client, s.Repository)
|
||||
if err != nil {
|
||||
return IssueCreateSelectables{}, err
|
||||
}
|
||||
templates, err := s.IssueTemplates(ctx)
|
||||
return IssueCreateSelectables{CreateSelectables: choices, Templates: templates}, err
|
||||
}
|
||||
Reference in new issue
Block a user