Skip to content

Commit

Permalink
fix: return empty list when branching is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Feb 13, 2024
1 parent ca68e2e commit 29c9f93
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/provider/branch_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -110,6 +111,10 @@ func (d *BranchDataSource) Read(ctx context.Context, req datasource.ReadRequest,
resp.Diagnostics.AddError("Client Error", msg)
return
}
// Create an empty array if branching is disabled
if httpResp.StatusCode() == http.StatusUnprocessableEntity {
httpResp.JSON200 = &[]api.BranchResponse{}
}
if httpResp.JSON200 == nil {
msg := fmt.Sprintf("Unable to read branch, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
resp.Diagnostics.AddError("Client Error", msg)
Expand Down

0 comments on commit 29c9f93

Please sign in to comment.