Skip to content

Commit 7d06267

Browse files
authored
refactor: Remove redundant github.Ptr calls (#4145)
1 parent ffd18dc commit 7d06267

26 files changed

Lines changed: 434 additions & 44 deletions

.custom-gcl.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ plugins:
44
path: ./tools/extraneousnew
55
- module: "github.com/google/go-github/v84/tools/fmtpercentv"
66
path: ./tools/fmtpercentv
7+
- module: "github.com/google/go-github/v84/tools/redundantptr"
8+
path: ./tools/redundantptr
79
- module: "github.com/google/go-github/v84/tools/sliceofpointers"
810
path: ./tools/sliceofpointers
911
- module: "github.com/google/go-github/v84/tools/structfield"

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ linters:
2727
- nolintlint
2828
- paralleltest
2929
- perfsprint
30+
- redundantptr
3031
- revive
3132
- sliceofpointers
3233
- staticcheck
@@ -193,6 +194,10 @@ linters:
193194
type: module
194195
description: Reports usage of %d or %s in format strings.
195196
original-url: github.com/google/go-github/v84/tools/fmtpercentv
197+
redundantptr:
198+
type: module
199+
description: Reports github.Ptr(x) calls that can be replaced with &x.
200+
original-url: github.com/google/go-github/v84/tools/redundantptr
196201
sliceofpointers:
197202
type: module
198203
description: Reports usage of []*string and slices of structs without pointers.

example/commitpr/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func getTree(ref *github.Reference) (tree *github.Tree, err error) {
105105
if err != nil {
106106
return nil, err
107107
}
108-
entries = append(entries, &github.TreeEntry{Path: github.Ptr(file), Type: github.Ptr("blob"), Content: github.Ptr(string(content)), Mode: github.Ptr("100644")})
108+
entries = append(entries, &github.TreeEntry{Path: &file, Type: github.Ptr("blob"), Content: github.Ptr(string(content)), Mode: github.Ptr("100644")})
109109
}
110110

111111
tree, _, err = client.Git.CreateTree(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA, entries)

github/actions_hosted_runners_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) {
111111
Length: 31,
112112
},
113113
},
114-
LastActiveOn: Ptr(lastActiveOn),
114+
LastActiveOn: &lastActiveOn,
115115
},
116116
{
117117
ID: Ptr(int64(7)),
@@ -132,7 +132,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) {
132132
MaximumRunners: Ptr(int64(20)),
133133
PublicIPEnabled: Ptr(false),
134134
PublicIPs: []*HostedRunnerPublicIP{},
135-
LastActiveOn: Ptr(lastActiveOn),
135+
LastActiveOn: &lastActiveOn,
136136
},
137137
},
138138
}
@@ -236,7 +236,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) {
236236
Length: 31,
237237
},
238238
},
239-
LastActiveOn: Ptr(lastActiveOn),
239+
LastActiveOn: &lastActiveOn,
240240
}
241241

242242
if !cmp.Equal(hostedRunner, want) {
@@ -652,7 +652,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) {
652652
Length: 31,
653653
},
654654
},
655-
LastActiveOn: Ptr(lastActiveOn),
655+
LastActiveOn: &lastActiveOn,
656656
}
657657

658658
if !cmp.Equal(hostedRunner, want) {
@@ -748,7 +748,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) {
748748
Length: 31,
749749
},
750750
},
751-
LastActiveOn: Ptr(lastActiveOn),
751+
LastActiveOn: &lastActiveOn,
752752
}
753753

754754
if !cmp.Equal(hostedRunner, want) {
@@ -837,7 +837,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) {
837837
Length: 31,
838838
},
839839
},
840-
LastActiveOn: Ptr(lastActiveOn),
840+
LastActiveOn: &lastActiveOn,
841841
}
842842

843843
if !cmp.Equal(hostedRunner, want) {

github/actions_runner_groups_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
513513
Length: 31,
514514
},
515515
},
516-
LastActiveOn: Ptr(lastActiveOn),
516+
LastActiveOn: &lastActiveOn,
517517
},
518518
{
519519
ID: Ptr(int64(7)),
@@ -534,7 +534,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
534534
MaximumRunners: Ptr(int64(20)),
535535
PublicIPEnabled: Ptr(false),
536536
PublicIPs: []*HostedRunnerPublicIP{},
537-
LastActiveOn: Ptr(lastActiveOn),
537+
LastActiveOn: &lastActiveOn,
538538
},
539539
},
540540
}

github/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func (s *AppsService) CreateInstallationTokenListRepos(ctx context.Context, id i
431431
//meta:operation POST /repos/{owner}/{repo}/content_references/{content_reference_id}/attachments
432432
func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID int64, title, body string) (*Attachment, *Response, error) {
433433
u := fmt.Sprintf("content_references/%v/attachments", contentReferenceID)
434-
payload := &Attachment{Title: Ptr(title), Body: Ptr(body)}
434+
payload := &Attachment{Title: &title, Body: &body}
435435
req, err := s.client.NewRequest("POST", u, payload)
436436
if err != nil {
437437
return nil, nil, err

github/enterprise_actions_hosted_runners_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) {
111111
Length: 31,
112112
},
113113
},
114-
LastActiveOn: Ptr(lastActiveOn),
114+
LastActiveOn: &lastActiveOn,
115115
},
116116
{
117117
ID: Ptr(int64(7)),
@@ -132,7 +132,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) {
132132
MaximumRunners: Ptr(int64(20)),
133133
PublicIPEnabled: Ptr(false),
134134
PublicIPs: []*HostedRunnerPublicIP{},
135-
LastActiveOn: Ptr(lastActiveOn),
135+
LastActiveOn: &lastActiveOn,
136136
},
137137
},
138138
}
@@ -235,7 +235,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) {
235235
Length: 31,
236236
},
237237
},
238-
LastActiveOn: Ptr(lastActiveOn),
238+
LastActiveOn: &lastActiveOn,
239239
}
240240

241241
if !cmp.Equal(hostedRunner, want) {
@@ -650,7 +650,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) {
650650
Length: 31,
651651
},
652652
},
653-
LastActiveOn: Ptr(lastActiveOn),
653+
LastActiveOn: &lastActiveOn,
654654
}
655655

656656
if !cmp.Equal(hostedRunner, want) {
@@ -747,7 +747,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) {
747747
Length: 31,
748748
},
749749
},
750-
LastActiveOn: Ptr(lastActiveOn),
750+
LastActiveOn: &lastActiveOn,
751751
}
752752

753753
if !cmp.Equal(hostedRunner, want) {
@@ -836,7 +836,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) {
836836
Length: 31,
837837
},
838838
},
839-
LastActiveOn: Ptr(lastActiveOn),
839+
LastActiveOn: &lastActiveOn,
840840
}
841841

842842
if !cmp.Equal(hostedRunner, want) {

github/git_commits_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func TestGitService_CreateSignedCommit(t *testing.T) {
235235
Tree: &Tree{SHA: Ptr("t")},
236236
Parents: []*Commit{{SHA: Ptr("p")}},
237237
Verification: &SignatureVerification{
238-
Signature: Ptr(signature),
238+
Signature: &signature,
239239
},
240240
}
241241

@@ -249,7 +249,7 @@ func TestGitService_CreateSignedCommit(t *testing.T) {
249249
Message: input.Message,
250250
Tree: Ptr("t"),
251251
Parents: []string{"p"},
252-
Signature: Ptr(signature),
252+
Signature: &signature,
253253
}
254254
if !cmp.Equal(v, want) {
255255
t.Errorf("Request body = %+v, want %+v", v, want)
@@ -336,7 +336,7 @@ Commit Message.`
336336
fmt.Fprintf(w, `{"sha":"%v"}`, sha)
337337
})
338338
ctx := t.Context()
339-
wantCommit := &Commit{SHA: Ptr(sha)}
339+
wantCommit := &Commit{SHA: &sha}
340340
opts := CreateCommitOptions{Signer: mockSigner(t, signature, nil, wantMessage)}
341341
commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input, &opts)
342342
assertNilError(t, err)

github/interactions_orgs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organiz
4545
func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, organization, limit string) (*InteractionRestriction, *Response, error) {
4646
u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
4747

48-
interaction := &InteractionRestriction{Limit: Ptr(limit)}
48+
interaction := &InteractionRestriction{Limit: &limit}
4949

5050
req, err := s.client.NewRequest("PUT", u, interaction)
5151
if err != nil {

github/interactions_repos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner,
4545
func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) {
4646
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
4747

48-
interaction := &InteractionRestriction{Limit: Ptr(limit)}
48+
interaction := &InteractionRestriction{Limit: &limit}
4949

5050
req, err := s.client.NewRequest("PUT", u, interaction)
5151
if err != nil {

0 commit comments

Comments
 (0)