Skip to content

Commit

Permalink
cr fix: use DeleteFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyaug committed Sep 27, 2023
1 parent 41177d3 commit e956035
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 8 additions & 6 deletions cmd/lakectl/cmd/branch_protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion pkg/graveler/branch/protection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e956035

Please sign in to comment.