diff options
author | Zettat123 <zettat123@gmail.com> | 2024-12-27 03:14:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-26 19:14:49 +0000 |
commit | 44b4fb21a4e99f327303f66cc7e48f7ca7ba09e1 (patch) | |
tree | 7cc0bffc471dd61adf2dafc38a91348f74c9ef45 /routers/api/v1 | |
parent | 7bb7ba1b5b70eb9ad984eaeeabecc1dcc2a26eb9 (diff) | |
download | gitea-44b4fb21a4e99f327303f66cc7e48f7ca7ba09e1.tar.gz gitea-44b4fb21a4e99f327303f66cc7e48f7ca7ba09e1.zip |
Support org labels when adding labels by label names (#32988)
Fix #32891
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/repo/issue_label.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go index a2c81ceb16..ee1a842bc6 100644 --- a/routers/api/v1/repo/issue_label.go +++ b/routers/api/v1/repo/issue_label.go @@ -335,6 +335,9 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) labelIDs = append(labelIDs, int64(rv.Float())) case reflect.String: labelNames = append(labelNames, rv.String()) + default: + ctx.Error(http.StatusBadRequest, "InvalidLabel", "a label must be an integer or a string") + return nil, nil, fmt.Errorf("invalid label") } } if len(labelIDs) > 0 && len(labelNames) > 0 { @@ -342,11 +345,20 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) return nil, nil, fmt.Errorf("invalid labels") } if len(labelNames) > 0 { - labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames) + repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err) return nil, nil, err } + labelIDs = append(labelIDs, repoLabelIDs...) + if ctx.Repo.Owner.IsOrganization() { + orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetLabelIDsInOrgByNames", err) + return nil, nil, err + } + labelIDs = append(labelIDs, orgLabelIDs...) + } } labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive") |