From d554a05ef414ff0674afa6e11bf646c3dad5cfec Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 6 Jun 2026 14:01:19 +0200 Subject: [PATCH 1/2] chore: Bump go-github to expose pull request repository settings The has_pull_requests and pull_request_creation_policy fields were added to go-github's Repository struct after the v88.0.0 release. Pin to the master pseudo-version until v89 is tagged. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5c6a1e5f84..fc52470c6c 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-jose/go-jose/v4 v4.1.4 github.com/gofri/go-github-ratelimit/v2 v2.0.2 github.com/google/go-cmp v0.7.0 - github.com/google/go-github/v88 v88.0.0 + github.com/google/go-github/v88 v88.0.1-0.20260605122729-bbd1294f1602 github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.5.0 github.com/hashicorp/go-retryablehttp v0.7.8 diff --git a/go.sum b/go.sum index c2e59560e7..e34f827c14 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/go-github/v88 v88.0.0 h1:dZA9IKkPK1eXZj4ypngnpRj5FwdpTv4whix2PrQMP7M= -github.com/google/go-github/v88 v88.0.0/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw= +github.com/google/go-github/v88 v88.0.1-0.20260605122729-bbd1294f1602 h1:2US8Ojrwi+Yi/IG5QYkRrEF211lyryqIo0Q+QlntZ10= +github.com/google/go-github/v88 v88.0.1-0.20260605122729-bbd1294f1602/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw= github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= From dfbe700b4499a04acf33340dabbc3dcde5005814 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 6 Jun 2026 14:01:19 +0200 Subject: [PATCH 2/2] feat: Add pull request settings to github_repository GitHub added two repository settings in February 2026: disabling pull requests entirely (has_pull_requests) and restricting who can open them (pull_request_creation_policy, "all" or "collaborators_only"). has_pull_requests defaults to true so existing repositories keep pull requests enabled. The creation policy is only sent when pull requests are enabled, matching how the merge-commit title/message fields are handled. --- docs/data-sources/repository.md | 4 + docs/resources/repository.md | 4 + github/data_source_github_repository.go | 10 +++ github/resource_github_repository.go | 21 +++++ github/resource_github_repository_test.go | 94 +++++++++++++++++++++++ templates/data-sources/repository.md.tmpl | 4 + templates/resources/repository.md.tmpl | 4 + 7 files changed, 141 insertions(+) diff --git a/docs/data-sources/repository.md b/docs/data-sources/repository.md index 3dee5e1460..2d07ac3a3b 100644 --- a/docs/data-sources/repository.md +++ b/docs/data-sources/repository.md @@ -44,6 +44,10 @@ The following arguments are supported: - `has_wiki` - Whether the repository has the GitHub Wiki enabled. +- `has_pull_requests` - Whether the repository has pull requests enabled. + +- `pull_request_creation_policy` - Who can create pull requests on the repository. Either `all` or `collaborators_only`. + - `is_template` - Whether the repository is a template repository. - `fork` - Whether the repository is a fork. diff --git a/docs/resources/repository.md b/docs/resources/repository.md index 58aede34a6..3192aabe21 100644 --- a/docs/resources/repository.md +++ b/docs/resources/repository.md @@ -67,6 +67,10 @@ The following arguments are supported: - `has_wiki` - (Optional) Set to `true` to enable the GitHub Wiki features on the repository. +- `has_pull_requests` - (Optional) Set to `false` to disable pull requests on the repository, hiding the pull requests tab. Defaults to `true`. + +- `pull_request_creation_policy` - (Optional) Restricts who can create pull requests on the repository. Can be `all` (default) to allow any user, or `collaborators_only` to restrict creation to collaborators with write access. Applicable only if `has_pull_requests` is `true`. + - `is_template` - (Optional) Set to `true` to tell GitHub that this is a template repository. - `allow_merge_commit` - (Optional) Set to `false` to disable merge commits on the repository. diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 6e0cdfba98..dfa50238cc 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -69,6 +69,14 @@ func dataSourceGithubRepository() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "has_pull_requests": { + Type: schema.TypeBool, + Computed: true, + }, + "pull_request_creation_policy": { + Type: schema.TypeString, + Computed: true, + }, "is_template": { Type: schema.TypeBool, Computed: true, @@ -389,6 +397,8 @@ func dataSourceGithubRepositoryRead(ctx context.Context, d *schema.ResourceData, _ = d.Set("has_issues", repo.GetHasIssues()) _ = d.Set("has_discussions", repo.GetHasDiscussions()) _ = d.Set("has_wiki", repo.GetHasWiki()) + _ = d.Set("has_pull_requests", repo.GetHasPullRequests()) + _ = d.Set("pull_request_creation_policy", repo.GetPullRequestCreationPolicy()) _ = d.Set("is_template", repo.GetIsTemplate()) _ = d.Set("fork", repo.GetFork()) _ = d.Set("allow_merge_commit", repo.GetAllowMergeCommit()) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index fef9483cf1..44cd1b5fa7 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -219,6 +219,19 @@ func resourceGithubRepository() *schema.Resource { Optional: true, Description: "Set to 'true' to enable the GitHub Wiki features on the repository.", }, + "has_pull_requests": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Set to 'false' to disable pull requests on the repository, hiding the pull requests tab. Defaults to 'true'.", + }, + "pull_request_creation_policy": { + Type: schema.TypeString, + Optional: true, + Default: "all", + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "collaborators_only"}, false)), + Description: "Restricts who can create pull requests on the repository. Can be 'all' (default) to allow any user, or 'collaborators_only' to restrict creation to collaborators with write access.", + }, "is_template": { Type: schema.TypeBool, Optional: true, @@ -597,6 +610,7 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { HasDiscussions: new(d.Get("has_discussions").(bool)), HasProjects: new(d.Get("has_projects").(bool)), HasWiki: new(d.Get("has_wiki").(bool)), + HasPullRequests: new(d.Get("has_pull_requests").(bool)), IsTemplate: new(d.Get("is_template").(bool)), AllowMergeCommit: new(d.Get("allow_merge_commit").(bool)), AllowSquashMerge: new(d.Get("allow_squash_merge").(bool)), @@ -630,6 +644,11 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { } } + // only configure the pull request creation policy when pull requests are enabled + if d.Get("has_pull_requests").(bool) { + repository.PullRequestCreationPolicy = new(d.Get("pull_request_creation_policy").(string)) + } + // only configure allow forking if repository is not public if visibility != "public" && (d.IsNewResource() || d.HasChange("allow_forking")) { if allowForking, ok := d.GetOkExists("allow_forking"); ok { //nolint:staticcheck // SA1019 // We sometimes need to use GetOkExists for booleans @@ -830,6 +849,8 @@ func resourceGithubRepositoryRead(ctx context.Context, d *schema.ResourceData, m _ = d.Set("has_discussions", repo.GetHasDiscussions()) _ = d.Set("has_projects", repo.GetHasProjects()) _ = d.Set("has_wiki", repo.GetHasWiki()) + _ = d.Set("has_pull_requests", repo.GetHasPullRequests()) + _ = d.Set("pull_request_creation_policy", repo.GetPullRequestCreationPolicy()) _ = d.Set("is_template", repo.GetIsTemplate()) _ = d.Set("full_name", repo.GetFullName()) _ = d.Set("default_branch", repo.GetDefaultBranch()) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 1046df1cc3..bdd5ec1a43 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -73,6 +73,100 @@ func TestAccGithubRepository(t *testing.T) { }) }) + t.Run("manages pull request settings without error", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%spr-settings-%s", testResourcePrefix, randomID) + + // Restrict pull request creation to collaborators only. + configRestricted := fmt.Sprintf(` + resource "github_repository" "test" { + name = "%s" + description = "Terraform acceptance tests %[1]s" + has_pull_requests = true + pull_request_creation_policy = "collaborators_only" + visibility = "%s" + } + `, testRepoName, testAccConf.testRepositoryVisibility) + + // Disable pull requests entirely. + configDisabled := fmt.Sprintf(` + resource "github_repository" "test" { + name = "%s" + description = "Terraform acceptance tests %[1]s" + has_pull_requests = false + visibility = "%s" + } + `, testRepoName, testAccConf.testRepositoryVisibility) + + checks := map[string]resource.TestCheckFunc{ + "restricted": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "has_pull_requests", + "true", + ), + resource.TestCheckResourceAttr( + "github_repository.test", "pull_request_creation_policy", + "collaborators_only", + ), + ), + "disabled": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "has_pull_requests", + "false", + ), + ), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnauthenticated(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: configRestricted, + Check: checks["restricted"], + }, + { + Config: configDisabled, + Check: checks["disabled"], + }, + }, + }) + }) + + t.Run("defaults pull request settings without error", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%spr-defaults-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` + resource "github_repository" "test" { + name = "%s" + description = "Terraform acceptance tests %[1]s" + visibility = "%s" + } + `, testRepoName, testAccConf.testRepositoryVisibility) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "has_pull_requests", + "true", + ), + resource.TestCheckResourceAttr( + "github_repository.test", "pull_request_creation_policy", + "all", + ), + ) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnauthenticated(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: config, + Check: check, + }, + }, + }) + }) + t.Run("updates a repositories name without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) oldName := fmt.Sprintf(`%srename-%s`, testResourcePrefix, randomID) diff --git a/templates/data-sources/repository.md.tmpl b/templates/data-sources/repository.md.tmpl index f1e389a051..a79c9d543f 100644 --- a/templates/data-sources/repository.md.tmpl +++ b/templates/data-sources/repository.md.tmpl @@ -40,6 +40,10 @@ The following arguments are supported: - `has_wiki` - Whether the repository has the GitHub Wiki enabled. +- `has_pull_requests` - Whether the repository has pull requests enabled. + +- `pull_request_creation_policy` - Who can create pull requests on the repository. Either `all` or `collaborators_only`. + - `is_template` - Whether the repository is a template repository. - `fork` - Whether the repository is a fork. diff --git a/templates/resources/repository.md.tmpl b/templates/resources/repository.md.tmpl index 5b2cd371f2..f8e0c566c0 100644 --- a/templates/resources/repository.md.tmpl +++ b/templates/resources/repository.md.tmpl @@ -46,6 +46,10 @@ The following arguments are supported: - `has_wiki` - (Optional) Set to `true` to enable the GitHub Wiki features on the repository. +- `has_pull_requests` - (Optional) Set to `false` to disable pull requests on the repository, hiding the pull requests tab. Defaults to `true`. + +- `pull_request_creation_policy` - (Optional) Restricts who can create pull requests on the repository. Can be `all` (default) to allow any user, or `collaborators_only` to restrict creation to collaborators with write access. Applicable only if `has_pull_requests` is `true`. + - `is_template` - (Optional) Set to `true` to tell GitHub that this is a template repository. - `allow_merge_commit` - (Optional) Set to `false` to disable merge commits on the repository.