fix(labels): add org label for ls and pr (#1017)

Fix https://gitea.com/gitea/tea/issues/634, https://gitea.com/gitea/tea/issues/669

Reviewed-on: https://gitea.com/gitea/tea/pulls/1017
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Minjie Fang <wingsallen@gmail.com>
Co-committed-by: Minjie Fang <wingsallen@gmail.com>
This commit is contained in:
Minjie Fang
2026-06-24 17:46:12 +00:00
committed by Lunny Xiao
parent 5cfee362c8
commit 88f5cdcafa
8 changed files with 371 additions and 13 deletions
+8 -1
View File
@@ -5,8 +5,9 @@ package print
import (
"strconv"
"strings"
"gitea.dev/sdk"
gitea "gitea.dev/sdk"
)
// LabelsList prints a listing of labels
@@ -16,14 +17,20 @@ func LabelsList(labels []*gitea.Label, output string) error {
"Color",
"Name",
"Description",
"Level",
)
for _, label := range labels {
level := "Repository"
if strings.Contains(label.URL, "/orgs/") {
level = "Organization"
}
t.addRow(
strconv.FormatInt(label.ID, 10),
formatLabel(label, !isMachineReadable(output), label.Color),
label.Name,
label.Description,
level,
)
}
return t.print(output)
+10
View File
@@ -23,6 +23,16 @@ func ResolveLabelNames(requestCtx stdctx.Context, client *gitea.Client, owner, r
if err != nil {
return nil, err
}
if _, _, err := client.Organizations.GetOrg(requestCtx, owner); err == nil {
orgLabels, _, err := client.Organizations.ListOrgLabels(requestCtx, owner, gitea.ListOrgLabelsOptions{
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
})
if err != nil {
return nil, err
}
labels = append(labels, orgLabels...)
}
for _, l := range labels {
if utils.Contains(labelNames, l.Name) {
labelIDs = append(labelIDs, l.ID)