Support org labels when adding labels by label names (#32988)

Fix #32891

(cherry picked from commit 44b4fb21a4e99f327303f66cc7e48f7ca7ba09e1)
This commit is contained in:
Zettat123 2024-12-27 03:14:49 +08:00 committed by Earl Warren
parent 2ffa9a5e6e
commit 92ac337263
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 50 additions and 10 deletions

View file

@ -350,6 +350,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 {
@ -357,11 +360,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")