diff options
author | Giteabot <teabot@gitea.io> | 2024-01-13 05:53:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-12 21:53:16 +0000 |
commit | 80e564087dc1a89b8b74abcdc879c2de444d3278 (patch) | |
tree | e0ada99b77057385f285cfa1f0ea4e75a3fd7a07 | |
parent | 571822b6eca07832f6b5ff633bec8ab8fdb32624 (diff) | |
download | gitea-80e564087dc1a89b8b74abcdc879c2de444d3278.tar.gz gitea-80e564087dc1a89b8b74abcdc879c2de444d3278.zip |
Assign pull request to project during creation (#28227) (#28775)
Backport #28227 by @denyskon
When creating a pull request, allow directly assigning it to a project,
as it is already possible for issues.
After:

---------
Co-authored-by: Denys Konovalov <kontakt@denyskon.de>
Co-authored-by: delvh <dev.lh@web.de>
-rw-r--r-- | routers/web/repo/compare.go | 1 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index fc5f82ec06..b0d93fc7b0 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -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") diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 0f1491ae80..29d17d2e65 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -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()) } |