diff options
author | CirnoT <1447794+CirnoT@users.noreply.github.com> | 2020-04-20 15:10:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 14:10:45 +0100 |
commit | d2693f18de2bd85f9e2e700bef5f38270a9e5591 (patch) | |
tree | c7b77b4b3031aad505764af5a7d04b9c2898bb09 /routers | |
parent | 5bfb9bc2b6a2e10d8f0fcdd2cc1e93de39a58555 (diff) | |
download | gitea-d2693f18de2bd85f9e2e700bef5f38270a9e5591.tar.gz gitea-d2693f18de2bd85f9e2e700bef5f38270a9e5591.zip |
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.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/pull.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index b23d502c6f..db0b14bd70 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -241,10 +241,26 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption return } - labelIDs = make([]int64, len(labels)) + labelIDs = make([]int64, len(form.Labels)) + orgLabelIDs := make([]int64, len(form.Labels)) + for i := range labels { labelIDs[i] = labels[i].ID } + + if ctx.Repo.Owner.IsOrganization() { + orgLabels, err := models.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err) + return + } + + for i := range orgLabels { + orgLabelIDs[i] = orgLabels[i].ID + } + } + + labelIDs = append(labelIDs, orgLabelIDs...) } if form.Milestone > 0 { @@ -452,6 +468,17 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err) return } + + if ctx.Repo.Owner.IsOrganization() { + orgLabels, err := models.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err) + return + } + + labels = append(labels, orgLabels...) + } + if err = issue.ReplaceLabels(labels, ctx.User); err != nil { ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err) return |