Skip to content

Commit

Permalink
Fix missing message in git hook when pull requests disabled on fork (#…
Browse files Browse the repository at this point in the history
…22625) (#22658)

Backport #22625

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
  • Loading branch information
jolheiser and brechtvl committed Jan 30, 2023
1 parent a9ba737 commit e6d6bce
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions routers/private/hook_post_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,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 {
Expand All @@ -192,7 +185,17 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
})
return
}
baseRepo = repo.BaseRepo
if repo.BaseRepo.AllowsPulls() {
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
}
}

Expand All @@ -218,14 +221,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),
Expand Down

0 comments on commit e6d6bce

Please sign in to comment.