0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-02-24 16:57:27 +01:00

Fix load label for project

This commit is contained in:
Lunny Xiao 2025-12-29 13:42:57 -08:00
parent 48e144d015
commit a6806c65b5
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
5 changed files with 48 additions and 30 deletions

View File

@ -11,7 +11,6 @@ import (
"strings"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
project_model "code.gitea.io/gitea/models/project"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/templates"
@ -222,24 +221,11 @@ func WorkflowsColumns(ctx *context.Context, project *project_model.Project) {
}
func WorkflowsLabels(ctx *context.Context, project *project_model.Project) {
var labels []*issues_model.Label
orgLabels, err := issues_model.GetLabelsByOrgID(ctx, project.OwnerID, "", db.ListOptionsAll)
labels, err := project_service.GetProjectLabels(ctx, project)
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
ctx.ServerError("GetProjectLabels", err)
return
}
labels = append(labels, orgLabels...)
if project.Type == project_model.TypeRepository {
// Get repository labels
repoLabels, err := issues_model.GetLabelsByRepoID(ctx, project.RepoID, "", db.ListOptionsAll)
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
}
labels = append(labels, repoLabels...)
}
type Label struct {
ID int64 `json:"id"`

View File

@ -362,22 +362,12 @@ func ViewProject(ctx *context.Context) {
}
ctx.Data["LinkedPRs"] = linkedPrsMap
labels, err := issues_model.GetLabelsByRepoID(ctx, project.RepoID, "", db.ListOptions{})
labels, err := project_service.GetProjectLabels(ctx, project)
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
ctx.ServerError("GetProjectLabels", err)
return
}
if ctx.Repo.Owner.IsOrganization() {
orgLabels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
}
labels = append(labels, orgLabels...)
}
// Get the exclusive scope for every label ID
labelExclusiveScopes := make([]string, 0, len(preparedLabelFilter.SelectedLabelIDs))
for _, labelID := range preparedLabelFilter.SelectedLabelIDs {

View File

@ -0,0 +1,42 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package projects
import (
"context"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
project_model "code.gitea.io/gitea/models/project"
)
func GetProjectLabels(ctx context.Context, project *project_model.Project) ([]*issues_model.Label, error) {
var labels []*issues_model.Label
switch project.Type {
case project_model.TypeOrganization, project_model.TypeIndividual:
orgLabels, err := issues_model.GetLabelsByOrgID(ctx, project.OwnerID, "", db.ListOptionsAll)
if err != nil {
return nil, err
}
labels = append(labels, orgLabels...)
case project_model.TypeRepository:
// Get repository labels
repoLabels, err := issues_model.GetLabelsByRepoID(ctx, project.RepoID, "", db.ListOptionsAll)
if err != nil {
return nil, err
}
labels = append(labels, repoLabels...)
if err := project.LoadRepo(ctx); err != nil {
return nil, err
}
orgLabels, err := issues_model.GetLabelsByOrgID(ctx, project.Repo.OwnerID, "", db.ListOptionsAll)
if err != nil {
return nil, err
}
labels = append(labels, orgLabels...)
}
return labels, nil
}

View File

@ -1,5 +1,5 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content organization repository projects view-project">
<div role="main" aria-label="{{.Title}}" class="page-content organization repository projects projects-view">
{{if .ContextUser.IsOrganization}}
{{template "org/header" .}}
{{else}}

View File

@ -1,5 +1,5 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository projects view-project">
<div role="main" aria-label="{{.Title}}" class="page-content repository projects projects-view">
{{template "repo/header" .}}
<div class="ui container padded">
<div class="tw-flex tw-justify-between tw-items-center tw-mb-4">