Skip to content

Commit

Permalink
Fix lakectl branch protection set 400 response (#7590)
Browse files Browse the repository at this point in the history
* Fix lakectl branch protection set 400 response

* pr comments
  • Loading branch information
itaiad200 authored Mar 24, 2024
1 parent aae8b80 commit b821b82
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/lakectl/cmd/branch_protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ var branchProtectAddCmd = &cobra.Command{
rules = append(rules, apigen.BranchProtectionRule{
Pattern: args[1],
})
setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, &apigen.SetBranchProtectionRulesParams{
IfMatch: swag.String(resp.HTTPResponse.Header.Get("ETag")),
}, rules)
params := &apigen.SetBranchProtectionRulesParams{}
etag := swag.String(resp.HTTPResponse.Header.Get("ETag"))
if etag != nil && *etag != "" {
params.IfMatch = etag
}
setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, params, rules)
DieOnErrorOrUnexpectedStatusCode(setResp, err, http.StatusNoContent)
},
}
Expand Down
2 changes: 2 additions & 0 deletions esti/golden/lakectl_branch_protection_list.term.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${BRANCH}

14 changes: 14 additions & 0 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,17 @@ func TestLakectlUsage(t *testing.T) {
runCmd(t, r.Replace("{lakectl} repo list"), false, false, nil)
RunCmdAndVerifyFailureWithFile(t, r.Replace("{lakectl} usage summary"), false, "lakectl_usage_summary", vars)
}

func TestLakectlBranchProtection(t *testing.T) {
repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
}
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, "lakectl_repo_create", vars)

RunCmdAndVerifySuccessWithFile(t, Lakectl()+" branch-protect add lakefs://"+repoName+" "+mainBranch, false, "lakectl_empty", vars)
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" branch-protect list lakefs://"+repoName, false, "lakectl_branch_protection_list.term", vars)
}

0 comments on commit b821b82

Please sign in to comment.