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
@@ -6,9 +6,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
@@ -81,17 +79,11 @@ func (s Wiki) page(ctx context.Context, op repoOperation[*gitea.WikiPage]) (Wiki
|
||||
return wikiContentFrom(page)
|
||||
}
|
||||
|
||||
// List returns a non-nil page of wiki metadata.
|
||||
func (s Wiki) List(ctx context.Context, limit, page int) ([]WikiPage, error) {
|
||||
window, err := s.ListPage(ctx, limit, page)
|
||||
return window.Items, err
|
||||
}
|
||||
|
||||
// wikiPageSize is the page size for reading the whole wiki; Gitea replaces a limit of 1 with its
|
||||
// default page size.
|
||||
const wikiPageSize = 50
|
||||
|
||||
// ListPage is List that also reports whether more pages follow and how many there are. It reads
|
||||
// ListPage lists a page of wiki pages, with whether more follow and how many there are. It reads
|
||||
// the whole page list and pages it on the client, because the server pages it inconsistently.
|
||||
func (s Wiki) ListPage(ctx context.Context, limit, page int) (Page[WikiPage], error) {
|
||||
all, err := listAll(func(page int) ([]*gitea.WikiPageMetaData, error) {
|
||||
@@ -100,7 +92,7 @@ func (s Wiki) ListPage(ctx context.Context, limit, page int) (Page[WikiPage], er
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
if apiError, ok := errors.AsType[*transport.APIError](err); !ok || apiError.Status != http.StatusNotFound {
|
||||
if !IsNotFound(err) {
|
||||
return Page[WikiPage]{}, err
|
||||
}
|
||||
// An uninitialized wiki returns 404. Verify repository visibility and
|
||||
|
||||
Reference in new issue
Block a user