Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create and delete branch protection error and lakectl output #6135

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4435,6 +4435,8 @@ paths:
$ref: "#/components/responses/Unauthorized"
404:
$ref: "#/components/responses/NotFound"
409:
$ref: "#/components/responses/Conflict"
default:
$ref: "#/components/responses/ServerError"

Expand Down
6 changes: 6 additions & 0 deletions clients/java/api/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/java/docs/RepositoriesApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/python/docs/RepositoriesApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cmd/lakectl/cmd/branch_protect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"net/http"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -57,6 +58,7 @@ var branchProtectAddCmd = &cobra.Command{
Pattern: args[1],
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent)
fmt.Printf("Branch protection rule added to '%s' repository.\n", u.Repository)
},
}

Expand All @@ -74,6 +76,7 @@ var branchProtectDeleteCmd = &cobra.Command{
Pattern: args[1],
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent)
fmt.Printf("Branch protection rule deleted from '%s' repository.\n", u.Repository)
},
}

Expand Down
2 changes: 2 additions & 0 deletions docs/assets/js/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4435,6 +4435,8 @@ paths:
$ref: "#/components/responses/Unauthorized"
404:
$ref: "#/components/responses/NotFound"
409:
$ref: "#/components/responses/Conflict"
default:
$ref: "#/components/responses/ServerError"

Expand Down
8 changes: 6 additions & 2 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1731,9 +1731,9 @@ func (c *Controller) ListRepositoryRuns(w http.ResponseWriter, r *http.Request,
return
}

branch := StringValue(params.Branch)
branchName := StringValue(params.Branch)
commitID := StringValue(params.Commit)
runsIter, err := c.Actions.ListRunResults(ctx, repository, branch, commitID, paginationAfter(params.After))
runsIter, err := c.Actions.ListRunResults(ctx, repository, branchName, commitID, paginationAfter(params.After))
if c.handleAPIError(ctx, w, r, err) {
return
}
Expand Down Expand Up @@ -3064,6 +3064,8 @@ func (c *Controller) DeleteBranchProtectionRule(w http.ResponseWriter, r *http.R
return
}
ctx := r.Context()
c.LogAction(ctx, "delete_branch_protection_rule", r, repository, "", "")

err := c.Catalog.DeleteBranchProtectionRule(ctx, repository, body.Pattern)
if c.handleAPIError(ctx, w, r, err) {
return
Expand Down Expand Up @@ -3097,6 +3099,8 @@ func (c *Controller) CreateBranchProtectionRule(w http.ResponseWriter, r *http.R
return
}
ctx := r.Context()
c.LogAction(ctx, "create_branch_protection_rule", r, repository, "", "")

// For now, all protected branches use the same default set of blocked actions. In the future this set will be user configurable.
blockedActions := []graveler.BranchProtectionBlockedAction{graveler.BranchProtectionBlockedAction_STAGING_WRITE, graveler.BranchProtectionBlockedAction_COMMIT}
err := c.Catalog.CreateBranchProtectionRule(ctx, repository, body.Pattern, blockedActions)
Expand Down
4 changes: 2 additions & 2 deletions pkg/graveler/branch/protection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const (
)

var (
ErrRuleAlreadyExists = errors.New("branch protection rule already exists")
ErrRuleNotExists = errors.New("branch protection rule does not exist")
ErrRuleAlreadyExists = fmt.Errorf("branch protection rule already exists: %w", graveler.ErrNotUnique)
ErrRuleNotExists = fmt.Errorf("branch protection rule does not exist: %w", graveler.ErrNotFound)
)

type ProtectionManager struct {
Expand Down