Skip to content

[MAINT] Use gofmt to rewrite unwanted patterns#3265

Merged
deiga merged 13 commits into
integrations:mainfrom
F-Secure-web:gofmt-rewrites
May 15, 2026
Merged

[MAINT] Use gofmt to rewrite unwanted patterns#3265
deiga merged 13 commits into
integrations:mainfrom
F-Secure-web:gofmt-rewrites

Conversation

@deiga
Copy link
Copy Markdown
Collaborator

@deiga deiga commented Mar 10, 2026


Before the change?

  • Codebase had unwanted patterns and no automatic protection against them

After the change?

  • Configure gofmt to rewrite:
    • skipUnlessMode(t, enterprise) to skipUnlessEnterprise(t)
    • parseTwoPartID with parseID2
    • parseThreePartID with parseID3
    • usage of wrapErrors with single fmt.Errorf with diag.Errorf
    • unnecessary diag.FromErr(fmt.Errof( calls
    • usage of wrapErrors with single err element with diag.FromErr
  • Replace usage of wrapErrors directly with diag.Diagnostics
  • Fix github_branch_protection migration test to be unit tests
  • Replace all unnecessary context.Background() in tests with t.Context()

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

@deiga deiga requested review from nickfloyd and stevehipwell March 10, 2026 22:26
@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 added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Apr 18, 2026
@deiga deiga added this to the v6.13.0 Release milestone Apr 18, 2026
@deiga deiga force-pushed the gofmt-rewrites branch from e3c9d40 to 332e265 Compare May 11, 2026 02:01
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

It's a shame that gofumpt doesn't support replacement rules as I'd like to disable gofmt. Did you consider using gocritic?

Comment thread .golangci.yml Outdated
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented May 12, 2026

@stevehipwell I had not before, no
I just noticed that go-ruleguard (through go-critic) has some rewriting options.

I'd be happy to check that out at some point. Unless you think it makes sense to do now?

@deiga deiga requested review from stevehipwell and removed request for nickfloyd May 12, 2026 21:26
@deiga deiga force-pushed the gofmt-rewrites branch from b9723ab to 7543e02 Compare May 12, 2026 22:26
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

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?

Comment thread .golangci.yml Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 wrapErrors and migrated call sites to diag.Errorf / diag.FromErr, plus updated related validation code.
  • Replaced legacy parseTwoPartID / parseThreePartID usage with parseID2 / parseID3 and updated numerous resource/data-source implementations accordingly.
  • Updated tests to prefer t.Context() over context.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.

Comment thread github/provider.go
Comment thread github/provider.go Outdated
deiga and others added 13 commits May 15, 2026 00:13
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>
…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>
@deiga deiga force-pushed the gofmt-rewrites branch from 44c0ca8 to 9cc697b Compare May 14, 2026 21:14
@deiga deiga requested a review from stevehipwell May 14, 2026 21:14
@deiga deiga added vNext and removed vNext labels May 14, 2026
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@stevehipwell
Copy link
Copy Markdown
Collaborator

@robert-crandall please could you review this?

@deiga deiga merged commit b9e1d41 into integrations:main May 15, 2026
11 checks passed
@deiga deiga deleted the gofmt-rewrites branch May 15, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants