Skip to content

Conversation

@deiga
Copy link
Contributor

@deiga deiga commented Dec 2, 2025

Warning

This PR is "stacked" on top of #2976
Currently relevant commits are after 3752c16 (This might link to correct changeset: https://github.com/integrations/terraform-provider-github/pull/2958/files/519ea54cdb3035806fb28caa2ab6fd0002209b0f..97e235105dcd2dafd1606451729325de56a694c9)

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

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

"ref_name": {
Type: schema.TypeList,
Required: true,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

This is a non breaking change ➕

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

var ruleset *github.RepositoryRuleset

ruleset, _, err = client.Organizations.UpdateRepositoryRuleset(ctx, org, rulesetID, *rulesetReq)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking if the bypass actors have changed and the length is 0 here would allow you to use the clear function to resolve #2952. See #2891 (comment).

@deiga deiga force-pushed the org-ruleset-fix-push branch from 1bdfa45 to efd67ae Compare December 7, 2025 00:20
deiga added 23 commits December 7, 2025 16:48
…sport`

Updated the logging transport in the RateLimitedHTTPClient function to use NewLoggingHTTPTransport. As the subsystem would need to be explicitly inititated in each resource

Signed-off-by: Timo Sand <[email protected]>
By using the `*Context` CRUD functions we get context pass-through and enable HTTP Req/Resp Debug logging

Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
It's a required field in the API and go-github doesn't use `omitempty`, so it submits `nil` if it isn't sent explicitly.

This change tries to keep it in the state, without having a configuration option for it (poor choice?)

And it defaults to all 3 available merge methods if it can't set something from the state.

Signed-off-by: Timo Sand <[email protected]>
This is a required field and the SDK doesn't omit if it's empty

Signed-off-by: Timo Sand <[email protected]>
This enables better debugging during tests as we are able to use get logs for HTTP req/resp

Signed-off-by: Timo Sand <[email protected]>
…on_rulesets_without_errors` to pass

Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
…_all_bypass_modes`

Main fix: `bypass_actors` is returned as sorted from GH API so tests need re-indexing

Signed-off-by: Timo Sand <[email protected]>
deiga added 23 commits December 7, 2025 20:58
Signed-off-by: Timo Sand <[email protected]>
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]>
By using the `*Context` CRUD functions we get context pass-through and enable HTTP Req/Resp Debug logging

Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
@deiga deiga changed the title Fix github_organization_ruleset with push target [MAINT] Fix github_organization_ruleset with push target Dec 7, 2025
deiga added 2 commits December 8, 2025 15:40
Signed-off-by: Timo Sand <[email protected]>
@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?

client.Transport = NewEtagTransport(client.Transport)
client.Transport = NewRateLimitTransport(client.Transport, WithWriteDelay(writeDelay), WithReadDelay(readDelay), WithParallelRequests(parallelRequests))
client.Transport = logging.NewSubsystemLoggingHTTPTransport("GitHub", client.Transport)
client.Transport = logging.NewLoggingHTTPTransport(client.Transport)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain why we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't inititialize the GitHub subsystem anywhere and from my understanding subsystems are usually per-resource things.
With an unitialized Subsystem the logs get spammed with warnings about it.

But this implementation is "actually" in this PR #2976 and any modifications to it should happen there

},
"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

@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 :)

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