mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor: reuse the existing service and rendering helpers
services.IsNotFound replaces the hand-rolled 404 checks, convertPage the copied page conversions and lastPathNumber the comment's own number parser. The List wrappers around ListPage of releases, branches, wiki pages, secrets and variables go, pull request filters resolve milestones through Milestones.FindOne like issues, and localFlagsChanged, boolOrder, Cell.Render, stateBadge and dueText replace their copies. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
33 files changed
+85
-212
No files matched your search
@@ -34,7 +34,7 @@ func organization(ctx context.Context, client *transport.Client, owner string) (
|
||||
org, _, err := call(ctx, client, func(ctx context.Context, c *gitea.Client) (*gitea.Organization, *gitea.Response, error) {
|
||||
return c.Organizations.GetOrg(ctx, owner)
|
||||
})
|
||||
if statusNotFound(err) {
|
||||
if IsNotFound(err) {
|
||||
return 0, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
@@ -46,12 +46,6 @@ func organization(ctx context.Context, client *transport.Client, owner string) (
|
||||
return org.ID, true, nil
|
||||
}
|
||||
|
||||
// statusNotFound reports whether err is a 404 response.
|
||||
func statusNotFound(err error) bool {
|
||||
failure, ok := errors.AsType[*transport.APIError](err)
|
||||
return ok && failure.Status == http.StatusNotFound
|
||||
}
|
||||
|
||||
// OrganizationOptions permits explicit empty and false preference updates.
|
||||
type OrganizationOptions struct {
|
||||
Name *string `json:"username,omitempty"`
|
||||
@@ -84,11 +78,6 @@ func (s Organizations) List(ctx context.Context, mine bool, username string, lim
|
||||
return convertPage(orgs, organizationFrom), err
|
||||
}
|
||||
|
||||
// convertPage maps a page of SDK items onto tea results.
|
||||
func convertPage[S, T any](page Page[*S], convert func(*S) T) Page[T] {
|
||||
return Page[T]{Items: convertAll(page.Items, convert), More: page.More, Total: page.Total, Counted: page.Counted}
|
||||
}
|
||||
|
||||
// View retrieves a named organization.
|
||||
func (s Organizations) View(ctx context.Context, name string) (Organization, error) {
|
||||
org, _, err := call(ctx, s.Client, func(ctx context.Context, c *gitea.Client) (*gitea.Organization, *gitea.Response, error) {
|
||||
@@ -285,7 +274,7 @@ func (s Organizations) IsPublicMember(ctx context.Context, name, username string
|
||||
// check runs a membership check that answers no with a 404.
|
||||
func (s Organizations) check(ctx context.Context, op func(context.Context, *gitea.Client) (*gitea.Response, error)) (bool, error) {
|
||||
err := do(ctx, s.Client, op)
|
||||
if statusNotFound(err) {
|
||||
if IsNotFound(err) {
|
||||
return false, nil
|
||||
}
|
||||
return err == nil, err
|
||||
|
||||
Reference in new issue
Block a user