From 34e28af55a7cbdfad67bcbdfedbd7c1c0c8b25cb Mon Sep 17 00:00:00 2001 From: Steve Hipwell Date: Wed, 10 Dec 2025 12:06:28 +0000 Subject: [PATCH] fix: Fix errors as nil bomb Signed-off-by: Steve Hipwell --- .github/workflows/ci.yaml | 8 ++++---- GNUmakefile | 11 ++++++----- github/data_source_github_branch.go | 6 +++--- github/data_source_github_ref.go | 6 +++--- github/data_source_github_repository.go | 6 +++--- github/data_source_github_repository_file.go | 6 +++--- github/repository_utils.go | 4 ++-- .../resource_github_actions_environment_secret.go | 4 ++-- .../resource_github_actions_environment_variable.go | 4 ++-- .../resource_github_actions_organization_secret.go | 2 +- ...resource_github_actions_organization_variable.go | 2 +- github/resource_github_actions_runner_group.go | 4 ++-- github/resource_github_actions_secret.go | 2 +- github/resource_github_actions_variable.go | 2 +- github/resource_github_branch.go | 2 +- github/resource_github_branch_default.go | 2 +- github/resource_github_branch_protection_v3.go | 2 +- ...esource_github_codespaces_organization_secret.go | 2 +- github/resource_github_codespaces_secret.go | 2 +- github/resource_github_codespaces_user_secret.go | 2 +- ...esource_github_dependabot_organization_secret.go | 2 +- github/resource_github_dependabot_secret.go | 2 +- ...source_github_enterprise_actions_runner_group.go | 4 ++-- github/resource_github_issue.go | 2 +- github/resource_github_issue_label.go | 2 +- github/resource_github_membership.go | 4 ++-- github/resource_github_organization_project.go | 2 +- github/resource_github_organization_role.go | 2 +- github/resource_github_organization_ruleset.go | 2 +- github/resource_github_organization_webhook.go | 2 +- github/resource_github_project_card.go | 6 +++--- github/resource_github_project_column.go | 6 +++--- github/resource_github_release.go | 2 +- github/resource_github_repository.go | 2 +- ...resource_github_repository_autolink_reference.go | 2 +- github/resource_github_repository_collaborator.go | 2 +- github/resource_github_repository_deploy_key.go | 2 +- ...ce_github_repository_deployment_branch_policy.go | 2 +- github/resource_github_repository_environment.go | 2 +- ...thub_repository_environment_deployment_policy.go | 2 +- github/resource_github_repository_milestone.go | 2 +- github/resource_github_repository_project.go | 2 +- github/resource_github_repository_ruleset.go | 2 +- github/resource_github_repository_topics.go | 2 +- github/resource_github_repository_webhook.go | 2 +- github/resource_github_team.go | 4 ++-- github/resource_github_team_membership.go | 2 +- github/resource_github_team_repository.go | 2 +- github/resource_github_team_sync_group_mapping.go | 2 +- github/resource_github_user_gpg_key.go | 2 +- github/resource_github_user_ssh_key.go | 2 +- github/resource_organization_block.go | 2 +- github/transport_test.go | 6 +++--- github/util.go | 2 +- scripts/gofmtcheck.sh | 13 ------------- 55 files changed, 83 insertions(+), 95 deletions(-) delete mode 100755 scripts/gofmtcheck.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ec9476ae55..123a0dd612 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: GitHub Actions CI +name: CI on: push: @@ -21,11 +21,11 @@ jobs: ci: name: Continuous Integration runs-on: ubuntu-latest + permissions: + contents: read defaults: run: shell: bash - env: - GITHUB_TEST_ORGANIZATION: kfcampbell-terraform-provider steps: - name: Checkout uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 @@ -35,7 +35,7 @@ jobs: go-version-file: go.mod cache: true - run: make tools - - run: make lint + - run: make lintcheck - run: make website-lint - run: make build - run: make test diff --git a/GNUmakefile b/GNUmakefile index 22901d666e..c5fd2e833a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -8,17 +8,18 @@ tools: go install github.com/client9/misspell/cmd/misspell@v0.3.4 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0 -build: fmtcheck +build: lintcheck CGO_ENABLED=0 go build -ldflags="-s -w" ./... fmt: @echo "==> Fixing source code with golangci-lint..." golangci-lint fmt ./... -fmtcheck: - @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" - lint: + @echo "==> Checking source code against linters and fixing..." + golangci-lint run --fix ./... + +lintcheck: @echo "==> Checking source code against linters..." golangci-lint run ./... @@ -55,4 +56,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) endif @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) -.PHONY: build test testacc fmt fmtcheck lint tools test-compile website website-lint website-test +.PHONY: build test testacc fmt lint lintcheck tools test-compile website website-lint website-test diff --git a/github/data_source_github_branch.go b/github/data_source_github_branch.go index 9176529ece..0aadf10d44 100644 --- a/github/data_source_github_branch.go +++ b/github/data_source_github_branch.go @@ -50,9 +50,9 @@ func dataSourceGithubBranchRead(d *schema.ResourceData, meta any) error { ref, resp, err := client.Git.GetRef(context.TODO(), orgName, repoName, branchRefName) if err != nil { - err := &github.ErrorResponse{} - if errors.As(err, &err) { - if err.Response.StatusCode == http.StatusNotFound { + var ghErr *github.ErrorResponse + if errors.As(err, &ghErr) { + if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[DEBUG] Missing GitHub branch %s/%s (%s)", orgName, repoName, branchRefName) d.SetId("") return nil diff --git a/github/data_source_github_ref.go b/github/data_source_github_ref.go index 814b0dd84d..69551f5830 100644 --- a/github/data_source_github_ref.go +++ b/github/data_source_github_ref.go @@ -52,9 +52,9 @@ func dataSourceGithubRefRead(d *schema.ResourceData, meta any) error { refData, resp, err := client.Git.GetRef(context.TODO(), owner, repoName, ref) if err != nil { - err := &github.ErrorResponse{} - if errors.As(err, &err) { - if err.Response.StatusCode == http.StatusNotFound { + var ghErr *github.ErrorResponse + if errors.As(err, &ghErr) { + if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", owner, repoName, ref) d.SetId("") return nil diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 94e40d0c3b..0fe967ed23 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -361,9 +361,9 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta any) error { repo, _, err := client.Repositories.Get(context.TODO(), owner, repoName) if err != nil { - err := &github.ErrorResponse{} - if errors.As(err, &err) { - if err.Response.StatusCode == http.StatusNotFound { + var ghErr *github.ErrorResponse + if errors.As(err, &ghErr) { + if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[DEBUG] Missing GitHub repository %s/%s", owner, repoName) d.SetId("") return nil diff --git a/github/data_source_github_repository_file.go b/github/data_source_github_repository_file.go index 361587d192..e710cb9572 100644 --- a/github/data_source_github_repository_file.go +++ b/github/data_source_github_repository_file.go @@ -99,9 +99,9 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD fc, dc, _, err := client.Repositories.GetContents(ctx, owner, repo, file, opts) if err != nil { - err := &github.ErrorResponse{} - if errors.As(err, &err) { - if err.Response.StatusCode == http.StatusNotFound { + var ghErr *github.ErrorResponse + if errors.As(err, &ghErr) { + if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[DEBUG] Missing GitHub repository file %s/%s/%s", owner, repo, file) d.SetId("") return nil diff --git a/github/repository_utils.go b/github/repository_utils.go index 89e31a5067..b95fd2bf00 100644 --- a/github/repository_utils.go +++ b/github/repository_utils.go @@ -16,7 +16,7 @@ func checkRepositoryBranchExists(client *github.Client, owner, repo, branch stri ctx := context.WithValue(context.Background(), ctxId, buildTwoPartID(repo, branch)) _, _, err := client.Repositories.GetBranch(ctx, owner, repo, branch, 2) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { return fmt.Errorf("branch %s not found in repository %s/%s or repository is not readable", branch, owner, repo) @@ -130,7 +130,7 @@ func listAutolinks(client *github.Client, owner, repo string) ([]*github.Autolin // isArchivedRepositoryError checks if an error is a 403 "repository archived" error. // Returns true if the repository is archived. func isArchivedRepositoryError(err error) bool { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusForbidden { return strings.Contains(strings.ToLower(ghErr.Message), "archived") diff --git a/github/resource_github_actions_environment_secret.go b/github/resource_github_actions_environment_secret.go index d556faeb0d..c975ca39a4 100644 --- a/github/resource_github_actions_environment_secret.go +++ b/github/resource_github_actions_environment_secret.go @@ -131,7 +131,7 @@ func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta any repo, _, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing environment secret %s from state because it no longer exists in GitHub", @@ -145,7 +145,7 @@ func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta any secret, _, err := client.Actions.GetEnvSecret(ctx, int(repo.GetID()), escapedEnvName, secretName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing environment secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_actions_environment_variable.go b/github/resource_github_actions_environment_variable.go index 239141e888..5d3b419012 100644 --- a/github/resource_github_actions_environment_variable.go +++ b/github/resource_github_actions_environment_variable.go @@ -77,7 +77,7 @@ func resourceGithubActionsEnvironmentVariableCreateOrUpdate(d *schema.ResourceDa // Try to create the variable first _, err := client.Actions.CreateEnvVariable(ctx, owner, repoName, escapedEnvName, variable) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusConflict { // Variable already exists, try to update instead // If it fails here, we want to return the error otherwise continue @@ -107,7 +107,7 @@ func resourceGithubActionsEnvironmentVariableRead(d *schema.ResourceData, meta a variable, _, err := client.Actions.GetEnvVariable(ctx, owner, repoName, escapedEnvName, name) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing actions variable %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_actions_organization_secret.go b/github/resource_github_actions_organization_secret.go index 9601ba5aab..8d83192e38 100644 --- a/github/resource_github_actions_organization_secret.go +++ b/github/resource_github_actions_organization_secret.go @@ -161,7 +161,7 @@ func resourceGithubActionsOrganizationSecretRead(d *schema.ResourceData, meta an secret, _, err := client.Actions.GetOrgSecret(ctx, owner, d.Id()) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_actions_organization_variable.go b/github/resource_github_actions_organization_variable.go index 7249837906..5187b0ef06 100644 --- a/github/resource_github_actions_organization_variable.go +++ b/github/resource_github_actions_organization_variable.go @@ -156,7 +156,7 @@ func resourceGithubActionsOrganizationVariableRead(d *schema.ResourceData, meta variable, _, err := client.Actions.GetOrgVariable(ctx, owner, name) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing actions variable %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_actions_runner_group.go b/github/resource_github_actions_runner_group.go index b53b2817e1..399fd237ca 100644 --- a/github/resource_github_actions_runner_group.go +++ b/github/resource_github_actions_runner_group.go @@ -192,7 +192,7 @@ func resourceGithubActionsRunnerGroupCreate(d *schema.ResourceData, meta any) er func getOrganizationRunnerGroup(client *github.Client, ctx context.Context, org string, groupID int64) (*github.RunnerGroup, *github.Response, error) { runnerGroup, resp, err := client.Actions.GetOrganizationRunnerGroup(ctx, org, groupID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { // ignore error StatusNotModified return runnerGroup, resp, nil @@ -221,7 +221,7 @@ func resourceGithubActionsRunnerGroupRead(d *schema.ResourceData, meta any) erro runnerGroup, resp, err := getOrganizationRunnerGroup(client, ctx, orgName, runnerGroupID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing organization runner group %s/%s from state because it no longer exists in GitHub", diff --git a/github/resource_github_actions_secret.go b/github/resource_github_actions_secret.go index 4e1346e0de..8f02e1c160 100644 --- a/github/resource_github_actions_secret.go +++ b/github/resource_github_actions_secret.go @@ -132,7 +132,7 @@ func resourceGithubActionsSecretRead(d *schema.ResourceData, meta any) error { secret, _, err := client.Actions.GetRepoSecret(ctx, owner, repoName, secretName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_actions_variable.go b/github/resource_github_actions_variable.go index a40f6baceb..d45f62a2a8 100644 --- a/github/resource_github_actions_variable.go +++ b/github/resource_github_actions_variable.go @@ -104,7 +104,7 @@ func resourceGithubActionsVariableRead(d *schema.ResourceData, meta any) error { variable, _, err := client.Actions.GetRepoVariable(ctx, owner, repoName, variableName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing actions variable %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_branch.go b/github/resource_github_branch.go index 298ae3e2e7..11e1e08268 100644 --- a/github/resource_github_branch.go +++ b/github/resource_github_branch.go @@ -130,7 +130,7 @@ func resourceGithubBranchRead(d *schema.ResourceData, meta any) error { ref, resp, err := client.Git.GetRef(ctx, orgName, repoName, branchRefName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_branch_default.go b/github/resource_github_branch_default.go index 465ef00f13..1a1df3a07a 100644 --- a/github/resource_github_branch_default.go +++ b/github/resource_github_branch_default.go @@ -98,7 +98,7 @@ func resourceGithubBranchDefaultRead(d *schema.ResourceData, meta any) error { repository, resp, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_branch_protection_v3.go b/github/resource_github_branch_protection_v3.go index 5d5cc11d1f..0b51e863f4 100644 --- a/github/resource_github_branch_protection_v3.go +++ b/github/resource_github_branch_protection_v3.go @@ -282,7 +282,7 @@ func resourceGithubBranchProtectionV3Read(d *schema.ResourceData, meta any) erro githubProtection, resp, err := client.Repositories.GetBranchProtection(ctx, orgName, repoName, branch) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { if err := requireSignedCommitsRead(d, meta); err != nil { diff --git a/github/resource_github_codespaces_organization_secret.go b/github/resource_github_codespaces_organization_secret.go index a79cd76a51..c0efc5793e 100644 --- a/github/resource_github_codespaces_organization_secret.go +++ b/github/resource_github_codespaces_organization_secret.go @@ -149,7 +149,7 @@ func resourceGithubCodespacesOrganizationSecretRead(d *schema.ResourceData, meta secret, _, err := client.Codespaces.GetOrgSecret(ctx, owner, d.Id()) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_codespaces_secret.go b/github/resource_github_codespaces_secret.go index 94615b6e24..1fca28fbb7 100644 --- a/github/resource_github_codespaces_secret.go +++ b/github/resource_github_codespaces_secret.go @@ -119,7 +119,7 @@ func resourceGithubCodespacesSecretRead(d *schema.ResourceData, meta any) error secret, _, err := client.Codespaces.GetRepoSecret(ctx, owner, repoName, secretName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_codespaces_user_secret.go b/github/resource_github_codespaces_user_secret.go index 91762f29e8..87cecd8aa7 100644 --- a/github/resource_github_codespaces_user_secret.go +++ b/github/resource_github_codespaces_user_secret.go @@ -133,7 +133,7 @@ func resourceGithubCodespacesUserSecretRead(d *schema.ResourceData, meta any) er secret, _, err := client.Codespaces.GetUserSecret(ctx, d.Id()) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_dependabot_organization_secret.go b/github/resource_github_dependabot_organization_secret.go index d98f6edc0c..326921627b 100644 --- a/github/resource_github_dependabot_organization_secret.go +++ b/github/resource_github_dependabot_organization_secret.go @@ -149,7 +149,7 @@ func resourceGithubDependabotOrganizationSecretRead(d *schema.ResourceData, meta secret, _, err := client.Dependabot.GetOrgSecret(ctx, owner, d.Id()) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_dependabot_secret.go b/github/resource_github_dependabot_secret.go index 2fcf5f0a98..740fc5dca0 100644 --- a/github/resource_github_dependabot_secret.go +++ b/github/resource_github_dependabot_secret.go @@ -120,7 +120,7 @@ func resourceGithubDependabotSecretRead(d *schema.ResourceData, meta any) error secret, _, err := client.Dependabot.GetRepoSecret(ctx, owner, repoName, secretName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] Removing actions secret %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_enterprise_actions_runner_group.go b/github/resource_github_enterprise_actions_runner_group.go index 143eb6851f..959eb3ee1e 100644 --- a/github/resource_github_enterprise_actions_runner_group.go +++ b/github/resource_github_enterprise_actions_runner_group.go @@ -180,7 +180,7 @@ func resourceGithubActionsEnterpriseRunnerGroupCreate(d *schema.ResourceData, me func getEnterpriseRunnerGroup(client *github.Client, ctx context.Context, ent string, groupID int64) (*github.EnterpriseRunnerGroup, *github.Response, error) { enterpriseRunnerGroup, resp, err := client.Enterprise.GetEnterpriseRunnerGroup(ctx, ent, groupID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { // ignore error StatusNotModified return enterpriseRunnerGroup, resp, nil @@ -204,7 +204,7 @@ func resourceGithubActionsEnterpriseRunnerGroupRead(d *schema.ResourceData, meta enterpriseRunnerGroup, resp, err := getEnterpriseRunnerGroup(client, ctx, enterpriseSlug, runnerGroupID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing enterprise runner group %s/%s from state because it no longer exists in GitHub", diff --git a/github/resource_github_issue.go b/github/resource_github_issue.go index a3f07a1660..2465313728 100644 --- a/github/resource_github_issue.go +++ b/github/resource_github_issue.go @@ -153,7 +153,7 @@ func resourceGithubIssueRead(d *schema.ResourceData, meta any) error { issue, resp, err := client.Issues.Get(ctx, orgName, repoName, number) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_issue_label.go b/github/resource_github_issue_label.go index 57176fd555..996a202f42 100644 --- a/github/resource_github_issue_label.go +++ b/github/resource_github_issue_label.go @@ -159,7 +159,7 @@ func resourceGithubIssueLabelRead(d *schema.ResourceData, meta any) error { githubLabel, resp, err := client.Issues.GetLabel(ctx, orgName, repoName, name) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_membership.go b/github/resource_github_membership.go index 0f508ed10a..ed0a3de765 100644 --- a/github/resource_github_membership.go +++ b/github/resource_github_membership.go @@ -102,7 +102,7 @@ func resourceGithubMembershipRead(d *schema.ResourceData, meta any) error { membership, resp, err := client.Organizations.GetOrgMembership(ctx, username, orgName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil @@ -152,7 +152,7 @@ func resourceGithubMembershipDelete(d *schema.ResourceData, meta any) error { var membership *github.Membership membership, _, err = client.Organizations.GetOrgMembership(ctx, username, orgName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Not downgrading '%s' membership for '%s' because they are not a member of the org anymore", orgName, username) diff --git a/github/resource_github_organization_project.go b/github/resource_github_organization_project.go index 7577223761..a576580d81 100644 --- a/github/resource_github_organization_project.go +++ b/github/resource_github_organization_project.go @@ -95,7 +95,7 @@ func resourceGithubOrganizationProjectRead(d *schema.ResourceData, meta any) err project, resp, err := client.Projects.GetProject(ctx, projectID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_organization_role.go b/github/resource_github_organization_role.go index d6da7fa746..53c3647923 100644 --- a/github/resource_github_organization_role.go +++ b/github/resource_github_organization_role.go @@ -103,7 +103,7 @@ func resourceGithubOrganizationRoleRead(ctx context.Context, d *schema.ResourceD role, _, err := client.Organizations.GetOrgRole(ctx, orgName, roleId) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] organization role (%s/%d) not found, removing from state", orgName, roleId) diff --git a/github/resource_github_organization_ruleset.go b/github/resource_github_organization_ruleset.go index a92c5f14df..95a4a8e359 100644 --- a/github/resource_github_organization_ruleset.go +++ b/github/resource_github_organization_ruleset.go @@ -625,7 +625,7 @@ func resourceGithubOrganizationRulesetRead(d *schema.ResourceData, meta any) err ruleset, resp, err = client.Organizations.GetOrganizationRuleset(ctx, owner, rulesetID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_organization_webhook.go b/github/resource_github_organization_webhook.go index dc43d7a5d3..a636b65891 100644 --- a/github/resource_github_organization_webhook.go +++ b/github/resource_github_organization_webhook.go @@ -125,7 +125,7 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta any) err hook, resp, err := client.Organizations.GetHook(ctx, orgName, hookID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_project_card.go b/github/resource_github_project_card.go index af3b12252f..cd5fe3d784 100644 --- a/github/resource_github_project_card.go +++ b/github/resource_github_project_card.go @@ -115,9 +115,9 @@ func resourceGithubProjectCardRead(d *schema.ResourceData, meta any) error { log.Printf("[DEBUG] Reading project card: %s", nodeID) card, _, err := client.Projects.GetProjectCard(ctx, int64(cardID)) if err != nil { - err := &github.ErrorResponse{} - if errors.As(err, &err) { - if err.Response.StatusCode == http.StatusNotFound { + var ghErr *github.ErrorResponse + if errors.As(err, &ghErr) { + if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing project card %s from state because it no longer exists in GitHub", d.Id()) d.SetId("") return nil diff --git a/github/resource_github_project_column.go b/github/resource_github_project_column.go index 6b3ee4365c..7f1fb8d483 100644 --- a/github/resource_github_project_column.go +++ b/github/resource_github_project_column.go @@ -98,9 +98,9 @@ func resourceGithubProjectColumnRead(d *schema.ResourceData, meta any) error { column, _, err := client.Projects.GetProjectColumn(ctx, columnID) if err != nil { - err := &github.ErrorResponse{} - if errors.As(err, &err) { - if err.Response.StatusCode == http.StatusNotFound { + var ghErr *github.ErrorResponse + if errors.As(err, &ghErr) { + if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing project column %s from state because it no longer exists in GitHub", d.Id()) d.SetId("") return nil diff --git a/github/resource_github_release.go b/github/resource_github_release.go index 83a1b0fb52..3e1efffecf 100644 --- a/github/resource_github_release.go +++ b/github/resource_github_release.go @@ -220,7 +220,7 @@ func resourceGithubReleaseRead(d *schema.ResourceData, meta any) error { release, _, err := client.Repositories.GetRelease(ctx, owner, repository, releaseID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing release ID %d for repository %s from state, because it no longer exists on GitHub", releaseID, repository) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 6f4abaeb62..2be5f8717f 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -795,7 +795,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta any) error { repo, resp, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_autolink_reference.go b/github/resource_github_repository_autolink_reference.go index b819ed62e0..e2544a5195 100644 --- a/github/resource_github_repository_autolink_reference.go +++ b/github/resource_github_repository_autolink_reference.go @@ -133,7 +133,7 @@ func resourceGithubRepositoryAutolinkReferenceRead(d *schema.ResourceData, meta autolinkRef, _, err := client.Repositories.GetAutolink(ctx, owner, repoName, autolinkRefID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing autolink reference for repository %s/%s from state because it no longer exists in GitHub", diff --git a/github/resource_github_repository_collaborator.go b/github/resource_github_repository_collaborator.go index 387617d1b7..324e74906b 100644 --- a/github/resource_github_repository_collaborator.go +++ b/github/resource_github_repository_collaborator.go @@ -106,7 +106,7 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta any) // First, check if the user has been invited but has not yet accepted invitation, err := findRepoInvitation(client, ctx, owner, repoNameWithoutOwner, username) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { // this short circuits the rest of the code because if the diff --git a/github/resource_github_repository_deploy_key.go b/github/resource_github_repository_deploy_key.go index 944eaa6054..19731b49da 100644 --- a/github/resource_github_repository_deploy_key.go +++ b/github/resource_github_repository_deploy_key.go @@ -104,7 +104,7 @@ func resourceGithubRepositoryDeployKeyRead(d *schema.ResourceData, meta any) err key, resp, err := client.Repositories.GetKey(ctx, owner, repoName, id) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_deployment_branch_policy.go b/github/resource_github_repository_deployment_branch_policy.go index a62436260e..06039a3a5a 100644 --- a/github/resource_github_repository_deployment_branch_policy.go +++ b/github/resource_github_repository_deployment_branch_policy.go @@ -116,7 +116,7 @@ func resourceGithubRepositoryDeploymentBranchPolicyRead(d *schema.ResourceData, policy, resp, err := client.Repositories.GetDeploymentBranchPolicy(ctx, owner, repoName, environmentName, int64(id)) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_environment.go b/github/resource_github_repository_environment.go index 6e8c0b7d46..5020d44f19 100644 --- a/github/resource_github_repository_environment.go +++ b/github/resource_github_repository_environment.go @@ -133,7 +133,7 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta any) e env, _, err := client.Repositories.GetEnvironment(ctx, owner, repoName, escapedEnvName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[INFO] Removing repository environment %s from state because it no longer exists in GitHub", diff --git a/github/resource_github_repository_environment_deployment_policy.go b/github/resource_github_repository_environment_deployment_policy.go index 2b573fce29..7022ff08aa 100644 --- a/github/resource_github_repository_environment_deployment_policy.go +++ b/github/resource_github_repository_environment_deployment_policy.go @@ -104,7 +104,7 @@ func resourceGithubRepositoryEnvironmentDeploymentPolicyRead(d *schema.ResourceD branchPolicy, _, err := client.Repositories.GetDeploymentBranchPolicy(ctx, owner, repoName, envName, branchPolicyId) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_milestone.go b/github/resource_github_repository_milestone.go index b1ec2e2212..4de9caf945 100644 --- a/github/resource_github_repository_milestone.go +++ b/github/resource_github_repository_milestone.go @@ -144,7 +144,7 @@ func resourceGithubRepositoryMilestoneRead(d *schema.ResourceData, meta any) err milestone, _, err := conn.Issues.GetMilestone(ctx, owner, repoName, number) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_project.go b/github/resource_github_repository_project.go index 2b3b13e789..a127c67672 100644 --- a/github/resource_github_repository_project.go +++ b/github/resource_github_repository_project.go @@ -109,7 +109,7 @@ func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta any) error project, resp, err := client.Projects.GetProject(ctx, projectID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_ruleset.go b/github/resource_github_repository_ruleset.go index 3e711bd32d..5b7cf2c057 100644 --- a/github/resource_github_repository_ruleset.go +++ b/github/resource_github_repository_ruleset.go @@ -645,7 +645,7 @@ func resourceGithubRepositoryRulesetRead(d *schema.ResourceData, meta any) error ruleset, resp, err = client.Repositories.GetRuleset(ctx, owner, repoName, rulesetID, false) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_topics.go b/github/resource_github_repository_topics.go index e4ef9a2558..34300ba869 100644 --- a/github/resource_github_repository_topics.go +++ b/github/resource_github_repository_topics.go @@ -72,7 +72,7 @@ func resourceGithubRepositoryTopicsRead(d *schema.ResourceData, meta any) error topics, _, err := client.Repositories.ListAllTopics(ctx, owner, repoName) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_repository_webhook.go b/github/resource_github_repository_webhook.go index a09f388ad9..09f6af0297 100644 --- a/github/resource_github_repository_webhook.go +++ b/github/resource_github_repository_webhook.go @@ -142,7 +142,7 @@ func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta any) error hook, _, err := client.Repositories.GetHook(ctx, owner, repoName, hookID) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_team.go b/github/resource_github_team.go index 482b9bc860..03bbe66ba1 100644 --- a/github/resource_github_team.go +++ b/github/resource_github_team.go @@ -196,7 +196,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta any) error { team, resp, err := client.Teams.GetTeamByID(ctx, orgId, id) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil @@ -339,7 +339,7 @@ func resourceGithubTeamDelete(d *schema.ResourceData, meta any) error { // Fetch the team in order to see if it exists or not (http 404) _, _, err = client.Teams.GetTeamByID(ctx, orgId, id) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { // If team we failed to delete does not exist, remove it from TF state. diff --git a/github/resource_github_team_membership.go b/github/resource_github_team_membership.go index 601cb723c4..70061d6d2e 100644 --- a/github/resource_github_team_membership.go +++ b/github/resource_github_team_membership.go @@ -125,7 +125,7 @@ func resourceGithubTeamMembershipRead(d *schema.ResourceData, meta any) error { membership, resp, err := client.Teams.GetTeamMembershipByID(ctx, orgId, teamId, username) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_team_repository.go b/github/resource_github_team_repository.go index 210bbacd73..f4853fa018 100644 --- a/github/resource_github_team_repository.go +++ b/github/resource_github_team_repository.go @@ -126,7 +126,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta any) error { repo, resp, repoErr := client.Teams.IsTeamRepoByID(ctx, orgId, teamId, orgName, repoName) if repoErr != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(repoErr, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_team_sync_group_mapping.go b/github/resource_github_team_sync_group_mapping.go index eeba0e37f0..01ea9696b8 100644 --- a/github/resource_github_team_sync_group_mapping.go +++ b/github/resource_github_team_sync_group_mapping.go @@ -105,7 +105,7 @@ func resourceGithubTeamSyncGroupMappingRead(d *schema.ResourceData, meta any) er idpGroupList, resp, err := client.Teams.ListIDPGroupsForTeamBySlug(ctx, orgName, slug) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_user_gpg_key.go b/github/resource_github_user_gpg_key.go index 6830ea4643..979c84f282 100644 --- a/github/resource_github_user_gpg_key.go +++ b/github/resource_github_user_gpg_key.go @@ -67,7 +67,7 @@ func resourceGithubUserGpgKeyRead(d *schema.ResourceData, meta any) error { key, _, err := client.Users.GetGPGKey(ctx, id) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_github_user_ssh_key.go b/github/resource_github_user_ssh_key.go index 34b6030fe7..e509b2de1b 100644 --- a/github/resource_github_user_ssh_key.go +++ b/github/resource_github_user_ssh_key.go @@ -85,7 +85,7 @@ func resourceGithubUserSshKeyRead(d *schema.ResourceData, meta any) error { key, resp, err := client.Users.GetKey(ctx, id) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/resource_organization_block.go b/github/resource_organization_block.go index 5487f5ec73..c89b34dcf8 100644 --- a/github/resource_organization_block.go +++ b/github/resource_organization_block.go @@ -68,7 +68,7 @@ func resourceOrganizationBlockRead(d *schema.ResourceData, meta any) error { blocked, resp, err := client.Organizations.IsBlocked(ctx, orgName, username) if err != nil { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/github/transport_test.go b/github/transport_test.go index fab8242a29..3f70dde752 100644 --- a/github/transport_test.go +++ b/github/transport_test.go @@ -263,7 +263,7 @@ func TestRateLimitTransport_abuseLimit_post_error(t *testing.T) { t.Fatal("Expected 422 error, got nil") } - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse ok := errors.As(err, &ghErr) if !ok { t.Fatalf("Expected github.ErrorResponse, got: %#v", err) @@ -396,7 +396,7 @@ func TestRetryTransport_retry_post_error(t *testing.T) { t.Fatal("Expected error not to be nil") } - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse ok := errors.As(err, &ghErr) if !ok { t.Fatalf("Expected github.ErrorResponse, got: %#v", err) @@ -459,7 +459,7 @@ func TestRetryTransport_retry_post_success(t *testing.T) { t.Fatalf("Expected error to be nil, got %v", err) } - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse ok := errors.As(err, &ghErr) if ok { t.Fatalf("Expected successful github call, got: %q", ghErr.Message) diff --git a/github/util.go b/github/util.go index 2389acd90c..0fd5da32c2 100644 --- a/github/util.go +++ b/github/util.go @@ -248,7 +248,7 @@ func validateSecretNameFunc(v any, path cty.Path) diag.Diagnostics { // resourceDescription represents a formatting string that represents the resource // args will be passed to resourceDescription in `log.Printf`. func deleteResourceOn404AndSwallow304OtherwiseReturnError(err error, d *schema.ResourceData, resourceDescription string, args ...any) error { - ghErr := &github.ErrorResponse{} + var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotModified { return nil diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh deleted file mode 100755 index 1c055815f8..0000000000 --- a/scripts/gofmtcheck.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking that code complies with gofmt requirements..." -gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`) -if [[ -n ${gofmt_files} ]]; then - echo 'gofmt needs running on the following files:' - echo "${gofmt_files}" - echo "You can use the command: \`make fmt\` to reformat code." - exit 1 -fi - -exit 0