Skip to content

[MAINT] Modernize github_repository resource#3310

Open
deiga wants to merge 37 commits into
integrations:mainfrom
F-Secure-web:refactor-github-repository
Open

[MAINT] Modernize github_repository resource#3310
deiga wants to merge 37 commits into
integrations:mainfrom
F-Secure-web:refactor-github-repository

Conversation

@deiga

@deiga deiga commented Mar 28, 2026

Copy link
Copy Markdown
Collaborator

Resolves #2604
Resolves #2264
Addresses many parts of #3133
Addresses #3070


Before the change?

  • Tests used legacy testing checks
  • Tests weren't being run in parallel
  • Resource was still using log
  • There was an deprecated gate against archived in the Read func
  • Create would call Update and Update would call Read which is an anti-pattern

After the change?

  • Ensure that each CRUD function is fully self-contained
  • Tests use modern ConfigStateChecks
  • Tests can run in parallel, which reduces time to run tests immensely
  • Logging has been refactored to use tflog
  • After verification the "if not archived" gate in Read could be removed
  • Updates the resource and data-source docs to use template generation
  • Enable some resource tests that needed Org settings changes
  • Adds web_commit_signoff_required computed attribute to data-source
  • Adds timeouts to resource operations
  • Adds deprecation warning to topics attribute in resource
  • Adds validation that correct settings for allow_squash_merge and allow_commit_merge are set

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

@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! 🚀

@deiga deiga requested a review from stevehipwell March 28, 2026 18:41
@deiga deiga marked this pull request as draft March 28, 2026 19:02
@deiga deiga marked this pull request as ready for review March 30, 2026 06:06
@deiga deiga added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Apr 19, 2026
@deiga

This comment was marked as outdated.

@deiga deiga force-pushed the refactor-github-repository branch from 0b52c2c to 9f55dad Compare May 11, 2026 01:43
@deiga deiga marked this pull request as draft May 14, 2026 21:10
@deiga deiga removed the request for review from stevehipwell May 17, 2026 13:22
@deiga deiga force-pushed the refactor-github-repository branch from 9f55dad to e40af83 Compare May 24, 2026 12:47
@deiga deiga force-pushed the refactor-github-repository branch from e40af83 to 57e9be8 Compare June 3, 2026 06:55
@deiga deiga requested a review from Copilot June 3, 2026 06:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

These provider review instructions are being used. This PR modernizes the github_repository resource by refactoring CRUD behavior, migrating logging to tflog, updating repository documentation, and modernizing acceptance tests to use ConfigStateChecks and run in parallel.

Changes:

  • Refactors github_repository CRUD flow to be more self-contained and centralizes state population via a helper.
  • Migrates github_repository acceptance tests to resource.ParallelTest + ConfigStateChecks and expands coverage for merge-strategy validation.
  • Updates docs/templates for deprecated private, exported etag, and Pages attribute descriptions; adds web_commit_signoff_required to the repository data source.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
github/resource_github_repository.go Moves repository state-setting into setResourceFieldsFromRepo, refactors create/update/read flows, adds custom diff validation for conflicting merge settings, and migrates logging to tflog.
github/resource_github_repository_test.go Converts acceptance tests to resource.ParallelTest and ConfigStateChecks, adds coverage for merge/squash strategy validation.
github/data_source_github_repository.go Adds computed web_commit_signoff_required to the repository data source schema and read.
GNUmakefile Runs acceptance tests with a parallelism cap to support parallelized test cases.
templates/resources/repository.md.tmpl Updates generated doc template to reflect deprecations/exports and Pages field descriptions.
docs/resources/repository.md Updates generated docs to match the template changes (deprecated private, etag, Pages fields, etc.).

Comment thread github/resource_github_repository.go
Comment thread github/resource_github_repository.go
Comment thread github/resource_github_repository_test.go Outdated
@deiga deiga force-pushed the refactor-github-repository branch from 57e9be8 to c43f69e Compare July 10, 2026 10:35
@deiga deiga requested a review from Copilot July 10, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 10 changed files in this pull request and generated 5 comments.

Comment thread github/resource_github_repository.go Outdated
Comment thread github/resource_github_repository.go Outdated
Comment thread github/resource_github_repository.go Outdated
Comment thread github/resource_github_repository.go
Comment thread github/data_source_github_repository.go
@deiga deiga force-pushed the refactor-github-repository branch from c43f69e to 4c9a812 Compare July 11, 2026 18:54
@deiga deiga requested a review from Copilot July 12, 2026 19:49
@deiga deiga marked this pull request as ready for review July 12, 2026 19:49
@deiga deiga requested a review from stevehipwell July 12, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 14 changed files in this pull request and generated 5 comments.

Comment thread github/resource_github_repository.go Outdated
Comment thread github/resource_github_repository.go Outdated
Comment thread github/resource_github_repository.go Outdated
Comment thread github/data_source_github_repository.go
Comment thread github/resource_github_repository_test.go
@deiga deiga force-pushed the refactor-github-repository branch from 6fc8411 to 53fac2d Compare July 13, 2026 19:59
@deiga deiga requested a review from Copilot July 14, 2026 10:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 15 changed files in this pull request and generated 8 comments.

Comment on lines +1350 to +1359
if err != nil {
if ghErr, ok := errors.AsType[*github.ErrorResponse](err); ok {
if ghErr.Response.StatusCode == http.StatusUnprocessableEntity && strings.Contains(ghErr.Error(), "A previous repository operation is still in progress") {
tflog.Debug(ctx, "Repository is still being created, retrying PATCH", map[string]any{"owner": owner, "name": repoName})
return retry.RetryableError(fmt.Errorf("repository is still being created, retrying PATCH"))
}
return retry.NonRetryableError(fmt.Errorf("Error editing repository: %w", err))
}
}
return nil
}

return resourceGithubRepositoryRead(ctx, d, meta)
if diags := setResourceFieldsFromRepo(ctx, d, client, owner, repo); diags.HasError() {
Comment thread github/data_source_github_repository.go Outdated
Comment on lines +295 to +299
"pages": {
Type: schema.TypeList,
Computed: true,
Deprecated: "Use the github_repository_pages data source instead. This field will be removed in a future version.",
Type: schema.TypeList,
Computed: true,
Deprecated: "Use the github_repository_pages data source instead. This field will be removed in a future version.",
Description: "The repository's GitHub Pages configuration. Use the `github_repository_pages` data source instead. This field will be removed in a future version.",
)

func TestAccGithubRepository(t *testing.T) {
t.Parallel()

t.Skip("This test should be run manually after confirming that the test organization has 'Require contributors to sign off on web-based commits' enabled under Organizations -> Settings -> Repository -> Repository defaults.")
// This test can't be run in parallel because it modifies the organization settings, which could affect other tests.
mustRequireWebCommitSignoffForOrganization(t, testAccConf.owner)

t.Skip("This test should be run manually after confirming that the test organization has been correctly configured to disable setting forking at the repo level.")
// This test can't be run in parallel because it modifies the organization settings, which could affect other tests.
mustDisableForkingForOrganization(t, testAccConf.owner)
Comment on lines 1400 to +1404
{
Config: fmt.Sprintf(config, testRepoName, "foo"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_repository.private", "allow_forking", "false"),
),
},
{
Config: fmt.Sprintf(config, testRepoName, "bar"),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("github_repository.private", tfjsonpath.New("allow_forking"), knownvalue.Bool(false)),
},
Comment on lines +1045 to +1048
// setResourceFieldsFromRepo populates all Computed schema fields
// from a *github.Repository API response.
// For fields requiring separate API calls (pages, vulnerability alerts), targeted calls are made here.
func setResourceFieldsFromRepo(ctx context.Context, d *schema.ResourceData, client *github.Client, owner string, repo *github.Repository) diag.Diagnostics {
deiga added 29 commits July 14, 2026 21:53
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
`RequiredWith` doesn't work with `Default` values

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
This ensures that Visibility changes work properly even for internal repos created from Templates

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
… not provider

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…nown at diff time

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga force-pushed the refactor-github-repository branch from 4b5d697 to 2ba7b9a Compare July 14, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r/repository Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR vNext

Projects

None yet

2 participants