Skip to content

Commit 103cdab

Browse files
authored
fix: Fix errors as nil bomb (#2992)
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent c4d9e26 commit 103cdab

File tree

55 files changed

+83
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+83
-95
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: GitHub Actions CI
1+
name: CI
22

33
on:
44
push:
@@ -21,11 +21,11 @@ jobs:
2121
ci:
2222
name: Continuous Integration
2323
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
2426
defaults:
2527
run:
2628
shell: bash
27-
env:
28-
GITHUB_TEST_ORGANIZATION: kfcampbell-terraform-provider
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
@@ -35,7 +35,7 @@ jobs:
3535
go-version-file: go.mod
3636
cache: true
3737
- run: make tools
38-
- run: make lint
38+
- run: make lintcheck
3939
- run: make website-lint
4040
- run: make build
4141
- run: make test

GNUmakefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ tools:
88
go install github.com/client9/misspell/cmd/misspell@v0.3.4
99
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0
1010

11-
build: fmtcheck
11+
build: lintcheck
1212
CGO_ENABLED=0 go build -ldflags="-s -w" ./...
1313

1414
fmt:
1515
@echo "==> Fixing source code with golangci-lint..."
1616
golangci-lint fmt ./...
1717

18-
fmtcheck:
19-
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
20-
2118
lint:
19+
@echo "==> Checking source code against linters and fixing..."
20+
golangci-lint run --fix ./...
21+
22+
lintcheck:
2223
@echo "==> Checking source code against linters..."
2324
golangci-lint run ./...
2425

@@ -55,4 +56,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
5556
endif
5657
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
5758

58-
.PHONY: build test testacc fmt fmtcheck lint tools test-compile website website-lint website-test
59+
.PHONY: build test testacc fmt lint lintcheck tools test-compile website website-lint website-test

github/data_source_github_branch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func dataSourceGithubBranchRead(d *schema.ResourceData, meta any) error {
5050

5151
ref, resp, err := client.Git.GetRef(context.TODO(), orgName, repoName, branchRefName)
5252
if err != nil {
53-
err := &github.ErrorResponse{}
54-
if errors.As(err, &err) {
55-
if err.Response.StatusCode == http.StatusNotFound {
53+
var ghErr *github.ErrorResponse
54+
if errors.As(err, &ghErr) {
55+
if ghErr.Response.StatusCode == http.StatusNotFound {
5656
log.Printf("[DEBUG] Missing GitHub branch %s/%s (%s)", orgName, repoName, branchRefName)
5757
d.SetId("")
5858
return nil

github/data_source_github_ref.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func dataSourceGithubRefRead(d *schema.ResourceData, meta any) error {
5252

5353
refData, resp, err := client.Git.GetRef(context.TODO(), owner, repoName, ref)
5454
if err != nil {
55-
err := &github.ErrorResponse{}
56-
if errors.As(err, &err) {
57-
if err.Response.StatusCode == http.StatusNotFound {
55+
var ghErr *github.ErrorResponse
56+
if errors.As(err, &ghErr) {
57+
if ghErr.Response.StatusCode == http.StatusNotFound {
5858
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", owner, repoName, ref)
5959
d.SetId("")
6060
return nil

github/data_source_github_repository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta any) error {
361361

362362
repo, _, err := client.Repositories.Get(context.TODO(), owner, repoName)
363363
if err != nil {
364-
err := &github.ErrorResponse{}
365-
if errors.As(err, &err) {
366-
if err.Response.StatusCode == http.StatusNotFound {
364+
var ghErr *github.ErrorResponse
365+
if errors.As(err, &ghErr) {
366+
if ghErr.Response.StatusCode == http.StatusNotFound {
367367
log.Printf("[DEBUG] Missing GitHub repository %s/%s", owner, repoName)
368368
d.SetId("")
369369
return nil

github/data_source_github_repository_file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
9999

100100
fc, dc, _, err := client.Repositories.GetContents(ctx, owner, repo, file, opts)
101101
if err != nil {
102-
err := &github.ErrorResponse{}
103-
if errors.As(err, &err) {
104-
if err.Response.StatusCode == http.StatusNotFound {
102+
var ghErr *github.ErrorResponse
103+
if errors.As(err, &ghErr) {
104+
if ghErr.Response.StatusCode == http.StatusNotFound {
105105
log.Printf("[DEBUG] Missing GitHub repository file %s/%s/%s", owner, repo, file)
106106
d.SetId("")
107107
return nil

github/repository_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func checkRepositoryBranchExists(client *github.Client, owner, repo, branch stri
1616
ctx := context.WithValue(context.Background(), ctxId, buildTwoPartID(repo, branch))
1717
_, _, err := client.Repositories.GetBranch(ctx, owner, repo, branch, 2)
1818
if err != nil {
19-
ghErr := &github.ErrorResponse{}
19+
var ghErr *github.ErrorResponse
2020
if errors.As(err, &ghErr) {
2121
if ghErr.Response.StatusCode == http.StatusNotFound {
2222
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
130130
// isArchivedRepositoryError checks if an error is a 403 "repository archived" error.
131131
// Returns true if the repository is archived.
132132
func isArchivedRepositoryError(err error) bool {
133-
ghErr := &github.ErrorResponse{}
133+
var ghErr *github.ErrorResponse
134134
if errors.As(err, &ghErr) {
135135
if ghErr.Response.StatusCode == http.StatusForbidden {
136136
return strings.Contains(strings.ToLower(ghErr.Message), "archived")

github/resource_github_actions_environment_secret.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta any
131131

132132
repo, _, err := client.Repositories.Get(ctx, owner, repoName)
133133
if err != nil {
134-
ghErr := &github.ErrorResponse{}
134+
var ghErr *github.ErrorResponse
135135
if errors.As(err, &ghErr) {
136136
if ghErr.Response.StatusCode == http.StatusNotFound {
137137
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
145145

146146
secret, _, err := client.Actions.GetEnvSecret(ctx, int(repo.GetID()), escapedEnvName, secretName)
147147
if err != nil {
148-
ghErr := &github.ErrorResponse{}
148+
var ghErr *github.ErrorResponse
149149
if errors.As(err, &ghErr) {
150150
if ghErr.Response.StatusCode == http.StatusNotFound {
151151
log.Printf("[INFO] Removing environment secret %s from state because it no longer exists in GitHub",

github/resource_github_actions_environment_variable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func resourceGithubActionsEnvironmentVariableCreateOrUpdate(d *schema.ResourceDa
7777
// Try to create the variable first
7878
_, err := client.Actions.CreateEnvVariable(ctx, owner, repoName, escapedEnvName, variable)
7979
if err != nil {
80-
ghErr := &github.ErrorResponse{}
80+
var ghErr *github.ErrorResponse
8181
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusConflict {
8282
// Variable already exists, try to update instead
8383
// If it fails here, we want to return the error otherwise continue
@@ -107,7 +107,7 @@ func resourceGithubActionsEnvironmentVariableRead(d *schema.ResourceData, meta a
107107

108108
variable, _, err := client.Actions.GetEnvVariable(ctx, owner, repoName, escapedEnvName, name)
109109
if err != nil {
110-
ghErr := &github.ErrorResponse{}
110+
var ghErr *github.ErrorResponse
111111
if errors.As(err, &ghErr) {
112112
if ghErr.Response.StatusCode == http.StatusNotFound {
113113
log.Printf("[INFO] Removing actions variable %s from state because it no longer exists in GitHub",

github/resource_github_actions_organization_secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func resourceGithubActionsOrganizationSecretRead(d *schema.ResourceData, meta an
161161

162162
secret, _, err := client.Actions.GetOrgSecret(ctx, owner, d.Id())
163163
if err != nil {
164-
ghErr := &github.ErrorResponse{}
164+
var ghErr *github.ErrorResponse
165165
if errors.As(err, &ghErr) {
166166
if ghErr.Response.StatusCode == http.StatusNotFound {
167167
log.Printf("[INFO] Removing actions secret %s from state because it no longer exists in GitHub",

0 commit comments

Comments
 (0)