From e9560351b0a3dd56f1bc13ef2d6b121264a3262d Mon Sep 17 00:00:00 2001 From: johnnyaug Date: Wed, 27 Sep 2023 18:23:35 +0300 Subject: [PATCH] cr fix: use DeleteFunc --- cmd/lakectl/cmd/branch_protect.go | 14 ++++++++------ pkg/graveler/branch/protection_manager.go | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index 87a2860fffd..989ad65b0a3 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -6,6 +6,7 @@ import ( "github.com/go-openapi/swag" "github.com/spf13/cobra" "github.com/treeverse/lakefs/pkg/api/apigen" + "golang.org/x/exp/slices" ) const ( @@ -80,14 +81,15 @@ var branchProtectDeleteCmd = &cobra.Command{ u := MustParseRepoURI("repository", args[0]) resp, err := client.GetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository) DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) - rules := *resp.JSON200 - for i, rule := range *resp.JSON200 { + found := false + rules := slices.DeleteFunc(*resp.JSON200, func(rule apigen.BranchProtectionRule) bool { if rule.Pattern == args[1] { - rules = append(rules[:i], rules[i+1:]...) - break + found = true + return true } - } - if len(rules) == len(*resp.JSON200) { + return false + }) + if !found { Die("Branch protection rule not found", 1) } setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, &apigen.SetBranchProtectionRulesParams{ diff --git a/pkg/graveler/branch/protection_manager.go b/pkg/graveler/branch/protection_manager.go index d6a3df26055..18394f84dae 100644 --- a/pkg/graveler/branch/protection_manager.go +++ b/pkg/graveler/branch/protection_manager.go @@ -64,7 +64,6 @@ func (m *ProtectionManager) GetRules(ctx context.Context, repository *graveler.R } func (m *ProtectionManager) SetRules(ctx context.Context, repository *graveler.RepositoryRecord, rules *graveler.BranchProtectionRules) error { return m.settingManager.Save(ctx, repository, ProtectionSettingKey, rules) - } func (m *ProtectionManager) SetRulesIf(ctx context.Context, repository *graveler.RepositoryRecord, rules *graveler.BranchProtectionRules, ifMatchETag string) error {