]> source.dussan.org Git - gitea.git/commitdiff
Assign pull request to project during creation (#28227)
authorDenys Konovalov <kontakt@denyskon.de>
Fri, 12 Jan 2024 15:25:15 +0000 (16:25 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 15:25:15 +0000 (15:25 +0000)
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)

routers/web/repo/compare.go
routers/web/repo/pull.go

index f3b95b68fe5a2b47fc6184a767c0b3785a18f563..042b8ed692acfcf2be00d7c1d518f619a8dc736b 100644 (file)
@@ -845,6 +845,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 39f9cefa5c6699703790c15338e1bf671c9706cd..a7e703d01c8d636d7aa90d3d0d611be96ba911a8 100644 (file)
@@ -1387,7 +1387,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
        }
@@ -1465,6 +1465,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(ctx, 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())
 }