Skip to content

Commit

Permalink
Merge pull request #1680 from bmsareias/fix-UptadeProtectedBranch
Browse files Browse the repository at this point in the history
Fix uptade protected branch
  • Loading branch information
svanharmelen committed Mar 31, 2023
2 parents 71bce5a + 34980c2 commit b88a1b2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gitlab.go
Expand Up @@ -568,7 +568,7 @@ func (c *Client) NewRequest(method, path string, opt interface{}, options []Requ

var body interface{}
switch {
case method == http.MethodPost || method == http.MethodPut:
case method == http.MethodPatch || method == http.MethodPost || method == http.MethodPut:
reqHeaders.Set("Content-Type", "application/json")

if opt != nil {
Expand Down
5 changes: 1 addition & 4 deletions project_managed_licenses_test.go
Expand Up @@ -124,10 +124,7 @@ func TestEditManagedLicenses(t *testing.T) {

mux.HandleFunc("/api/v4/projects/1/managed_licenses/3", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
approvalStatus := r.URL.Query().Get("approval_status")
if approvalStatus != "blacklisted" {
t.Errorf("query param approval_status should be blacklisted but was %s", approvalStatus)
}
testBody(t, r, `{"approval_status":"blacklisted"}`)
mustWriteHTTPResponse(t, w, "testdata/edit_project_managed_license.json")
})

Expand Down
2 changes: 2 additions & 0 deletions protected_branches.go
Expand Up @@ -140,10 +140,12 @@ type ProtectRepositoryBranchesOptions struct {
// GitLab API docs:
// https://docs.gitlab.com/ee/api/protected_branches.html#protect-repository-branches
type BranchPermissionOptions struct {
ID *int `url:"id,omitempty" json:"id,omitempty"`
UserID *int `url:"user_id,omitempty" json:"user_id,omitempty"`
GroupID *int `url:"group_id,omitempty" json:"group_id,omitempty"`
DeployKeyID *int `url:"deploy_key_id,omitempty" json:"deploy_key_id,omitempty"`
AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
Destroy *bool `url:"_destroy,omitempty" json:"_destroy,omitempty"`
}

// ProtectRepositoryBranches protects a single repository branch or several
Expand Down
5 changes: 1 addition & 4 deletions protected_branches_test.go
Expand Up @@ -188,10 +188,7 @@ func TestUpdateRepositoryBranches(t *testing.T) {

mux.HandleFunc("/api/v4/projects/1/protected_branches/master", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
codeApprovalQueryParam := r.URL.Query().Get("code_owner_approval_required")
if codeApprovalQueryParam != "true" {
t.Errorf("query param code_owner_approval_required should be true but was %s", codeApprovalQueryParam)
}
testBody(t, r, `{"code_owner_approval_required":true}`)
fmt.Fprintf(w, `{
"name": "master",
"code_owner_approval_required": true
Expand Down

0 comments on commit b88a1b2

Please sign in to comment.