Skip to content

feat: add repository_property condition support for organization rulesets#3235

Closed
mkushakov wants to merge 2 commits intointegrations:mainfrom
mkushakov:feat/org-ruleset-repository-property-conditions
Closed

feat: add repository_property condition support for organization rulesets#3235
mkushakov wants to merge 2 commits intointegrations:mainfrom
mkushakov:feat/org-ruleset-repository-property-conditions

Conversation

@mkushakov
Copy link
Copy Markdown

Summary

Add support for the repository_property condition type in organization rulesets, allowing users to target repositories based on custom or system properties instead of only by name or ID.

Resolves #2137
Resolves #2594

Motivation

Organization rulesets currently only support targeting repositories by repository_name or repository_id. The GitHub API also supports repository_property conditions, which allow matching repositories based on their custom properties (e.g., targeting all repos with team = "platform" or environment = "production").

This is particularly useful for large organizations that use custom properties to categorize repositories, as it enables dynamic ruleset targeting without maintaining explicit name/ID lists.

Changes

Schema (resource_github_organization_ruleset.go)

  • Added repository_property block to the conditions schema with:
    • include — list of property targets that must all match
    • exclude — list of property targets that must not match
    • Each target contains property_name (string), property_value (list of strings), and source (optional, "custom" or "system", defaults to "custom")
  • Fixed condition constraints: replaced broken ExactlyOneOf/AtLeastOneOf with proper ConflictsWith/AtLeastOneOf across all three condition types (repository_name, repository_id, repository_property) — exactly one of the three must be specified

Expand/Flatten (util_rules.go)

  • Added expand logic in expandConditions to convert the repository_property schema block to github.RepositoryRulesetRepositoryPropertyConditionParameters API type
  • Added flatten logic in flattenConditions to convert the API response back to the schema format

Example Usage

resource "github_organization_ruleset" "example" {
  name        = "example"
  target      = "branch"
  enforcement = "active"

  conditions {
    ref_name {
      include = ["~DEFAULT_BRANCH"]
      exclude = []
    }
    repository_property {
      include {
        property_name  = "environment"
        property_value = ["production"]
      }
      include {
        property_name  = "team"
        property_value = ["platform", "infrastructure"]
        source         = "custom"
      }
      exclude {
        property_name  = "archived"
        property_value = ["true"]
        source         = "system"
      }
    }
  }

  rules {
    required_signatures = true
  }
}

Testing

  • go build ./... — passes
  • go vet ./... — passes
  • Uses existing go-github v83 types (RepositoryRulesetRepositoryPropertyConditionParameters, RepositoryRulesetRepositoryPropertyTargetParameters)

Add support for the repository_property condition type in organization
rulesets, allowing users to target repositories based on custom or system
properties instead of only by name or ID.

Changes:
- Add repository_property block to conditions schema with include/exclude
  sub-blocks supporting property_name, property_value, and source fields
- Add expand logic in expandConditions to convert schema to API types
- Add flatten logic in flattenConditions to convert API types back to schema
- Fix condition constraints: replace broken ExactlyOneOf/AtLeastOneOf with
  proper ConflictsWith/AtLeastOneOf across repository_name, repository_id,
  and repository_property (exactly one of the three must be specified)

Resolves integrations#2137
Resolves integrations#2594
@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-actions github-actions Bot added the Type: Feature New feature or request label Feb 27, 2026
@jack-sdx
Copy link
Copy Markdown

I'm looking forward to this one 👀

@deiga
Copy link
Copy Markdown
Collaborator

deiga commented Mar 20, 2026

Duplicate of #2356
Please provide comments or suggestion in that PR if it doesn't cover your need

@deiga deiga closed this Mar 20, 2026
Moser-ss added a commit to Pipedrive-OSS/terraform-provider-github that referenced this pull request Mar 20, 2026
…ory conditions

ExactlyOneOf has known issues with nested optional list blocks in Terraform SDK.
Use ConflictsWith + AtLeastOneOf pattern for reliable "exactly one" validation
across repository_name, repository_id, and repository_property conditions.

Updated test expectations to match new error message format from ConflictsWith.

Addresses feedback from PR integrations#2356 comment r2968116244, references fix from integrations#3235
stevehipwell pushed a commit that referenced this pull request Mar 23, 2026
…2356)

* Define schema for repository_property

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

* Apply format in the code base

* Fix repository_property validation and docs

  - 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

* Support repository_property in push rulesets

* Remove unused customdiff imports

* Replace custom validation with built-in ExactlyOneOf for repo targeting

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 #2356 review feedback - simplifies validation using schema constraints.

* Rever unintencial change

* Add tests, docs, and fix default handling for repository_property

- 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

* Apply suggestions from PR comment

* Add unit tests

* Remove redundant condition

* Updated description based in the GitHub API docs

* Apply linter and fmt

* Remove unnecessary checks

* Remove tests

These tests check validation that was handover to the Terraform built-in validation

* Improve syntax for include and exclude property

Improve e2e tests for the ruleset and improve documentation

* Use t context

* Rewrite tests using the resource_github_organization_custom_properties

Setup the tests case using the config instead of using the API

* Refactor repository property names in organization ruleset tests for consistency

* Refactor tests to use state checks for repository property validation in organization ruleset

* Update repository property references to use default_branch in organization ruleset tests

* Fix: Replace ExactlyOneOf with ConflictsWith/AtLeastOneOf for repository conditions

ExactlyOneOf has known issues with nested optional list blocks in Terraform SDK.
Use ConflictsWith + AtLeastOneOf pattern for reliable "exactly one" validation
across repository_name, repository_id, and repository_property conditions.

Updated test expectations to match new error message format from ConflictsWith.

Addresses feedback from PR #2356 comment r2968116244, references fix from #3235

* Apply lint
@mkushakov mkushakov deleted the feat/org-ruleset-repository-property-conditions branch April 1, 2026 07:24
JiayangZhou pushed a commit to JiayangZhou/terraform-provider-github that referenced this pull request Apr 16, 2026
…ntegrations#2356)

* Define schema for repository_property

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

* Apply format in the code base

* Fix repository_property validation and docs

  - 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

* Support repository_property in push rulesets

* Remove unused customdiff imports

* Replace custom validation with built-in ExactlyOneOf for repo targeting

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.

* Rever unintencial change

* Add tests, docs, and fix default handling for repository_property

- 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

* Apply suggestions from PR comment

* Add unit tests

* Remove redundant condition

* Updated description based in the GitHub API docs

* Apply linter and fmt

* Remove unnecessary checks

* Remove tests

These tests check validation that was handover to the Terraform built-in validation

* Improve syntax for include and exclude property

Improve e2e tests for the ruleset and improve documentation

* Use t context

* Rewrite tests using the resource_github_organization_custom_properties

Setup the tests case using the config instead of using the API

* Refactor repository property names in organization ruleset tests for consistency

* Refactor tests to use state checks for repository property validation in organization ruleset

* Update repository property references to use default_branch in organization ruleset tests

* Fix: Replace ExactlyOneOf with ConflictsWith/AtLeastOneOf for repository conditions

ExactlyOneOf has known issues with nested optional list blocks in Terraform SDK.
Use ConflictsWith + AtLeastOneOf pattern for reliable "exactly one" validation
across repository_name, repository_id, and repository_property conditions.

Updated test expectations to match new error message format from ConflictsWith.

Addresses feedback from PR integrations#2356 comment r2968116244, references fix from integrations#3235

* Apply lint
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

None yet

3 participants