From 0e9c9947585baac717d28b532079178df6742996 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 27 Jan 2023 16:36:11 +0100 Subject: [PATCH 1/2] Fix missing message in git hook when pull request disabled on fork And also the other way around, it would show an non-working URL in the message when pull requests are disabled on the base repository but enabled on the fork. --- routers/private/hook_post_receive.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index c62038899d71..06076ffdfe56 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -173,13 +173,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { return } - if !repo.AllowsPulls() { - // We can stop there's no need to go any further - ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ - RepoWasEmpty: wasEmpty, - }) - return - } baseRepo = repo if repo.IsFork { @@ -193,6 +186,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { } baseRepo = repo.BaseRepo } + + if !baseRepo.AllowsPulls() { + // We can stop there's no need to go any further + ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ + RepoWasEmpty: wasEmpty, + }) + return + } } // If our branch is the default branch of an unforked repo - there's no PR to create or refer to @@ -217,14 +218,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch) } results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), Create: true, Branch: branch, URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)), }) } else { results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), Create: false, Branch: branch, URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index), From c88d0faa2cac6924367797a5e1fd16c54df41bc5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 28 Jan 2023 02:27:52 +0100 Subject: [PATCH 2/2] Show a link to merge into fork if pull requests in base repo are disabled --- routers/private/hook_post_receive.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 06076ffdfe56..75de47bdc4b2 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -184,7 +184,9 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { }) return } - baseRepo = repo.BaseRepo + if repo.BaseRepo.AllowsPulls() { + baseRepo = repo.BaseRepo + } } if !baseRepo.AllowsPulls() {