Skip to content

Commit 19b2b7c

Browse files
committed
form expect struct
1 parent ae19b8e commit 19b2b7c

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

routers/web/repo/setting/protected_branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ func DeleteProtectedBranchRulePost(ctx *context.Context) {
322322
}
323323

324324
func UpdateBranchProtectionPriories(ctx *context.Context) {
325-
form := web.GetForm(ctx).([]int64)
325+
form := web.GetForm(ctx).(*forms.ProtectBranchPriorityForm)
326326
repo := ctx.Repo.Repository
327327

328-
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form); err != nil {
328+
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDS); err != nil {
329329
ctx.ServerError("UpdateProtectBranchPriorities", err)
330330
return
331331
}

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ func registerRoutes(m *web.Router) {
10751075
m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch).
10761076
Post(web.Bind(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost)
10771077
m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost)
1078-
m.Post("/priority", web.Bind([]int64{}), context.RepoMustNotBeArchived(), repo_setting.UpdateBranchProtectionPriories)
1078+
m.Post("/priority", web.Bind(forms.ProtectBranchPriorityForm{}), context.RepoMustNotBeArchived(), repo_setting.UpdateBranchProtectionPriories)
10791079
})
10801080

10811081
m.Group("/tags", func() {

services/forms/repo_form.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) bin
227227
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
228228
}
229229

230+
type ProtectBranchPriorityForm struct {
231+
IDS []int64
232+
}
233+
230234
// __ __ ___. .__ __
231235
// / \ / \ ____\_ |__ | |__ ____ ____ | | __
232236
// \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /

web_src/js/features/repo-settings-branches.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ export function initRepoBranchesSettings() {
99
handle: '.drag-handle',
1010
animation: 150,
1111
onEnd: async (evt) => {
12-
const newOrder = Array.from(protectedBranchesList.children).map((item) => item.dataset.id);
12+
const newOrder = Array.from(protectedBranchesList.children).map((item) => {
13+
const id = item.dataset.id;
14+
return id ? parseInt(id, 10) : NaN;
15+
}).filter(id => !isNaN(id));
16+
1317
try {
1418
await POST(protectedBranchesList.getAttribute('data-priority-url'), {
15-
data: newOrder,
19+
data: {
20+
ids: newOrder,
21+
},
1622
});
1723
} catch (err) {
1824
console.error('Failed to update branch protection rule priority:', err);

0 commit comments

Comments
 (0)