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
10 changes: 8 additions & 2 deletions internal/provider/branch_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,21 @@ func readBranchDatabase(ctx context.Context, state *BranchResourceModel, client
}

func createBranch(ctx context.Context, plan *BranchResourceModel, client *api.ClientWithResponses) diag.Diagnostics {
resp, err := client.V1ListAllBranches(ctx, plan.ParentProjectRef.ValueString())
resp, err := client.V1ListAllBranchesWithResponse(ctx, plan.ParentProjectRef.ValueString())
if err != nil {
msg := fmt.Sprintf("Unable to enable branching, got error: %s", err)
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}
// 1. Enable branching
if resp.StatusCode == http.StatusUnprocessableEntity {
if resp.StatusCode() == http.StatusOK && resp.JSON200 == nil {
msg := fmt.Sprintf("Unable to list branches, got status %d: %s", resp.StatusCode(), resp.Body)
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}
if resp.StatusCode() == http.StatusUnprocessableEntity ||
(resp.StatusCode() == http.StatusOK && len(*resp.JSON200) == 0) {
httpResp, err := client.V1CreateABranchWithResponse(ctx, plan.ParentProjectRef.ValueString(), api.CreateBranchBody{
BranchName: "Production",
IsDefault: Ptr(true),
})
if err != nil {
msg := fmt.Sprintf("Unable to enable branching, got error: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/branch_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func TestAccBranchResource(t *testing.T) {
// Step 1: create
gock.New(defaultApiEndpoint).
Get(branchesApiPath).
Reply(http.StatusUnprocessableEntity)
Reply(http.StatusOK).
JSON([]api.BranchResponse{})
gock.New(defaultApiEndpoint).
Post(branchesApiPath).
Reply(http.StatusCreated).
Expand Down