mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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.
			
			
This commit is contained in:
		@@ -241,10 +241,26 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		labelIDs = make([]int64, len(labels))
 | 
							labelIDs = make([]int64, len(form.Labels))
 | 
				
			||||||
 | 
							orgLabelIDs := make([]int64, len(form.Labels))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for i := range labels {
 | 
							for i := range labels {
 | 
				
			||||||
			labelIDs[i] = labels[i].ID
 | 
								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 {
 | 
						if form.Milestone > 0 {
 | 
				
			||||||
@@ -452,6 +468,17 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
 | 
				
			|||||||
			ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err)
 | 
								ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err)
 | 
				
			||||||
			return
 | 
								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 {
 | 
							if err = issue.ReplaceLabels(labels, ctx.User); err != nil {
 | 
				
			||||||
			ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
 | 
								ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user