Skip to content

Commit 005c343

Browse files
committed
refactor: Remove redundant github.Ptr calls
1 parent 5124fac commit 005c343

26 files changed

Lines changed: 434 additions & 58 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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ func TestActionsService_ListHostedRunners(t *testing.T) {
8181
t.Errorf("Actions.ListHostedRunners returned error: %v", err)
8282
}
8383

84-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
85-
8684
want := &HostedRunners{
8785
TotalCount: 2,
8886
Runners: []*HostedRunner{
@@ -111,7 +109,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) {
111109
Length: 31,
112110
},
113111
},
114-
LastActiveOn: Ptr(lastActiveOn),
112+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
115113
},
116114
{
117115
ID: Ptr(int64(7)),
@@ -132,7 +130,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) {
132130
MaximumRunners: Ptr(int64(20)),
133131
PublicIPEnabled: Ptr(false),
134132
PublicIPs: []*HostedRunnerPublicIP{},
135-
LastActiveOn: Ptr(lastActiveOn),
133+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
136134
},
137135
},
138136
}
@@ -210,7 +208,6 @@ func TestActionsService_CreateHostedRunner(t *testing.T) {
210208
t.Errorf("Actions.CreateHostedRunner returned error: %v", err)
211209
}
212210

213-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
214211
want := &HostedRunner{
215212
ID: Ptr(int64(5)),
216213
Name: Ptr("My hosted ubuntu runner"),
@@ -236,7 +233,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) {
236233
Length: 31,
237234
},
238235
},
239-
LastActiveOn: Ptr(lastActiveOn),
236+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
240237
}
241238

242239
if !cmp.Equal(hostedRunner, want) {
@@ -626,7 +623,6 @@ func TestActionsService_GetHostedRunner(t *testing.T) {
626623
t.Errorf("Actions.GetHostedRunner returned error: %v", err)
627624
}
628625

629-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
630626
want := &HostedRunner{
631627
ID: Ptr(int64(5)),
632628
Name: Ptr("My hosted ubuntu runner"),
@@ -652,7 +648,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) {
652648
Length: 31,
653649
},
654650
},
655-
LastActiveOn: Ptr(lastActiveOn),
651+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
656652
}
657653

658654
if !cmp.Equal(hostedRunner, want) {
@@ -722,7 +718,6 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) {
722718
t.Errorf("Actions.UpdateHostedRunner returned error: %v", err)
723719
}
724720

725-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
726721
want := &HostedRunner{
727722
ID: Ptr(int64(5)),
728723
Name: Ptr("My hosted ubuntu runner"),
@@ -748,7 +743,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) {
748743
Length: 31,
749744
},
750745
},
751-
LastActiveOn: Ptr(lastActiveOn),
746+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
752747
}
753748

754749
if !cmp.Equal(hostedRunner, want) {
@@ -811,7 +806,6 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) {
811806
t.Errorf("Actions.GetHostedRunner returned error: %v", err)
812807
}
813808

814-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
815809
want := &HostedRunner{
816810
ID: Ptr(int64(5)),
817811
Name: Ptr("My hosted ubuntu runner"),
@@ -837,7 +831,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) {
837831
Length: 31,
838832
},
839833
},
840-
LastActiveOn: Ptr(lastActiveOn),
834+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
841835
}
842836

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

github/actions_runner_groups_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
483483
t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err)
484484
}
485485

486-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
487-
488486
want := &HostedRunners{
489487
TotalCount: 2,
490488
Runners: []*HostedRunner{
@@ -513,7 +511,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
513511
Length: 31,
514512
},
515513
},
516-
LastActiveOn: Ptr(lastActiveOn),
514+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
517515
},
518516
{
519517
ID: Ptr(int64(7)),
@@ -534,7 +532,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) {
534532
MaximumRunners: Ptr(int64(20)),
535533
PublicIPEnabled: Ptr(false),
536534
PublicIPs: []*HostedRunnerPublicIP{},
537-
LastActiveOn: Ptr(lastActiveOn),
535+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
538536
},
539537
},
540538
}

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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) {
8181
t.Errorf("Enterprise.ListHostedRunners returned error: %v", err)
8282
}
8383

84-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
85-
8684
want := &HostedRunners{
8785
TotalCount: 2,
8886
Runners: []*HostedRunner{
@@ -111,7 +109,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) {
111109
Length: 31,
112110
},
113111
},
114-
LastActiveOn: Ptr(lastActiveOn),
112+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
115113
},
116114
{
117115
ID: Ptr(int64(7)),
@@ -132,7 +130,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) {
132130
MaximumRunners: Ptr(int64(20)),
133131
PublicIPEnabled: Ptr(false),
134132
PublicIPs: []*HostedRunnerPublicIP{},
135-
LastActiveOn: Ptr(lastActiveOn),
133+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
136134
},
137135
},
138136
}
@@ -209,7 +207,6 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) {
209207
t.Errorf("Enterprise.CreateHostedRunner returned error: %v", err)
210208
}
211209

212-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
213210
want := &HostedRunner{
214211
ID: Ptr(int64(5)),
215212
Name: Ptr("My hosted ubuntu runner"),
@@ -235,7 +232,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) {
235232
Length: 31,
236233
},
237234
},
238-
LastActiveOn: Ptr(lastActiveOn),
235+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
239236
}
240237

241238
if !cmp.Equal(hostedRunner, want) {
@@ -624,7 +621,6 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) {
624621
t.Errorf("Enterprise.GetHostedRunner returned error: %v", err)
625622
}
626623

627-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
628624
want := &HostedRunner{
629625
ID: Ptr(int64(5)),
630626
Name: Ptr("My hosted ubuntu runner"),
@@ -650,7 +646,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) {
650646
Length: 31,
651647
},
652648
},
653-
LastActiveOn: Ptr(lastActiveOn),
649+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
654650
}
655651

656652
if !cmp.Equal(hostedRunner, want) {
@@ -721,7 +717,6 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) {
721717
t.Errorf("Enterprise.UpdateHostedRunner returned error: %v", err)
722718
}
723719

724-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
725720
want := &HostedRunner{
726721
ID: Ptr(int64(5)),
727722
Name: Ptr("My hosted ubuntu runner"),
@@ -747,7 +742,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) {
747742
Length: 31,
748743
},
749744
},
750-
LastActiveOn: Ptr(lastActiveOn),
745+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
751746
}
752747

753748
if !cmp.Equal(hostedRunner, want) {
@@ -810,7 +805,6 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) {
810805
t.Errorf("Enterprise.GetHostedRunner returned error: %v", err)
811806
}
812807

813-
lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}
814808
want := &HostedRunner{
815809
ID: Ptr(int64(5)),
816810
Name: Ptr("My hosted ubuntu runner"),
@@ -836,7 +830,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) {
836830
Length: 31,
837831
},
838832
},
839-
LastActiveOn: Ptr(lastActiveOn),
833+
LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}),
840834
}
841835

842836
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)