Skip to content

Comments

feat : Support repository property for GitHub organization ruleset#2356

Open
Moser-ss wants to merge 20 commits intointegrations:mainfrom
Pipedrive-OSS:Support-repository_property-for-github_organization_ruleset
Open

feat : Support repository property for GitHub organization ruleset#2356
Moser-ss wants to merge 20 commits intointegrations:mainfrom
Pipedrive-OSS:Support-repository_property-for-github_organization_ruleset

Conversation

@Moser-ss
Copy link
Contributor

@Moser-ss Moser-ss commented Aug 20, 2024

Resolves #2137
Introduces the support to use repository_property to target repositories in the ruleset

The 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?

  • Cannot target ruleset using repository_property

After the change?

  • The ruleset can use the repository_property under the conditions block

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@Moser-ss Moser-ss marked this pull request as draft August 20, 2024 18:57
@Moser-ss Moser-ss marked this pull request as ready for review August 20, 2024 22:58
@Moser-ss Moser-ss force-pushed the Support-repository_property-for-github_organization_ruleset branch from bb62d7a to 40c5111 Compare August 28, 2024 13:17
@Moser-ss Moser-ss changed the title Support repository property for GitHub organization ruleset feat : Support repository property for GitHub organization ruleset Sep 3, 2024
@Moser-ss
Copy link
Contributor Author

Moser-ss commented Sep 7, 2024

@kfcampbell, could you take a quick look to see if I need to improve anything in this PR

Copy link
Contributor

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Have you looked at expanding the tests in github/resource_github_organization_ruleset_test.go to cover this usecase yet?

@Moser-ss
Copy link
Contributor Author

A test case was added, I hope the change was not to ugly

@Moser-ss
Copy link
Contributor Author

Moser-ss commented Oct 5, 2024

@kfcampbell can I do anything to speed up the review of this PR?

@stevehipwell
Copy link
Collaborator

@Moser-ss I think you need to update the docs to reflect these changes?

@Moser-ss
Copy link
Contributor Author

Moser-ss commented Nov 9, 2024

@stevehipwell Docs updated, thanks for catching that.

@wrighbr
Copy link

wrighbr commented Nov 14, 2024

@PaarthShah @kfcampbell Would you have an estimate on when this PR might be reviewed and merged?

@PaarthShah
Copy link

@PaarthShah @kfcampbell Would you have an estimate on when this PR might be reviewed and merged?

@wrighbr No idea, I'm not a maintainer 😅

@alexymantha
Copy link

alexymantha commented Dec 16, 2024

We also need this feature. It's been stale for a little while, anything we can do to get this merged?

@daniddelrio
Copy link

+1 on this PR. Would be great if this can get merged soon

@ChrisStatham
Copy link

@kfcampbell If you have a chance to review this feature it would be appreciated thanks!

@aditya-nair1
Copy link

aditya-nair1 commented Jan 7, 2025

@kfcampbell +1, thanks!

@vimc9
Copy link

vimc9 commented Jan 7, 2025

@kfcampbell would be grateful for your review here 🚀 🚀 🚀

@tayven-bigelow
Copy link

@kfcampbell - Any chance of getting a review / approval of this PR?

@graham1228
Copy link

➕ 1️⃣ on getting this merged. Would love to migrate our bash scripts to TF, but need this functionality.

@lfraile
Copy link

lfraile commented Apr 7, 2025

+1 On desperately needing this PR to get approved :(

@tayven-bigelow
Copy link

@kfcampbell - Is there any chance we could get this merged?
Is there something missing or any sort of directive as to why it hasn't been approved?

@stevehipwell
Copy link
Collaborator

@tayven-bigelow check out the commit history for this repo, I don't think GitHub are providing engineering resources here at the moment.

@loksonarius
Copy link

tyvm for setting up this PR, I really hope it merges in soon 🙏

@Maksym-Perehinets
Copy link

hi, is there any chance to get this one merged?
+1

@deiga
Copy link
Collaborator

deiga commented Nov 18, 2025

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?

@stevehipwell
Copy link
Collaborator

@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?

@Moser-ss
Copy link
Contributor Author

@stevehipwell The unit tests were fixed
basicaly I removed the test cases that were testing the validation, which was replaced with the built-in validation
I revisit the acceptance tests and rewrite the failing ones, and test locally against a test organization using the command

 GH_TEST_AUTH_MODE=team GITHUB_OWNER=pipedrive-lab GITHUB_USERNAME=moser-ss GITHUB_TOKEN="${GITHUB_TOKEN}" TF_ACC=1 go test ./github -v -run "TestAccGithubOrganizationRuleset" -count=1

We have two test failing, but those tests are also failing in main brach
image

t.Fatalf("Error getting test meta: %v", err)
}

ctx := context.Background()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx := context.Background()
ctx := t.Context()

Comment on lines 316 to 321
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,
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Any reason you don't use resource_github_organization_custom_properties in the test config?

Copy link
Contributor Author

@Moser-ss Moser-ss Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deiga I rewerite the tests to using the Config object to setup the test case, also rebase the branch from the main branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests are passing, expect the one that is already failing in main
image

Comment on lines 1061 to 1087
// 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)
}
}()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: What if you use resource_github_organization_custom_properties in the Config?

Moser-ss added a commit to Pipedrive-OSS/terraform-provider-github that referenced this pull request Feb 23, 2026
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.
@Moser-ss Moser-ss force-pushed the Support-repository_property-for-github_organization_ruleset branch from 383ba15 to d53f8e2 Compare February 23, 2026 10:24
@stevehipwell
Copy link
Collaborator

@deiga are you able to give this a re-review after the changes? I'll then review it once you're happy.

Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! There are some final touches for the tests left :)

conditions {
repository_property {
include = [{
name = "%[2]s"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By using a direct dependency you might not need depends_on

Suggested change
name = "%[2]s"
name = github_organization_custom_properties.team.property_name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests updated

repository_property {
include = []
exclude = [{
name = "%[2]s"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository_property {
include = [
{
name = "%[2]s"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property_values = ["production"]
},
{
name = "%[3]s"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Please prepend this and other propnames with testResourcePrefix to enable adding a Sweeper for these in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@Moser-ss Moser-ss force-pushed the Support-repository_property-for-github_organization_ruleset branch from d53f8e2 to 91298ad Compare February 23, 2026 23:42
@Moser-ss Moser-ss requested a review from deiga February 23, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

Status: BLOCKED

Development

Successfully merging this pull request may close these issues.

[FEAT]: Support targeting dynamic list by properties in organizational rulesets