terraform-provider-github
terraform-provider-github copied to clipboard
[FEAT]: Support ruleset `allowed_merge_methods`
Describe the need
I want to be able to specify the allowed_merge_methods for both repo and org rulesets. This change depends on https://github.com/google/go-github/pull/3417.
SDK Version
No response
API Version
No response
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Same issue, it looks like we are both having the same day. 👍
@JossWhittle I'll open a PR to implement this once my go-github PR lands and is released. But based on the outstanding PRs here with no review comments on them I wouldn't hold your breath for this to be fixed any time soon.
Would love to have this feature in the provider!
Would love this feature aswell!
The change in google/go-github seems have already been released in v69.0.0 (https://github.com/google/go-github/pull/3417)
@at-wat at this point go-github is a long way ahead of the version used here and upgrading is likely to not be trivial as the broken project v1 REST APIs have been removed (see https://github.com/integrations/terraform-provider-github/issues/2494).
I need this feature as well. Please consider adding it.
@kfcampbell @afrazkhan @robabbott42 @kewalaka @EricDales Apologies in tagging you all.
But is there any ETA on when allowed_merge_methods will be added?
I've been migrating our 500 repo GitHub infrastructure to be managed by Terraform, was writing out the code to introduce rulesets and realised at terraform plan stage that I can't, this one single feature is not unavailable on the provider and will block me progressing with rulesets.
@kfcampbell @afrazkhan @robabbott42 @kewalaka @EricDales Apologies in tagging you all.
But is there any ETA on when
allowed_merge_methodswill be added?I've been migrating our 500 repo GitHub infrastructure to be managed by Terraform, was writing out the code to introduce rulesets and realised at
terraform planstage that I can't, this one single feature is not unavailable on the provider and will block me progressing with rulesets.
Don't think the support is coming anytime soon. Remember seeing that they are going through a major upgrade for the dependent Go package.
In the meantime, below is a workaround I applied to create policy with allowed_merge_methods.
locals {
prevent_rebase_merge = {
rules = [
{
type = "pull_request"
parameters = {
allowed_merge_methods = [
"merge",
"squash"
]
# These fields are required by the GitHub API but not directly related to specific rule functionality
# They are assigned the more relaxed values intentionally.
required_approving_review_count = 0
dismiss_stale_reviews_on_push = false
require_code_owner_review = false
require_last_push_approval = false
required_review_thread_resolution = false
}
}
]
}
}
resource "github_organization_ruleset" "unsupported" {
name = "foo"
target = "branch"
enforcement = "active"
conditions {
ref_name {
include = ["~DEFAULT_BRANCH"]
exclude = []
}
}
rules {
}
lifecycle {
ignore_changes = [
rules,
]
}
provisioner "local-exec" {
command = <<-EOT
echo '${jsonencode(local.prevent_rebase_merge)}' |
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/orgs/${var.github_organization}/rulesets/${self.ruleset_id} \
--input -
EOT
}
}
From testing, setting the following on github_repository and github_repository_ruleset
resource "github_repository" "this" {
...
allow_merge_commit = false
allow_rebase_merge = false
allow_squash_merge = true
...
}
resource "github_repository_ruleset" "main" {
name = "main"
repository = github_repository.this.name
target = "branch"
enforcement = "active"
conditions {
ref_name {
include = ["~DEFAULT_BRANCH"]
exclude = []
}
}
rules {
deletion = true
non_fast_forward = true
required_signatures = true
required_linear_history = true
pull_request {
required_approving_review_count = 1
dismiss_stale_reviews_on_push = true
require_code_owner_review = true
require_last_push_approval = true
required_review_thread_resolution = true
}
}
}
Results in our desired config of squash
@jacobwoffenden this behaviour is well understood. The repo setting in your test is for all PRs while the ruleset configuration requested is targeted and could be at the organization or enterprise scope.
Any update on this? Otherwise I will need to migrate to merge queue that supports it... but I don't want to as my team does not require it
@joluizquierdo I've not seen any movement for any of my open PRs so I don't think a fix is likely to be coming any time soon.