[MAINT] Use gofmt to rewrite unwanted patterns#3265
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 |
stevehipwell
left a comment
There was a problem hiding this comment.
It's a shame that gofumpt doesn't support replacement rules as I'd like to disable gofmt. Did you consider using gocritic?
|
@stevehipwell I had not before, no I'd be happy to check that out at some point. Unless you think it makes sense to do now? |
stevehipwell
left a comment
There was a problem hiding this comment.
One more minor change and then I think we should get this merged. Could you open an issue to replace gofmt by finding another mechanism for the custom rewrites in the future?
There was a problem hiding this comment.
Pull request overview
This PR introduces automated Go formatting rewrite rules (via golangci-lint/gofmt) to eliminate a set of discouraged patterns across the provider, then applies those rewrites across the codebase (including tests) to standardize diagnostics handling, ID parsing, and test context usage.
Changes:
- Removed
wrapErrorsand migrated call sites todiag.Errorf/diag.FromErr, plus updated related validation code. - Replaced legacy
parseTwoPartID/parseThreePartIDusage withparseID2/parseID3and updated numerous resource/data-source implementations accordingly. - Updated tests to prefer
t.Context()overcontext.Background(), and moved the branch protection migration test into a dedicated unit test file.
Reviewed changes
Copilot reviewed 64 out of 64 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| github/util.go | Removes wrapErrors and legacy ID parsers; uses diag directly and relies on parseID{2,3} helpers. |
| github/util_test.go | Drops the old two-part ID test and adds coverage for invalid inputs to validateSecretNameFunc. |
| github/transport_test.go | Replaces context.Background() with t.Context() in transport tests. |
| github/resource_github_team_sync_group_mapping_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_team_repository.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_team_membership.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_team_membership_test.go | Migrates ID parsing in acceptance helpers from parseTwoPartID to parseID2. |
| github/resource_github_repository_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_repository_ruleset.go | Migrates import ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_repository_pull_request.go | Migrates PR ID parsing from parseThreePartID to parseID3. |
| github/resource_github_repository_file_migration_test.go | Replaces context.Background() with t.Context() in commented migration test code. |
| github/resource_github_repository_deployment_branch_policy.go | Migrates import ID parsing from parseThreePartID to parseID3. |
| github/resource_github_repository_deploy_key.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_repository_deploy_key_test.go | Migrates ID parsing in acceptance helpers from parseTwoPartID to parseID2. |
| github/resource_github_repository_custom_property.go | Migrates ID parsing from parseThreePartID to parseID3. |
| github/resource_github_repository_collaborator.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_release.go | Migrates import ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_project_column_test.go | Replaces context.Background() with t.Context() in commented test code. |
| github/resource_github_organization_role_user.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_organization_role_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_organization_role_team.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_organization_role_team_assignment.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_organization_repository_role_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_organization_project_test.go | Replaces context.Background() with t.Context() in commented test code. |
| github/resource_github_membership.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_membership_test.go | Migrates ID parsing in acceptance helpers from parseTwoPartID to parseID2. |
| github/resource_github_issue.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_issue_label.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_enterprise_organization_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_enterprise_actions_runner_group_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_enterprise_actions_permissions_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/resource_github_dependabot_secret_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_dependabot_secret_migration_test.go | Replaces context.Background() with t.Context() in commented migration test code. |
| github/resource_github_dependabot_organization_secret_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_codespaces_secret.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_branch.go | Migrates ID parsing from parseTwoPartID to parseID2 (including import parsing). |
| github/resource_github_branch_protection.go | Migrates import ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_branch_protection_v3.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_branch_protection_v3_utils.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_branch_protection_test.go | Removes the migration unit test from this file (and trims imports accordingly). |
| github/resource_github_branch_protection_migration_test.go | Adds a dedicated unit test for resourceGithubBranchProtectionUpgradeV1 using t.Context(). |
| github/resource_github_app_installation_repository.go | Migrates ID parsing from parseTwoPartID to parseID2. |
| github/resource_github_actions_variable_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_actions_variable_migration_test.go | Replaces context.Background() with t.Context() in commented migration test code. |
| github/resource_github_actions_secret_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_actions_secret_migration_test.go | Uses t.Context() for the migration unit test call(s). |
| github/resource_github_actions_organization_variable_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_actions_organization_secret_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_actions_organization_secret_migration_test.go | Uses t.Context() for the migration unit test call(s). |
| github/resource_github_actions_environment_variable_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_actions_environment_variable_migration_test.go | Replaces context.Background() with t.Context() in commented migration test code. |
| github/resource_github_actions_environment_secret_test.go | Removes context import and uses t.Context() for API calls in tests. |
| github/resource_github_actions_environment_secret_migration_test.go | Replaces context.Background() with t.Context() in commented migration test code. |
| github/provider.go | Replaces wrapErrors usage with diag helpers and adjusts validation error returns. |
| github/provider_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/data_source_github_user_external_identity_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/data_source_github_organization_team_sync_groups_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/data_source_github_organization_repository_roles_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/data_source_github_organization_repository_role_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/data_source_github_organization_external_identities_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/data_source_github_enterprise_test.go | Rewrites enterprise precheck helper usage to skipUnlessEnterprise. |
| github/config_test.go | Replaces context.Background() with t.Context() in config acceptance tests. |
| github/acc_test.go | Replaces context.Background() with t.Context() in an acc-test helper. |
| .golangci.yml | Adds/updates gofmt rewrite rules to enforce preferred patterns automatically (with goimports enabled). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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>
…orf` Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…omErr` 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>
…xt()` Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Co-authored-by: Steve Hipwell <steve.hipwell@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@robert-crandall please could you review this? |
Before the change?
After the change?
gofmtto rewrite:skipUnlessMode(t, enterprise)toskipUnlessEnterprise(t)parseTwoPartIDwithparseID2parseThreePartIDwithparseID3wrapErrorswith singlefmt.Errorfwithdiag.Errorfdiag.FromErr(fmt.Errof(callswrapErrorswith singleerrelement withdiag.FromErrwrapErrorsdirectly withdiag.Diagnosticsgithub_branch_protectionmigration test to be unit testscontext.Background()in tests witht.Context()Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!