forked from kevadesu/forgejo
Support org labels when adding labels by label names (#32988)
Fix #32891 (cherry picked from commit 44b4fb21a4e99f327303f66cc7e48f7ca7ba09e1)
This commit is contained in:
parent
2ffa9a5e6e
commit
92ac337263
4 changed files with 50 additions and 10 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue