c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/db"
|
|
issues_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/issues"
|
|
user_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/user"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/base"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/services/context"
|
|
)
|
|
|
|
// PrepareFilterIssueLabels reads the "labels" query parameter, sets `ctx.Data["Labels"]` and `ctx.Data["SelectLabels"]`
|
|
func PrepareFilterIssueLabels(ctx *context.Context, repoID int64, owner *user_model.User) (ret struct {
|
|
AllLabels []*issues_model.Label
|
|
SelectedLabelIDs []int64
|
|
},
|
|
) {
|
|
// 1,-2 means including label 1 and excluding label 2
|
|
// 0 means issues with no label
|
|
// blank means labels will not be filtered for issues
|
|
selectLabels := ctx.FormString("labels")
|
|
if selectLabels != "" {
|
|
var err error
|
|
ret.SelectedLabelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ","))
|
|
if err != nil {
|
|
ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true)
|
|
}
|
|
}
|
|
|
|
var allLabels []*issues_model.Label
|
|
if repoID != 0 {
|
|
repoLabels, err := issues_model.GetLabelsByRepoID(ctx, repoID, "", db.ListOptions{})
|
|
if err != nil {
|
|
ctx.ServerError("GetLabelsByRepoID", err)
|
|
return ret
|
|
}
|
|
allLabels = append(allLabels, repoLabels...)
|
|
}
|
|
|
|
if owner != nil && owner.IsOrganization() {
|
|
orgLabels, err := issues_model.GetLabelsByOrgID(ctx, owner.ID, "", db.ListOptions{})
|
|
if err != nil {
|
|
ctx.ServerError("GetLabelsByOrgID", err)
|
|
return ret
|
|
}
|
|
allLabels = append(allLabels, orgLabels...)
|
|
}
|
|
|
|
// Get the exclusive scope for every label ID
|
|
labelExclusiveScopes := make([]string, 0, len(ret.SelectedLabelIDs))
|
|
for _, labelID := range ret.SelectedLabelIDs {
|
|
foundExclusiveScope := false
|
|
for _, label := range allLabels {
|
|
if label.ID == labelID || label.ID == -labelID {
|
|
labelExclusiveScopes = append(labelExclusiveScopes, label.ExclusiveScope())
|
|
foundExclusiveScope = true
|
|
break
|
|
}
|
|
}
|
|
if !foundExclusiveScope {
|
|
labelExclusiveScopes = append(labelExclusiveScopes, "")
|
|
}
|
|
}
|
|
|
|
for _, l := range allLabels {
|
|
l.LoadSelectedLabelsAfterClick(ret.SelectedLabelIDs, labelExclusiveScopes)
|
|
}
|
|
ctx.Data["Labels"] = allLabels
|
|
ctx.Data["SelectLabels"] = selectLabels
|
|
ret.AllLabels = allLabels
|
|
return ret
|
|
}
|