Skip to content

Commit

Permalink
Sync branches first (#29714)
Browse files Browse the repository at this point in the history
Follow #29493.

Sync branches to DB first, then trigger push events.
  • Loading branch information
wolfogre authored Mar 11, 2024
1 parent 4129e0e commit e6d1411
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions routers/private/hook_post_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
}

if repo != nil && len(updates) > 0 {
if err := repo_service.PushUpdates(updates); err != nil {
log.Error("Failed to Update: %s/%s Total Updates: %d", ownerName, repoName, len(updates))
for i, update := range updates {
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.RefFullName.BranchName())
}
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)

ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
})
return
}

branchesToSync := make([]*repo_module.PushUpdateOptions, 0, len(updates))
for _, update := range updates {
if !update.RefFullName.IsBranch() {
Expand Down Expand Up @@ -151,6 +138,19 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
return
}
}

if err := repo_service.PushUpdates(updates); err != nil {
log.Error("Failed to Update: %s/%s Total Updates: %d", ownerName, repoName, len(updates))
for i, update := range updates {
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.RefFullName.BranchName())
}
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)

ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
})
return
}
}

// Handle Push Options
Expand Down

0 comments on commit e6d1411

Please sign in to comment.