Skip to content

Commit 0e9c994

Browse files
committed
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.
1 parent 5ff037e commit 0e9c994

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

routers/private/hook_post_receive.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
173173
return
174174
}
175175

176-
if !repo.AllowsPulls() {
177-
// We can stop there's no need to go any further
178-
ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
179-
RepoWasEmpty: wasEmpty,
180-
})
181-
return
182-
}
183176
baseRepo = repo
184177

185178
if repo.IsFork {
@@ -193,6 +186,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
193186
}
194187
baseRepo = repo.BaseRepo
195188
}
189+
190+
if !baseRepo.AllowsPulls() {
191+
// We can stop there's no need to go any further
192+
ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
193+
RepoWasEmpty: wasEmpty,
194+
})
195+
return
196+
}
196197
}
197198

198199
// 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) {
217218
branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch)
218219
}
219220
results = append(results, private.HookPostReceiveBranchResult{
220-
Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(),
221+
Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(),
221222
Create: true,
222223
Branch: branch,
223224
URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)),
224225
})
225226
} else {
226227
results = append(results, private.HookPostReceiveBranchResult{
227-
Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(),
228+
Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(),
228229
Create: false,
229230
Branch: branch,
230231
URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index),

0 commit comments

Comments
 (0)