From 3703e11845cf479c398663a44a7684f225ba2161 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Sat, 2 May 2026 03:55:04 -0700 Subject: [PATCH 1/3] github_repository_custom_property: avoid panic on empty property_value Signed-off-by: SAY-5 --- github/resource_github_repository_custom_property.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/github/resource_github_repository_custom_property.go b/github/resource_github_repository_custom_property.go index 9da207a1be..8c6d3ce8c6 100644 --- a/github/resource_github_repository_custom_property.go +++ b/github/resource_github_repository_custom_property.go @@ -69,6 +69,9 @@ func resourceGithubRepositoryCustomPropertyCreate(d *schema.ResourceData, meta a // The propertyValue can either be a list of strings or a string switch propertyType { case github.PropertyValueTypeString, github.PropertyValueTypeSingleSelect, github.PropertyValueTypeURL, github.PropertyValueTypeTrueFalse: + if len(propertyValue) == 0 { + return fmt.Errorf("property_value must contain at least one element for property_type %q", propertyType) + } customProperty.Value = propertyValue[0] case github.PropertyValueTypeMultiSelect: customProperty.Value = propertyValue From c3fd60eccce8c70fca76b95b18d703033a2176f0 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Sun, 10 May 2026 14:43:29 -0700 Subject: [PATCH 2/3] github_repository_custom_property: add regression test for empty property_value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pin the panic guard for #3358: the Create path used to index propertyValue[0] without a length check, crashing the provider when the dynamic-block source produced an empty list despite the schema's MinItems=1. Reach the guarded branch from a unit test by passing a nil v3client meta — the empty-list check fires before any API call. Signed-off-by: SAY-5 --- ...ub_repository_custom_property_unit_test.go | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 github/resource_github_repository_custom_property_unit_test.go diff --git a/github/resource_github_repository_custom_property_unit_test.go b/github/resource_github_repository_custom_property_unit_test.go new file mode 100644 index 0000000000..f6b17f28e7 --- /dev/null +++ b/github/resource_github_repository_custom_property_unit_test.go @@ -0,0 +1,50 @@ +package github + +import ( + "strings" + "testing" + + "github.com/google/go-github/v85/github" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// TestResourceGithubRepositoryCustomPropertyCreate_EmptyValueRejectsCleanly +// pins the panic guard for #3358: when property_value resolves to an empty +// list at apply time (which can happen despite the schema's MinItems=1 when +// the value comes from a dynamic block whose source is empty), the Create +// path used to index propertyValue[0] and crash the provider with +// "index out of range [0] with length 0". The fix returns a clear error +// for the single-value property types instead. This unit test reaches that +// branch without going through the GitHub API by passing a nil v3client +// in the meta — the guard fires before any client call. +func TestResourceGithubRepositoryCustomPropertyCreate_EmptyValueRejectsCleanly(t *testing.T) { + singleValueTypes := []github.PropertyValueType{ + github.PropertyValueTypeString, + github.PropertyValueTypeSingleSelect, + github.PropertyValueTypeURL, + github.PropertyValueTypeTrueFalse, + } + + res := resourceGithubRepositoryCustomProperty() + + for _, pt := range singleValueTypes { + t.Run(string(pt), func(t *testing.T) { + d := schema.TestResourceDataRaw(t, res.Schema, map[string]any{ + "repository": "some-repo", + "property_name": "test-property", + "property_type": string(pt), + "property_value": []any{}, + }) + + meta := &Owner{name: "test-owner"} + err := resourceGithubRepositoryCustomPropertyCreate(d, meta) + + if err == nil { + t.Fatalf("expected error for empty property_value with type %q, got nil", pt) + } + if !strings.Contains(err.Error(), "property_value") { + t.Errorf("expected error to mention property_value, got: %v", err) + } + }) + } +} From 239487ac0ea9cb9dcd30e5da9c3d13fbdddd54ab Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Mon, 11 May 2026 13:01:55 -0700 Subject: [PATCH 3/3] chore: remove em-dashes from comments --- github/resource_github_repository_custom_property_unit_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_repository_custom_property_unit_test.go b/github/resource_github_repository_custom_property_unit_test.go index f6b17f28e7..f2f424d7c2 100644 --- a/github/resource_github_repository_custom_property_unit_test.go +++ b/github/resource_github_repository_custom_property_unit_test.go @@ -16,7 +16,7 @@ import ( // "index out of range [0] with length 0". The fix returns a clear error // for the single-value property types instead. This unit test reaches that // branch without going through the GitHub API by passing a nil v3client -// in the meta — the guard fires before any client call. +// in the meta, the guard fires before any client call. func TestResourceGithubRepositoryCustomPropertyCreate_EmptyValueRejectsCleanly(t *testing.T) { singleValueTypes := []github.PropertyValueType{ github.PropertyValueTypeString,