some improvements

This commit is contained in:
Lunny Xiao 2024-05-01 15:33:46 +08:00
parent 7c98b643b8
commit 6c44844222
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 59 additions and 58 deletions

View File

@ -104,7 +104,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
return
}
results := generateCompareLinks(ctx, opts, ownerName, repoName, wasEmpty)
results := generateBranchResults(ctx, opts, repo, ownerName, repoName, wasEmpty)
if ctx.Written() {
return
}
@ -229,9 +229,8 @@ func handlePushOptions(ctx *gitea_context.PrivateContext, opts *private.HookOpti
}
}
func generateCompareLinks(ctx *gitea_context.PrivateContext, opts *private.HookOptions, ownerName, repoName string, wasEmpty bool) []private.HookPostReceiveBranchResult {
func generateBranchResults(ctx *gitea_context.PrivateContext, opts *private.HookOptions, repo *repo_model.Repository, ownerName, repoName string, wasEmpty bool) []private.HookPostReceiveBranchResult {
results := make([]private.HookPostReceiveBranchResult, 0, len(opts.OldCommitIDs))
var repo *repo_model.Repository
var baseRepo *repo_model.Repository
// Now handle the pull request notification trailers
@ -240,7 +239,10 @@ func generateCompareLinks(ctx *gitea_context.PrivateContext, opts *private.HookO
newCommitID := opts.NewCommitIDs[i]
// If we've pushed a branch (and not deleted it)
if !git.IsEmptyCommitID(newCommitID) && refFullName.IsBranch() {
if !refFullName.IsBranch() || git.IsEmptyCommitID(newCommitID) {
continue
}
// First ensure we have the repository loaded, we're allowed pulls requests and we can get the base repo
if repo == nil {
repo = loadRepository(ctx, ownerName, repoName)
@ -311,7 +313,6 @@ func generateCompareLinks(ctx *gitea_context.PrivateContext, opts *private.HookO
})
}
}
}
return results
}