Skip to content

dependent issues support repo index or full index #29728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/references"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
Expand Down Expand Up @@ -2530,10 +2531,46 @@ func SearchIssues(ctx *context.Context) {
isClosed = optional.Some(false)
}

keyword := ctx.FormTrim("q")
if strings.IndexByte(keyword, 0) >= 0 {
keyword = ""
}

var (
repoIDs []int64
allPublic bool
repoIDs []int64
allPublic bool
matchedIssue *issues_model.Issue
)

priorityRepoID := ctx.FormInt64("priority_repo_id")

matched, ref := references.FindRenderizableReferenceNumeric(keyword, false, false)
if matched {
idx, err := strconv.ParseInt(ref.Issue, 10, 64)
if err != nil {
log.Error("Failed to parse issue number from reference: %v", err)
} else {
var repoID int64
if ref.Name != "" && ref.Owner != "" {
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, ref.Owner, ref.Name)
if err != nil {
log.Error("Failed to get repository by name: %v", err)
} else {
repoID = repo.ID
}
} else {
repoID = priorityRepoID
}

if repoID > 0 {
matchedIssue, err = issues_model.GetIssueByIndex(ctx, repoID, idx)
if err != nil {
log.Error("Failed to get issue by index: %v", err)
}
}
}
}

{
// find repos user can access (for issue search)
opts := &repo_model.SearchRepoOptions{
Expand Down Expand Up @@ -2597,11 +2634,6 @@ func SearchIssues(ctx *context.Context) {
}
}

keyword := ctx.FormTrim("q")
if strings.IndexByte(keyword, 0) >= 0 {
keyword = ""
}

isPull := optional.None[bool]()
switch ctx.FormString("type") {
case "pulls":
Expand All @@ -2612,7 +2644,6 @@ func SearchIssues(ctx *context.Context) {

var includedAnyLabels []int64
{

labels := ctx.FormTrim("labels")
var includedLabelNames []string
if len(labels) > 0 {
Expand Down Expand Up @@ -2697,8 +2728,6 @@ func SearchIssues(ctx *context.Context) {

// FIXME: It's unsupported to sort by priority repo when searching by indexer,
// it's indeed an regression, but I think it is worth to support filtering by indexer first.
_ = ctx.FormInt64("priority_repo_id")

ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
if err != nil {
ctx.Error(http.StatusInternalServerError, "SearchIssues", err.Error())
Expand All @@ -2709,8 +2738,11 @@ func SearchIssues(ctx *context.Context) {
ctx.Error(http.StatusInternalServerError, "FindIssuesByIDs", err.Error())
return
}
if matchedIssue != nil {
issues = append([]*issues_model.Issue{matchedIssue}, issues...)
}

ctx.SetTotalCountHeader(total)
ctx.SetTotalCountHeader(total + 1)
ctx.JSON(http.StatusOK, convert.ToIssueList(ctx, issues))
}

Expand Down