Skip to content
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
3 changes: 2 additions & 1 deletion routers/api/v1/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ func EditBranchProtection(ctx *context.APIContext) {
if form.EnableStatusCheck != nil {
protectBranch.EnableStatusCheck = *form.EnableStatusCheck
}
if protectBranch.EnableStatusCheck {

if form.StatusCheckContexts != nil {
protectBranch.StatusCheckContexts = form.StatusCheckContexts
}

Expand Down
22 changes: 21 additions & 1 deletion tests/integration/api_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
assert.True(t, branch.UserCanMerge)
}

func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) *api.BranchProtection {
token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
resp := MakeRequest(t, req, expectedHTTPStatus)
Expand All @@ -40,7 +40,9 @@ func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPSta
var branchProtection api.BranchProtection
DecodeJSON(t, resp, &branchProtection)
assert.EqualValues(t, branchName, branchProtection.RuleName)
return &branchProtection
}
return nil
}

func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
Expand Down Expand Up @@ -186,6 +188,24 @@ func TestAPIBranchProtection(t *testing.T) {
EnablePush: true,
}, http.StatusOK)

// enable status checks, require the "test1" check to pass
testAPIEditBranchProtection(t, "master", &api.BranchProtection{
EnableStatusCheck: true,
StatusCheckContexts: []string{"test1"},
}, http.StatusOK)
bp := testAPIGetBranchProtection(t, "master", http.StatusOK)
assert.Equal(t, true, bp.EnableStatusCheck)
assert.Equal(t, []string{"test1"}, bp.StatusCheckContexts)

// disable status checks, clear the list of required checks
testAPIEditBranchProtection(t, "master", &api.BranchProtection{
EnableStatusCheck: false,
StatusCheckContexts: []string{},
}, http.StatusOK)
bp = testAPIGetBranchProtection(t, "master", http.StatusOK)
assert.Equal(t, false, bp.EnableStatusCheck)
assert.Equal(t, []string{}, bp.StatusCheckContexts)

testAPIDeleteBranchProtection(t, "master", http.StatusNoContent)

// Test branch deletion
Expand Down