[MAINT] Modernize github_repository resource - #3310
Conversation
|
👋 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 |
This comment was marked as outdated.
This comment was marked as outdated.
0b52c2c to
9f55dad
Compare
9f55dad to
e40af83
Compare
e40af83 to
57e9be8
Compare
There was a problem hiding this comment.
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_repositoryCRUD flow to be more self-contained and centralizes state population via a helper. - Migrates
github_repositoryacceptance tests toresource.ParallelTest+ConfigStateChecksand expands coverage for merge-strategy validation. - Updates docs/templates for deprecated
private, exportedetag, and Pages attribute descriptions; addsweb_commit_signoff_requiredto 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.). |
57e9be8 to
c43f69e
Compare
c43f69e to
4c9a812
Compare
6fc8411 to
53fac2d
Compare
| 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() { |
| "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) |
| { | ||
| 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)), | ||
| }, |
| // 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 { |
`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>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
87b3f0f to
7675956
Compare
rilical
left a comment
There was a problem hiding this comment.
There are two state-behavior changes here that I think need either coverage or clearer deprecation handling. The PR removes the request and Read wiring for has_downloads, but the schema and generated docs still present it as a usable argument, so configurations can now set a value that is silently ignored. It also removes the archived-repository guard around several merge and forking fields even though the old code noted that GitHub may omit those values after archival. Could we either preserve the existing behavior or make the new behavior explicit, then add focused tests for both cases?
Resolves #2604
Resolves #2264
Resolves #3302
Resolves #3562
Resolves #3554
Resolves #3592
Addresses many parts of #3133
Addresses #3070
Before the change?
logarchivedin theReadfuncCreatewould callUpdateandUpdatewould callReadwhich is an anti-patternAfter the change?
ConfigStateCheckstflogReadcould be removedresourceanddata-sourcedocs to use template generationresourcetests that needed Org settings changesweb_commit_signoff_requiredcomputed attribute todata-sourceresourceoperationstopicsattribute inresourceallow_squash_mergeandallow_commit_mergeare setPull request checklist
Schema migrations have been created if needed (example)Does this introduce a breaking change?
Please see our docs on breaking changes to help!