Skip to content

Commit c1019c3

Browse files
committed
Remove repository target after thorough testing that it doesn't do anything
Signed-off-by: Timo Sand <[email protected]>
1 parent fe27c4d commit c1019c3

3 files changed

Lines changed: 12 additions & 65 deletions

File tree

github/repository_rules_validation_utils.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,3 @@ func validateConditionsFieldForPushTarget(ctx context.Context, conditions map[st
155155
tflog.Debug(ctx, "Conditions validation passed for push target")
156156
return nil
157157
}
158-
159-
func validateConditionsFieldForRepositoryTarget(ctx context.Context, conditions map[string]any) error {
160-
tflog.Debug(ctx, "Validating conditions field for repository target", map[string]any{"target": "repository", "conditions": conditions})
161-
162-
if conditions["ref_name"] != nil && len(conditions["ref_name"].([]any)) > 0 {
163-
tflog.Debug(ctx, "Invalid ref_name for repository target", map[string]any{"ref_name": conditions["ref_name"]})
164-
return fmt.Errorf("ref_name must not be set for repository target")
165-
}
166-
if conditions["repository_name"] == nil || len(conditions["repository_name"].([]any)) == 0 || conditions["repository_id"] == nil || len(conditions["repository_id"].([]any)) == 0 {
167-
return fmt.Errorf("one of repository_name or repository_id must be set for repository target")
168-
}
169-
tflog.Debug(ctx, "Conditions validation passed for repository target")
170-
return nil
171-
}

github/resource_github_organization_ruleset.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
4141
Description: "The name of the ruleset.",
4242
},
4343
"target": {
44-
Type: schema.TypeString,
45-
Required: true,
46-
ValidateFunc: validation.StringInSlice([]string{"branch", "tag", "push", "repository"}, false),
47-
Description: "The target of the ruleset. Possible values are `branch`, `tag`, `push` and `repository`.",
44+
Type: schema.TypeString,
45+
Required: true,
46+
// The API accepts an `repository` target, but any rule created with that doesn't show up in the UI, nor does it have any rules.
47+
ValidateFunc: validation.StringInSlice([]string{"branch", "tag", "push"}, false),
48+
Description: "The target of the ruleset. Possible values are `branch`, `tag` and `push`.",
4849
},
4950
"enforcement": {
5051
Type: schema.TypeString,
@@ -94,7 +95,7 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
9495
Type: schema.TypeList,
9596
Optional: true,
9697
MaxItems: 1,
97-
Description: "Parameters for an organization ruleset condition. `ref_name` is required for `branch` and `tag` targets, but must not be set for `push` or `repository` targets. One of `repository_name` or `repository_id` is always required.",
98+
Description: "Parameters for an organization ruleset condition. `ref_name` is required for `branch` and `tag` targets, but must not be set for `push` targets. One of `repository_name` or `repository_id` is always required.",
9899
Elem: &schema.Resource{
99100
Schema: map[string]*schema.Schema{
100101
"ref_name": {
@@ -861,8 +862,6 @@ func validateConditionsFieldBasedOnTarget(ctx context.Context, d *schema.Resourc
861862
return validateConditionsFieldForBranchAndTagTargets(ctx, target, conditions)
862863
case "push":
863864
return validateConditionsFieldForPushTarget(ctx, conditions)
864-
case "repository":
865-
return validateConditionsFieldForRepositoryTarget(ctx, conditions)
866865
}
867866
return nil
868867
}

github/resource_github_organization_ruleset_test.go

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ name: Echo Workflow
3636
on: [pull_request]
3737
3838
jobs:
39-
echo:
40-
runs-on: linux
41-
steps:
42-
- run: echo \"Hello, world!\"
39+
echo:
40+
runs-on: linux
41+
steps:
42+
- run: echo \"Hello, world!\"
4343
EOT
4444
commit_message = "Managed by Terraform"
4545
commit_author = "Terraform User"
@@ -673,9 +673,9 @@ resource "github_organization_ruleset" "test" {
673673
})
674674
})
675675

676-
t.Run("creates_push_ruleset_with_only_repository_name", func(t *testing.T) {
676+
t.Run("creates_push_ruleset", func(t *testing.T) {
677677
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
678-
resourceName := "test-push-repo-name-only"
678+
resourceName := "test-push-ruleset"
679679
config := fmt.Sprintf(`
680680
resource "github_organization_ruleset" "%s" {
681681
name = "test-push-%s"
@@ -816,44 +816,6 @@ resource "github_organization_ruleset" "test" {
816816
})
817817
})
818818
})
819-
820-
t.Run("validates_repository_target_rejects_ref_name", func(t *testing.T) {
821-
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
822-
resourceName := "test-repository-reject-ref-name"
823-
config := fmt.Sprintf(`
824-
resource "github_organization_ruleset" "%s" {
825-
name = "test-repo-with-ref-%s"
826-
target = "repository"
827-
enforcement = "active"
828-
829-
conditions {
830-
ref_name {
831-
include = ["~ALL"]
832-
exclude = []
833-
}
834-
repository_name {
835-
include = ["~ALL"]
836-
exclude = []
837-
}
838-
}
839-
840-
rules {
841-
creation = true
842-
}
843-
}
844-
`, resourceName, randomID)
845-
846-
resource.Test(t, resource.TestCase{
847-
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
848-
ProviderFactories: providerFactories,
849-
Steps: []resource.TestStep{
850-
{
851-
Config: config,
852-
ExpectError: regexp.MustCompile("ref_name must not be set for repository target"),
853-
},
854-
},
855-
})
856-
})
857819
}
858820

859821
func TestOrganizationPushRulesetSupport(t *testing.T) {

0 commit comments

Comments
 (0)