]> source.dussan.org Git - gitea.git/commitdiff
Assign pull request to project during creation (#28227) (#28775)
authorGiteabot <teabot@gitea.io>
Fri, 12 Jan 2024 21:53:16 +0000 (05:53 +0800)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 21:53:16 +0000 (21:53 +0000)
Backport #28227 by @denyskon

When creating a pull request, allow directly assigning it to a project,
as it is already possible for issues.

After:

![grafik](https://github.com/go-gitea/gitea/assets/47871822/01dc2b3d-d56a-4053-b2fc-138725d7633a)

---------

Co-authored-by: Denys Konovalov <kontakt@denyskon.de>
Co-authored-by: delvh <dev.lh@web.de>
routers/web/repo/compare.go
routers/web/repo/pull.go

index fc5f82ec0673c2a408343a07570c29f0732c211e..b0d93fc7b05f874e7bb651560e427441a2e78c37 100644 (file)
@@ -844,6 +844,7 @@ func CompareDiff(ctx *context.Context) {
                }
        }
 
+       ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanWrite(unit.TypeProjects)
        ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
        upload.AddUploadContext(ctx, "comment")
 
index 0f1491ae809391c74b12ad886080785e90588234..29d17d2e656a0fc4b7859ca1c11626654c7e1182 100644 (file)
@@ -1371,7 +1371,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
                return
        }
 
-       labelIDs, assigneeIDs, milestoneID, _ := ValidateRepoMetas(ctx, *form, true)
+       labelIDs, assigneeIDs, milestoneID, projectID := ValidateRepoMetas(ctx, *form, true)
        if ctx.Written() {
                return
        }
@@ -1449,6 +1449,17 @@ func CompareAndPullRequestPost(ctx *context.Context) {
                return
        }
 
+       if projectID > 0 {
+               if !ctx.Repo.CanWrite(unit.TypeProjects) {
+                       ctx.Error(http.StatusBadRequest, "user hasn't the permission to write to projects")
+                       return
+               }
+               if err := issues_model.ChangeProjectAssign(pullIssue, ctx.Doer, projectID); err != nil {
+                       ctx.ServerError("ChangeProjectAssign", err)
+                       return
+               }
+       }
+
        log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
        ctx.JSONRedirect(pullIssue.Link())
 }