Skip to content

Commit e6d1411

Browse files
authored
Sync branches first (#29714)
Follow #29493. Sync branches to DB first, then trigger push events.
1 parent 4129e0e commit e6d1411

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

routers/private/hook_post_receive.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
8282
}
8383

8484
if repo != nil && len(updates) > 0 {
85-
if err := repo_service.PushUpdates(updates); err != nil {
86-
log.Error("Failed to Update: %s/%s Total Updates: %d", ownerName, repoName, len(updates))
87-
for i, update := range updates {
88-
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.RefFullName.BranchName())
89-
}
90-
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)
91-
92-
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
93-
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
94-
})
95-
return
96-
}
97-
9885
branchesToSync := make([]*repo_module.PushUpdateOptions, 0, len(updates))
9986
for _, update := range updates {
10087
if !update.RefFullName.IsBranch() {
@@ -151,6 +138,19 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
151138
return
152139
}
153140
}
141+
142+
if err := repo_service.PushUpdates(updates); err != nil {
143+
log.Error("Failed to Update: %s/%s Total Updates: %d", ownerName, repoName, len(updates))
144+
for i, update := range updates {
145+
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.RefFullName.BranchName())
146+
}
147+
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)
148+
149+
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
150+
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
151+
})
152+
return
153+
}
154154
}
155155

156156
// Handle Push Options

0 commit comments

Comments
 (0)