mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
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>
67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
gitea "gitea.dev/sdk"
|
|
)
|
|
|
|
// 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 IsNotFound(err) {
|
|
return IssueDependencies{}, nil
|
|
}
|
|
if err != nil {
|
|
return IssueDependencies{}, err
|
|
}
|
|
*list.dest = items
|
|
}
|
|
return result, nil
|
|
}
|