Skip to content

Conversation

@deiga
Copy link
Contributor

@deiga deiga commented Dec 2, 2025

Resolves #2929, #2467


Before the change?

  • The provider would crash from a 422 error response when following the example in the docs
  • Removing ref_name would cause the provider to Panic as ref_name is a required field
  • One could add rules which weren't valid for push rulesets

After the change?

  • The provider should correctly apply push rulesets to an organization
  • ref_name should no longer be needed to be set for push target
  • conditions & target validation logic should ensure correct fields are populated

Pull request checklist

  • Schema migrations have been created if needed (example)
  • 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

Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

I think this change likely wants to wait for the SDK upgrade as a lot of this area is modified in future versions.

FYI the error behaviours previously seen should have been mitigated by #2705 so if there is an error the provider should handle it gracefully.

@deiga deiga force-pushed the org-ruleset-fix-push branch from 0531db8 to 9dd2965 Compare December 3, 2025 20:15
@deiga deiga changed the base branch from main to go-github-v68 December 3, 2025 20:15
@deiga deiga force-pushed the org-ruleset-fix-push branch from 1bdfa45 to efd67ae Compare December 7, 2025 00:20
@deiga deiga changed the title Fix github_organization_ruleset with push target [MAINT] Fix github_organization_ruleset with push target Dec 7, 2025
@deiga deiga force-pushed the org-ruleset-fix-push branch from 52d95d4 to 6782aab Compare December 8, 2025 13:42
Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Would it be possible to either de-scope this PR or open a new PR with the smallest number of changes possible to fix the outstanding bugs?

},
"bypass_actors": {
Type: schema.TypeList,
Type: schema.TypeList, // TODO: These are returned from GH API sorted by actor_id, we might want to investigate if we want to include sorting
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should sort the returned values based on the inputs which would stop churn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds sensible, need to investigate where the best place for the sorting is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stevehipwell after some investigation, it seems that schema.TypeSet would be the correct way to implement unsorted. What do you think?

@deiga
Copy link
Contributor Author

deiga commented Dec 10, 2025

@stevehipwell Yes, I agree. I've done that already in this PR: #2976

But I can't switch the base of this PR to point to that :)

@deiga deiga changed the title [MAINT] Fix github_organization_ruleset with push target [MAINT] Fix github_organization_ruleset and github_repository_ruleset with push target Dec 17, 2025
@deiga deiga marked this pull request as ready for review December 19, 2025 06:35
@deiga deiga marked this pull request as draft January 6, 2026 08:06
@deiga deiga changed the base branch from go-github-v68 to main January 7, 2026 22:14
@deiga deiga force-pushed the org-ruleset-fix-push branch from 10baa83 to 1fe74fc Compare January 8, 2026 23:33
deiga added 14 commits January 10, 2026 08:31
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
… to org rulesets will never be a thing

Signed-off-by: Timo Sand <[email protected]>
…re empty lists by default

Signed-off-by: Timo Sand <[email protected]>
deiga added 22 commits January 10, 2026 08:31
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
This turns out to be failing as there is a bug in our implementation! Unit tests and fix coming up

Signed-off-by: Timo Sand <[email protected]>
As they differ from `branch` and `tag` rules

Signed-off-by: Timo Sand <[email protected]>
…ved` repos to be private

This allows even EMU users to run these tests

Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
@deiga deiga force-pushed the org-ruleset-fix-push branch from 1fe74fc to 2a2277a Compare January 10, 2026 08:53
@deiga deiga marked this pull request as ready for review January 10, 2026 08:56
Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

I've added some review comments, mainly about the code structure.

@@ -0,0 +1,157 @@
package github
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure why we need this new file instead of using the util_rules.go file?

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 felt that util_rules.go is already getting too long to reason about nicely. But if this is an anti-pattern I can move these there

Comment on lines +31 to +34
CustomizeDiff: customdiff.All(
validateConditionsFieldBasedOnTarget,
validateOrganizationRulesetRules,
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should use separate function here as we're writing our own logic, that pattern is only really useful when we're composing. Could you take a look at how I've structured the schema and done this in #3069?

return []*schema.ResourceData{d}, nil
}

func validateConditionsFieldBasedOnTarget(ctx context.Context, d *schema.ResourceDiff, meta any) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is scoped to the organization ruleset then the name should reflect that, otherwise it should probably be in the util_rules.go file (idiomatically I'd expect this to be called util_ruleset.go).

}
`, resourceName, randomID)

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.

Can we please inline these instead of creating a separate var, this makes the code so much harder to read.

Comment on lines +703 to +707
resource.TestCheckResourceAttr(
fmt.Sprintf("github_organization_ruleset.%s", resourceName),
"name",
fmt.Sprintf("test-push-%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.

Suggested change
resource.TestCheckResourceAttr(
fmt.Sprintf("github_organization_ruleset.%s", resourceName),
"name",
fmt.Sprintf("test-push-%s", randomID),
),
resource.TestCheckResourceAttr(fmt.Sprintf("github_organization_ruleset.%s", resourceName), "name", fmt.Sprintf("test-push-%s", randomID)),

Please can these be made a single line, it's the idiomatic Go pattern (no introducing line breaks) and makes the code much easier to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: github_organization_ruleset doesn't work with push rulesets

3 participants