feat : Support repository property for GitHub organization ruleset#2356
feat : Support repository property for GitHub organization ruleset#2356Moser-ss wants to merge 20 commits intointegrations:mainfrom
Conversation
bb62d7a to
40c5111
Compare
|
@kfcampbell, could you take a quick look to see if I need to improve anything in this PR |
kfcampbell
left a comment
There was a problem hiding this comment.
Thanks! Have you looked at expanding the tests in github/resource_github_organization_ruleset_test.go to cover this usecase yet?
|
A test case was added, I hope the change was not to ugly |
|
@kfcampbell can I do anything to speed up the review of this PR? |
|
@Moser-ss I think you need to update the docs to reflect these changes? |
|
@stevehipwell Docs updated, thanks for catching that. |
|
@PaarthShah @kfcampbell Would you have an estimate on when this PR might be reviewed and merged? |
@wrighbr No idea, I'm not a maintainer 😅 |
|
We also need this feature. It's been stale for a little while, anything we can do to get this merged? |
|
+1 on this PR. Would be great if this can get merged soon |
|
@kfcampbell If you have a chance to review this feature it would be appreciated thanks! |
|
@kfcampbell +1, thanks! |
|
@kfcampbell would be grateful for your review here 🚀 🚀 🚀 |
|
@kfcampbell - Any chance of getting a review / approval of this PR? |
|
➕ 1️⃣ on getting this merged. Would love to migrate our bash scripts to TF, but need this functionality. |
|
+1 On desperately needing this PR to get approved :( |
|
@kfcampbell - Is there any chance we could get this merged? |
|
@tayven-bigelow check out the commit history for this repo, I don't think GitHub are providing engineering resources here at the moment. |
|
tyvm for setting up this PR, I really hope it merges in soon 🙏 |
|
hi, is there any chance to get this one merged? |
|
Hey there 👋 We're looking into getting this into a mergeable state :) This PR will need to wait until #2891 is merged as the ruleset resources in the SDK have changed. @Moser-ss Could you try rebasing and retargeting this branch to go-github-v68? |
|
@Moser-ss it looks like you need to fix some unit test failures. Also would it be possible for you to run the organization ruleset acceptance tests locally and provide a screenshot of what ran? |
|
@stevehipwell The unit tests were fixed We have two test failing, but those tests are also failing in main brach |
| t.Fatalf("Error getting test meta: %v", err) | ||
| } | ||
|
|
||
| ctx := context.Background() |
There was a problem hiding this comment.
| ctx := context.Background() | |
| ctx := t.Context() |
| for _, prop := range properties { | ||
| _, _, err := meta.v3client.Organizations.CreateOrUpdateCustomProperty(ctx, org, prop.name, &github.CustomProperty{ | ||
| ValueType: github.PropertyValueTypeSingleSelect, | ||
| Required: github.Ptr(false), | ||
| AllowedValues: prop.values, | ||
| }) |
There was a problem hiding this comment.
question: Any reason you don't use resource_github_organization_custom_properties in the test config?
There was a problem hiding this comment.
Do you mean to use Terraform to create the custom properties for the tests? I didn't think about that. In my mind, the test code creates all the necessary setup, executes the test case, and tears down the setup at the end.
But do you think that I should set up the test case in the Config or in the PreConfig?
I am afraid to add two actions in the same test case. For example, if we have an issue with the implementation of resource_github_organization_custom_properties, this test will fail. But that is just my way of thinking of having some kind of isolation of the tests.
There was a problem hiding this comment.
We use that pattern all over the tests already. I would even argue that having "unrelated" tests failing when some other resource implementation is broken is a benefit.
With your proposed solution we'd additionally have to ensure that this test setup code is kept up-to-date
There was a problem hiding this comment.
@deiga I rewerite the tests to using the Config object to setup the test case, also rebase the branch from the main branch
| // Setup: Create custom property for testing | ||
| meta, err := getTestMeta() | ||
| if err != nil { | ||
| t.Fatalf("Error getting test meta: %v", err) | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
| org := testAccConf.owner | ||
| propName := "e2e_test_environment" | ||
| propValues := []string{"production", "staging"} | ||
|
|
||
| _, _, err = meta.v3client.Organizations.CreateOrUpdateCustomProperty(ctx, org, propName, &github.CustomProperty{ | ||
| ValueType: github.PropertyValueTypeSingleSelect, | ||
| Required: github.Ptr(false), | ||
| AllowedValues: propValues, | ||
| }) | ||
| if err != nil { | ||
| t.Logf("Warning: Could not create custom property %s (may already exist): %v", propName, err) | ||
| } | ||
|
|
||
| // Cleanup: Remove custom property after test | ||
| defer func() { | ||
| _, err := meta.v3client.Organizations.RemoveCustomProperty(ctx, org, propName) | ||
| if err != nil { | ||
| t.Logf("Warning: Could not remove custom property %s: %v", propName, err) | ||
| } | ||
| }() |
There was a problem hiding this comment.
suggestion: What if you use resource_github_organization_custom_properties in the Config?
Add ExactlyOneOf/AtLeastOneOf to repository_property, repository_name,repository_id fields. Remove manual validation counting in util_ruleset_validation.Add 3 validation tests for single/multiple/missing repo targeting options. Addresses PR integrations#2356 review feedback - simplifies validation using schema constraints.
383ba15 to
d53f8e2
Compare
|
@deiga are you able to give this a re-review after the changes? I'll then review it once you're happy. |
deiga
left a comment
There was a problem hiding this comment.
Looking good! There are some final touches for the tests left :)
| conditions { | ||
| repository_property { | ||
| include = [{ | ||
| name = "%[2]s" |
There was a problem hiding this comment.
By using a direct dependency you might not need depends_on
| name = "%[2]s" | |
| name = github_organization_custom_properties.team.property_name |
| repository_property { | ||
| include = [] | ||
| exclude = [{ | ||
| name = "%[2]s" |
There was a problem hiding this comment.
| repository_property { | ||
| include = [ | ||
| { | ||
| name = "%[2]s" |
There was a problem hiding this comment.
| property_values = ["production"] | ||
| }, | ||
| { | ||
| name = "%[3]s" |
There was a problem hiding this comment.
| t.Run("create_ruleset_with_repository_property", func(t *testing.T) { | ||
| randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
| rulesetName := fmt.Sprintf("%s-repo-prop-ruleset-%s", testResourcePrefix, randomID) | ||
| propName := fmt.Sprintf("e2e_test_team_%s", randomID) |
There was a problem hiding this comment.
issue: Please prepend this and other propnames with testResourcePrefix to enable adding a Sweeper for these in the future
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: config, | ||
| Check: resource.ComposeTestCheckFunc( |
There was a problem hiding this comment.
Since there are other changes needed here, could you also replace the usages of Check with ConfigStateChecks (or ConfigPlantChecks where applicable)? https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/state-checks/resource
There was a problem hiding this comment.
I replaced Check with ConfigStateChecks in my tests. Do you want me to replace it in all tests in this file?
Refactor expandConditions to reduce complexity Refactor logic to reduce the cognitive complexity and add logic to handle the repository_property field Flatten conditions for repository_property and fix schemas Add test case when ruleset use repository_property Refactor repository property conditions to make them optional Flatten update Target parameters to allow the detection of changes when remote resource is updated Update documentation
- Add ValidateFunc to include.source field for consistency with exclude - Update docs to mention repository_property as third targeting option - Fix missing space in documentation
Add ExactlyOneOf/AtLeastOneOf to repository_property, repository_name,repository_id fields. Remove manual validation counting in util_ruleset_validation.Add 3 validation tests for single/multiple/missing repo targeting options. Addresses PR integrations#2356 review feedback - simplifies validation using schema constraints.
- Add doc example for repository_property usage - Add tests for exclude block, multiple properties, and updates - Fix source field default handling in flatten function to prevent diffs
These tests check validation that was handover to the Terraform built-in validation
Improve e2e tests for the ruleset and improve documentation
Setup the tests case using the config instead of using the API
… in organization ruleset
d53f8e2 to
91298ad
Compare


Resolves #2137
Introduces the support to use
repository_propertyto target repositories in the rulesetThe changes were manually tested against a GitHub Organization with an enterprise plan.
It is not possible to add properties with the source system because the lib version doesn't allow that. It is necessary to update to version v65
Before the change?
repository_propertyAfter the change?
repository_propertyunder the conditions blockPull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!