Skip to content

Commit d2693f1

Browse files
authored
Support organization labels for PRs in API (#11135)
Fix `/repos/{owner}/{repo}/pulls` and `/repos/{owner}/{repo}/pulls/{index}` to accept organization labels during PR creation and edition.
1 parent 5bfb9bc commit d2693f1

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

routers/api/v1/repo/pull.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,26 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
241241
return
242242
}
243243

244-
labelIDs = make([]int64, len(labels))
244+
labelIDs = make([]int64, len(form.Labels))
245+
orgLabelIDs := make([]int64, len(form.Labels))
246+
245247
for i := range labels {
246248
labelIDs[i] = labels[i].ID
247249
}
250+
251+
if ctx.Repo.Owner.IsOrganization() {
252+
orgLabels, err := models.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
253+
if err != nil {
254+
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
255+
return
256+
}
257+
258+
for i := range orgLabels {
259+
orgLabelIDs[i] = orgLabels[i].ID
260+
}
261+
}
262+
263+
labelIDs = append(labelIDs, orgLabelIDs...)
248264
}
249265

250266
if form.Milestone > 0 {
@@ -452,6 +468,17 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
452468
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err)
453469
return
454470
}
471+
472+
if ctx.Repo.Owner.IsOrganization() {
473+
orgLabels, err := models.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
474+
if err != nil {
475+
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
476+
return
477+
}
478+
479+
labels = append(labels, orgLabels...)
480+
}
481+
455482
if err = issue.ReplaceLabels(labels, ctx.User); err != nil {
456483
ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
457484
return

0 commit comments

Comments
 (0)