From 005c343f5c74dec7dd83383a7a9262ddaced1e6f Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 10 Apr 2026 00:43:53 +0300 Subject: [PATCH 1/2] refactor: Remove redundant github.Ptr calls --- .custom-gcl.yml | 2 + .golangci.yml | 5 + example/commitpr/main.go | 2 +- github/actions_hosted_runners_test.go | 18 +- github/actions_runner_groups_test.go | 6 +- github/apps.go | 2 +- .../enterprise_actions_hosted_runners_test.go | 18 +- github/git_commits_test.go | 6 +- github/interactions_orgs.go | 2 +- github/interactions_repos.go | 2 +- github/markdown.go | 6 +- github/migrations.go | 6 +- github/migrations_user.go | 4 +- github/reactions.go | 14 +- github/repos_hooks_deliveries_test.go | 2 +- github/repos_test.go | 4 +- github/strings_benchmark_test.go | 3 +- test/integration/github_test.go | 4 +- test/integration/users_test.go | 2 +- tools/redundantptr/go.mod | 13 + tools/redundantptr/go.sum | 10 + tools/redundantptr/redundantptr.go | 239 ++++++++++++++++++ tools/redundantptr/redundantptr_test.go | 20 ++ .../google/go-github/v84/github/github.go | 10 + .../testdata/src/has-warnings/main.go | 46 ++++ .../testdata/src/no-warnings/main.go | 46 ++++ 26 files changed, 434 insertions(+), 58 deletions(-) create mode 100644 tools/redundantptr/go.mod create mode 100644 tools/redundantptr/go.sum create mode 100644 tools/redundantptr/redundantptr.go create mode 100644 tools/redundantptr/redundantptr_test.go create mode 100644 tools/redundantptr/testdata/src/github.com/google/go-github/v84/github/github.go create mode 100644 tools/redundantptr/testdata/src/has-warnings/main.go create mode 100644 tools/redundantptr/testdata/src/no-warnings/main.go diff --git a/.custom-gcl.yml b/.custom-gcl.yml index 4c2c4aae714..5e07e9c23e5 100644 --- a/.custom-gcl.yml +++ b/.custom-gcl.yml @@ -4,6 +4,8 @@ plugins: path: ./tools/extraneousnew - module: "github.com/google/go-github/v84/tools/fmtpercentv" path: ./tools/fmtpercentv + - module: "github.com/google/go-github/v84/tools/redundantptr" + path: ./tools/redundantptr - module: "github.com/google/go-github/v84/tools/sliceofpointers" path: ./tools/sliceofpointers - module: "github.com/google/go-github/v84/tools/structfield" diff --git a/.golangci.yml b/.golangci.yml index 9bc14152b66..91fb15142e7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - nolintlint - paralleltest - perfsprint + - redundantptr - revive - sliceofpointers - staticcheck @@ -193,6 +194,10 @@ linters: type: module description: Reports usage of %d or %s in format strings. original-url: github.com/google/go-github/v84/tools/fmtpercentv + redundantptr: + type: module + description: Reports github.Ptr(x) calls that can be replaced with &x. + original-url: github.com/google/go-github/v84/tools/redundantptr sliceofpointers: type: module description: Reports usage of []*string and slices of structs without pointers. diff --git a/example/commitpr/main.go b/example/commitpr/main.go index db832e3e579..12ad2fc0809 100644 --- a/example/commitpr/main.go +++ b/example/commitpr/main.go @@ -105,7 +105,7 @@ func getTree(ref *github.Reference) (tree *github.Tree, err error) { if err != nil { return nil, err } - entries = append(entries, &github.TreeEntry{Path: github.Ptr(file), Type: github.Ptr("blob"), Content: github.Ptr(string(content)), Mode: github.Ptr("100644")}) + entries = append(entries, &github.TreeEntry{Path: &file, Type: github.Ptr("blob"), Content: github.Ptr(string(content)), Mode: github.Ptr("100644")}) } tree, _, err = client.Git.CreateTree(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA, entries) diff --git a/github/actions_hosted_runners_test.go b/github/actions_hosted_runners_test.go index 08492414b9f..3e792610cb1 100644 --- a/github/actions_hosted_runners_test.go +++ b/github/actions_hosted_runners_test.go @@ -81,8 +81,6 @@ func TestActionsService_ListHostedRunners(t *testing.T) { t.Errorf("Actions.ListHostedRunners returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} - want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -111,7 +109,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), }, { ID: Ptr(int64(7)), @@ -132,7 +130,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), }, }, } @@ -210,7 +208,6 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { t.Errorf("Actions.CreateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -236,7 +233,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { @@ -626,7 +623,6 @@ func TestActionsService_GetHostedRunner(t *testing.T) { t.Errorf("Actions.GetHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -652,7 +648,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { @@ -722,7 +718,6 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { t.Errorf("Actions.UpdateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -748,7 +743,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { @@ -811,7 +806,6 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { t.Errorf("Actions.GetHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -837,7 +831,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { diff --git a/github/actions_runner_groups_test.go b/github/actions_runner_groups_test.go index 8d7354d430f..225679afa75 100644 --- a/github/actions_runner_groups_test.go +++ b/github/actions_runner_groups_test.go @@ -483,8 +483,6 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} - want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -513,7 +511,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), }, { ID: Ptr(int64(7)), @@ -534,7 +532,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), }, }, } diff --git a/github/apps.go b/github/apps.go index f08a3b2a6ea..3e38807d8ff 100644 --- a/github/apps.go +++ b/github/apps.go @@ -431,7 +431,7 @@ func (s *AppsService) CreateInstallationTokenListRepos(ctx context.Context, id i //meta:operation POST /repos/{owner}/{repo}/content_references/{content_reference_id}/attachments func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID int64, title, body string) (*Attachment, *Response, error) { u := fmt.Sprintf("content_references/%v/attachments", contentReferenceID) - payload := &Attachment{Title: Ptr(title), Body: Ptr(body)} + payload := &Attachment{Title: &title, Body: &body} req, err := s.client.NewRequest("POST", u, payload) if err != nil { return nil, nil, err diff --git a/github/enterprise_actions_hosted_runners_test.go b/github/enterprise_actions_hosted_runners_test.go index 2cca4f9e678..f1a45a5691a 100644 --- a/github/enterprise_actions_hosted_runners_test.go +++ b/github/enterprise_actions_hosted_runners_test.go @@ -81,8 +81,6 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { t.Errorf("Enterprise.ListHostedRunners returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} - want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -111,7 +109,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), }, { ID: Ptr(int64(7)), @@ -132,7 +130,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), }, }, } @@ -209,7 +207,6 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { t.Errorf("Enterprise.CreateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -235,7 +232,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { @@ -624,7 +621,6 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { t.Errorf("Enterprise.GetHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -650,7 +646,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { @@ -721,7 +717,6 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { t.Errorf("Enterprise.UpdateHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -747,7 +742,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { @@ -810,7 +805,6 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { t.Errorf("Enterprise.GetHostedRunner returned error: %v", err) } - lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -836,7 +830,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(lastActiveOn), + LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), } if !cmp.Equal(hostedRunner, want) { diff --git a/github/git_commits_test.go b/github/git_commits_test.go index 054c793268e..01ce272a0d7 100644 --- a/github/git_commits_test.go +++ b/github/git_commits_test.go @@ -235,7 +235,7 @@ func TestGitService_CreateSignedCommit(t *testing.T) { Tree: &Tree{SHA: Ptr("t")}, Parents: []*Commit{{SHA: Ptr("p")}}, Verification: &SignatureVerification{ - Signature: Ptr(signature), + Signature: &signature, }, } @@ -249,7 +249,7 @@ func TestGitService_CreateSignedCommit(t *testing.T) { Message: input.Message, Tree: Ptr("t"), Parents: []string{"p"}, - Signature: Ptr(signature), + Signature: &signature, } if !cmp.Equal(v, want) { t.Errorf("Request body = %+v, want %+v", v, want) @@ -336,7 +336,7 @@ Commit Message.` fmt.Fprintf(w, `{"sha":"%v"}`, sha) }) ctx := t.Context() - wantCommit := &Commit{SHA: Ptr(sha)} + wantCommit := &Commit{SHA: &sha} opts := CreateCommitOptions{Signer: mockSigner(t, signature, nil, wantMessage)} commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input, &opts) assertNilError(t, err) diff --git a/github/interactions_orgs.go b/github/interactions_orgs.go index 0fb9ca111fb..70e634133fd 100644 --- a/github/interactions_orgs.go +++ b/github/interactions_orgs.go @@ -45,7 +45,7 @@ func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organiz func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, organization, limit string) (*InteractionRestriction, *Response, error) { u := fmt.Sprintf("orgs/%v/interaction-limits", organization) - interaction := &InteractionRestriction{Limit: Ptr(limit)} + interaction := &InteractionRestriction{Limit: &limit} req, err := s.client.NewRequest("PUT", u, interaction) if err != nil { diff --git a/github/interactions_repos.go b/github/interactions_repos.go index 1ee37dae8ad..97f41269bc2 100644 --- a/github/interactions_repos.go +++ b/github/interactions_repos.go @@ -45,7 +45,7 @@ func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo) - interaction := &InteractionRestriction{Limit: Ptr(limit)} + interaction := &InteractionRestriction{Limit: &limit} req, err := s.client.NewRequest("PUT", u, interaction) if err != nil { diff --git a/github/markdown.go b/github/markdown.go index 7879ab8a587..143f8223acc 100644 --- a/github/markdown.go +++ b/github/markdown.go @@ -44,13 +44,13 @@ type markdownRenderRequest struct { // //meta:operation POST /markdown func (s *MarkdownService) Render(ctx context.Context, text string, opts *MarkdownOptions) (string, *Response, error) { - request := &markdownRenderRequest{Text: Ptr(text)} + request := &markdownRenderRequest{Text: &text} if opts != nil { if opts.Mode != "" { - request.Mode = Ptr(opts.Mode) + request.Mode = &opts.Mode } if opts.Context != "" { - request.Context = Ptr(opts.Context) + request.Context = &opts.Context } } diff --git a/github/migrations.go b/github/migrations.go index e68591f6459..c052ee7cf82 100644 --- a/github/migrations.go +++ b/github/migrations.go @@ -98,9 +98,9 @@ func (s *MigrationService) StartMigration(ctx context.Context, org string, repos body := &startMigration{Repositories: repos} if opts != nil { - body.LockRepositories = Ptr(opts.LockRepositories) - body.ExcludeAttachments = Ptr(opts.ExcludeAttachments) - body.ExcludeReleases = Ptr(opts.ExcludeReleases) + body.LockRepositories = &opts.LockRepositories + body.ExcludeAttachments = &opts.ExcludeAttachments + body.ExcludeReleases = &opts.ExcludeReleases body.Exclude = append(body.Exclude, opts.Exclude...) } diff --git a/github/migrations_user.go b/github/migrations_user.go index b17abad8d31..009fd848f0b 100644 --- a/github/migrations_user.go +++ b/github/migrations_user.go @@ -75,8 +75,8 @@ func (s *MigrationService) StartUserMigration(ctx context.Context, repos []strin body := &startUserMigration{Repositories: repos} if opts != nil { - body.LockRepositories = Ptr(opts.LockRepositories) - body.ExcludeAttachments = Ptr(opts.ExcludeAttachments) + body.LockRepositories = &opts.LockRepositories + body.ExcludeAttachments = &opts.ExcludeAttachments } req, err := s.client.NewRequest("POST", u, body) diff --git a/github/reactions.go b/github/reactions.go index 9097a5d6902..54b70176b1e 100644 --- a/github/reactions.go +++ b/github/reactions.go @@ -96,7 +96,7 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err @@ -174,7 +174,7 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err @@ -252,7 +252,7 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err @@ -330,7 +330,7 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err @@ -406,7 +406,7 @@ func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, team func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err @@ -481,7 +481,7 @@ func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Contex func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err @@ -542,7 +542,7 @@ func (s *ReactionsService) deleteReaction(ctx context.Context, url string) (*Res func (s *ReactionsService) CreateReleaseReaction(ctx context.Context, owner, repo string, releaseID int64, content string) (*Reaction, *Response, error) { u := fmt.Sprintf("repos/%v/%v/releases/%v/reactions", owner, repo, releaseID) - body := &Reaction{Content: Ptr(content)} + body := &Reaction{Content: &content} req, err := s.client.NewRequest("POST", u, body) if err != nil { return nil, nil, err diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index eb5043ae479..7c5261a0dd0 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -215,7 +215,7 @@ func TestHookDelivery_ParsePayload(t *testing.T) { p := json.RawMessage(bs) d := &HookDelivery{ - Event: Ptr(evt), + Event: &evt, Request: &HookRequest{ RawPayload: &p, }, diff --git a/github/repos_test.go b/github/repos_test.go index 495bdc83f74..17b0737c955 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -1296,7 +1296,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { RequireLastPushApproval: false, }, EnforceAdmins: &AdminEnforcement{ - URL: Ptr(test.enforceAdminsURLPath), + URL: &test.enforceAdminsURLPath, Enabled: true, }, Restrictions: &BranchRestrictions{ @@ -1411,7 +1411,7 @@ func TestRepositoriesService_GetBranchProtection_noDismissalRestrictions(t *test RequiredApprovingReviewCount: 1, }, EnforceAdmins: &AdminEnforcement{ - URL: Ptr(test.enforceAdminsURLPath), + URL: &test.enforceAdminsURLPath, Enabled: true, }, Restrictions: &BranchRestrictions{ diff --git a/github/strings_benchmark_test.go b/github/strings_benchmark_test.go index bec928f2bcd..b19db42c51e 100644 --- a/github/strings_benchmark_test.go +++ b/github/strings_benchmark_test.go @@ -20,7 +20,6 @@ type BenchmarkStruct struct { } func BenchmarkStringify(b *testing.B) { - val := 42 s := &BenchmarkStruct{ Name: "benchmark", Age: 30, @@ -28,7 +27,7 @@ func BenchmarkStringify(b *testing.B) { Score: 1.1, Rank: 99.999999, Tags: []string{"go", "github", "api"}, - Pointer: Ptr(val), + Pointer: Ptr(42), } b.ResetTimer() for b.Loop() { diff --git a/test/integration/github_test.go b/test/integration/github_test.go index d2151c0f098..2b3ff9a6399 100644 --- a/test/integration/github_test.go +++ b/test/integration/github_test.go @@ -70,8 +70,8 @@ func createRandomTestRepository(t *testing.T, owner string, autoinit bool) *gith t.Context(), owner, &github.Repository{ - Name: github.Ptr(repoName), - AutoInit: github.Ptr(autoinit), + Name: &repoName, + AutoInit: &autoinit, }, ) if err != nil { diff --git a/test/integration/users_test.go b/test/integration/users_test.go index ef66c690843..bb81847b5d0 100644 --- a/test/integration/users_test.go +++ b/test/integration/users_test.go @@ -184,7 +184,7 @@ func TestUsers_Keys(t *testing.T) { // Add new key _, _, err = client.Users.CreateKey(t.Context(), &github.Key{ Title: github.Ptr("go-github test key"), - Key: github.Ptr(key), + Key: &key, }) if err != nil { t.Fatalf("Users.CreateKey() returned error: %v", err) diff --git a/tools/redundantptr/go.mod b/tools/redundantptr/go.mod new file mode 100644 index 00000000000..9238745a4f3 --- /dev/null +++ b/tools/redundantptr/go.mod @@ -0,0 +1,13 @@ +module tools/redundantptr + +go 1.25.0 + +require ( + github.com/golangci/plugin-module-register v0.1.2 + golang.org/x/tools v0.43.0 +) + +require ( + golang.org/x/mod v0.34.0 // indirect + golang.org/x/sync v0.20.0 // indirect +) diff --git a/tools/redundantptr/go.sum b/tools/redundantptr/go.sum new file mode 100644 index 00000000000..a7fda4fe1fe --- /dev/null +++ b/tools/redundantptr/go.sum @@ -0,0 +1,10 @@ +github.com/golangci/plugin-module-register v0.1.2 h1:e5WM6PO6NIAEcij3B053CohVp3HIYbzSuP53UAYgOpg= +github.com/golangci/plugin-module-register v0.1.2/go.mod h1:1+QGTsKBvAIvPvoY/os+G5eoqxWn70HYDm2uvUyGuVw= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI= +golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s= +golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0= diff --git a/tools/redundantptr/redundantptr.go b/tools/redundantptr/redundantptr.go new file mode 100644 index 00000000000..951e06bfed3 --- /dev/null +++ b/tools/redundantptr/redundantptr.go @@ -0,0 +1,239 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package redundantptr is a custom linter to find redundant github.Ptr calls. +package redundantptr + +import ( + "bytes" + "go/ast" + "go/format" + "go/token" + + "github.com/golangci/plugin-module-register/register" + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/ast/astutil" +) + +func init() { + register.Plugin("redundantptr", New) +} + +// RedundantPtrPlugin is a custom linter plugin for golangci-lint. +type RedundantPtrPlugin struct{} + +// New returns an analysis.Analyzer to use with golangci-lint. +func New(_ any) (register.LinterPlugin, error) { + return &RedundantPtrPlugin{}, nil +} + +// BuildAnalyzers builds the analyzers for the RedundantPtrPlugin. +func (p *RedundantPtrPlugin) BuildAnalyzers() ([]*analysis.Analyzer, error) { + return []*analysis.Analyzer{ + { + Name: "redundantptr", + Doc: "Reports github.Ptr(x) calls that can be replaced with &x.", + Run: run, + }, + }, nil +} + +// GetLoadMode returns the load mode for the RedundantPtrPlugin. +func (p *RedundantPtrPlugin) GetLoadMode() string { + return register.LoadModeSyntax +} + +func run(pass *analysis.Pass) (any, error) { + for _, file := range pass.Files { + ast.Inspect(file, func(n ast.Node) bool { + switch fn := n.(type) { + case *ast.FuncDecl: + if fn.Body != nil { + analyzeFunction(pass, fn, fn.Body) + } + case *ast.FuncLit: + analyzeFunction(pass, fn, fn.Body) + } + return true + }) + } + + return nil, nil +} + +func analyzeFunction(pass *analysis.Pass, fn ast.Node, body *ast.BlockStmt) { + if shouldIgnoreDeprecatedPtrWrapper(fn) { + return + } + + locals := collectLocals(fn, body) + + astutil.Apply(body, func(cursor *astutil.Cursor) bool { + call, ok := cursor.Node().(*ast.CallExpr) + if !ok { + return true + } + + rootName, argText := redundantPtrCall(pass, call) + if rootName == "" || argText == "" { + return true + } + + if !locals[rootName] { + return true + } + + replacement := "&" + argText + pass.Report(analysis.Diagnostic{ + Pos: call.Pos(), + End: call.End(), + Message: "replace github.Ptr(" + argText + ") with " + replacement, + SuggestedFixes: []analysis.SuggestedFix{ + { + Message: "Use address-of operator", + TextEdits: []analysis.TextEdit{ + {Pos: call.Pos(), End: call.End(), NewText: []byte(replacement)}, + }, + }, + }, + }) + return true + }, nil) +} + +func redundantPtrCall(pass *analysis.Pass, call *ast.CallExpr) (rootName, argText string) { + if len(call.Args) != 1 { + return "", "" + } + + switch fun := call.Fun.(type) { + case *ast.SelectorExpr: + if fun.Sel == nil || fun.Sel.Name != "Ptr" { + return "", "" + } + qual, ok := fun.X.(*ast.Ident) + if !ok || qual.Name != "github" { + return "", "" + } + case *ast.Ident: + if fun.Name != "Ptr" { + return "", "" + } + default: + return "", "" + } + + arg := call.Args[0] + root := rootIdentName(arg) + if root == "" { + return "", "" + } + return root, exprString(pass, arg) +} + +func rootIdentName(expr ast.Expr) string { + switch e := expr.(type) { + case *ast.Ident: + return e.Name + case *ast.SelectorExpr: + return rootIdentName(e.X) + default: + return "" + } +} + +func exprString(pass *analysis.Pass, expr ast.Expr) string { + var b bytes.Buffer + if err := format.Node(&b, pass.Fset, expr); err != nil { + return "" + } + return b.String() +} + +func collectLocals(fn ast.Node, body *ast.BlockStmt) map[string]bool { + locals := map[string]bool{} + + switch node := fn.(type) { + case *ast.FuncDecl: + addFieldListNames(locals, node.Recv) + addFieldListNames(locals, node.Type.Params) + addFieldListNames(locals, node.Type.Results) + case *ast.FuncLit: + addFieldListNames(locals, node.Type.Params) + addFieldListNames(locals, node.Type.Results) + } + + ast.Inspect(body, func(n ast.Node) bool { + switch stmt := n.(type) { + case *ast.DeclStmt: + gen, ok := stmt.Decl.(*ast.GenDecl) + if !ok || gen.Tok != token.VAR { + return true + } + for _, spec := range gen.Specs { + valueSpec, ok := spec.(*ast.ValueSpec) + if !ok { + continue + } + for _, name := range valueSpec.Names { + locals[name.Name] = true + } + } + case *ast.AssignStmt: + if stmt.Tok == token.DEFINE { + for _, lhs := range stmt.Lhs { + ident, ok := lhs.(*ast.Ident) + if !ok || ident.Name == "_" { + continue + } + locals[ident.Name] = true + } + } + case *ast.RangeStmt: + if stmt.Tok == token.DEFINE { + if ident, ok := stmt.Key.(*ast.Ident); ok && ident.Name != "_" { + locals[ident.Name] = true + } + if ident, ok := stmt.Value.(*ast.Ident); ok && ident.Name != "_" { + locals[ident.Name] = true + } + } + } + return true + }) + + return locals +} + +func addFieldListNames(locals map[string]bool, fields *ast.FieldList) { + if fields == nil { + return + } + for _, field := range fields.List { + for _, name := range field.Names { + if name.Name != "_" { + locals[name.Name] = true + } + } + } +} + +func shouldIgnoreDeprecatedPtrWrapper(fn ast.Node) bool { + decl, ok := fn.(*ast.FuncDecl) + if !ok { + return false + } + + if decl.Recv != nil || decl.Name == nil { + return false + } + + switch decl.Name.Name { + case "Bool", "Int", "Int64", "String": + return true + default: + return false + } +} diff --git a/tools/redundantptr/redundantptr_test.go b/tools/redundantptr/redundantptr_test.go new file mode 100644 index 00000000000..2b8465db0dd --- /dev/null +++ b/tools/redundantptr/redundantptr_test.go @@ -0,0 +1,20 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package redundantptr + +import ( + "testing" + + "golang.org/x/tools/go/analysis/analysistest" +) + +func TestRun(t *testing.T) { + t.Parallel() + testdata := analysistest.TestData() + plugin, _ := New(nil) + analyzers, _ := plugin.BuildAnalyzers() + analysistest.Run(t, testdata, analyzers[0], "has-warnings", "no-warnings") +} diff --git a/tools/redundantptr/testdata/src/github.com/google/go-github/v84/github/github.go b/tools/redundantptr/testdata/src/github.com/google/go-github/v84/github/github.go new file mode 100644 index 00000000000..994d06a400a --- /dev/null +++ b/tools/redundantptr/testdata/src/github.com/google/go-github/v84/github/github.go @@ -0,0 +1,10 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +func Ptr[T any](v T) *T { + return &v +} diff --git a/tools/redundantptr/testdata/src/has-warnings/main.go b/tools/redundantptr/testdata/src/has-warnings/main.go new file mode 100644 index 00000000000..4b78bad402e --- /dev/null +++ b/tools/redundantptr/testdata/src/has-warnings/main.go @@ -0,0 +1,46 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "github.com/google/go-github/v84/github" +) + +func main() { + file, content := getFileAndContent() + opts := struct { + Mode string + }{Mode: "gfm"} + + _ = github.Ptr(string(content)) + + _ = github.Ptr(file) // want `replace github.Ptr\(file\) with &file` + + other := "b.txt" + _ = github.Ptr(other) // want `replace github.Ptr\(other\) with &other` + _ = github.Ptr(opts.Mode) // want `replace github.Ptr\(opts.Mode\) with &opts.Mode` + + for _, loopFile := range []string{"x", "y"} { + _ = github.Ptr(loopFile) // want `replace github.Ptr\(loopFile\) with &loopFile` + } + + name := "before" + _ = github.Ptr(name) // want `replace github.Ptr\(name\) with &name` + name = "after" + _ = github.Ptr(name) // want `replace github.Ptr\(name\) with &name` + + i := 1 + _ = Ptr(i) // want `replace github.Ptr\(i\) with &i` + _ = Ptr(opts.Mode) // want `replace github.Ptr\(opts.Mode\) with &opts.Mode` +} + +func getFileAndContent() (string, []byte) { + return "", nil +} + +func Ptr[T any](v T) *T { + return &v +} diff --git a/tools/redundantptr/testdata/src/no-warnings/main.go b/tools/redundantptr/testdata/src/no-warnings/main.go new file mode 100644 index 00000000000..6f7f392f9a9 --- /dev/null +++ b/tools/redundantptr/testdata/src/no-warnings/main.go @@ -0,0 +1,46 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "github.com/google/go-github/v84/github" + +func main() { + // Literal argument cannot be addressed. + _ = github.Ptr("a.txt") + + const file = "a.txt" + _ = github.Ptr(file) + + for range []int{1, 2} { + _ = github.Ptr("a") + } + + _ = github.Ptr(getOptions().Mode) +} + +func getOptions() struct { + Mode string +} { + return struct { + Mode string + }{Mode: "gfm"} +} + +func unqualifiedIdentifierArgumentDoesNotWarn() { + _ = Ptr("x") +} + +func Bool(v bool) *bool { return Ptr(v) } + +func Int(v int) *int { return Ptr(v) } + +func Int64(v int64) *int64 { return Ptr(v) } + +func String(v string) *string { return Ptr(v) } + +func Ptr[T any](v T) *T { + return &v +} From 28ea3257cf4a10b75e51b0103daee83c29c3429d Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 10 Apr 2026 09:41:10 +0300 Subject: [PATCH 2/2] restore lastActiveOn variables in hosted runner tests --- github/actions_hosted_runners_test.go | 18 ++++++++++++------ github/actions_runner_groups_test.go | 6 ++++-- .../enterprise_actions_hosted_runners_test.go | 18 ++++++++++++------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/github/actions_hosted_runners_test.go b/github/actions_hosted_runners_test.go index 3e792610cb1..10d97162b6b 100644 --- a/github/actions_hosted_runners_test.go +++ b/github/actions_hosted_runners_test.go @@ -81,6 +81,8 @@ func TestActionsService_ListHostedRunners(t *testing.T) { t.Errorf("Actions.ListHostedRunners returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} + want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -109,7 +111,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, }, { ID: Ptr(int64(7)), @@ -130,7 +132,7 @@ func TestActionsService_ListHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, }, }, } @@ -208,6 +210,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { t.Errorf("Actions.CreateHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -233,7 +236,7 @@ func TestActionsService_CreateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { @@ -623,6 +626,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) { t.Errorf("Actions.GetHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -648,7 +652,7 @@ func TestActionsService_GetHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { @@ -718,6 +722,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { t.Errorf("Actions.UpdateHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -743,7 +748,7 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { @@ -806,6 +811,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { t.Errorf("Actions.GetHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -831,7 +837,7 @@ func TestActionsService_DeleteHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { diff --git a/github/actions_runner_groups_test.go b/github/actions_runner_groups_test.go index 225679afa75..c7424d7a152 100644 --- a/github/actions_runner_groups_test.go +++ b/github/actions_runner_groups_test.go @@ -483,6 +483,8 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} + want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -511,7 +513,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, }, { ID: Ptr(int64(7)), @@ -532,7 +534,7 @@ func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, }, }, } diff --git a/github/enterprise_actions_hosted_runners_test.go b/github/enterprise_actions_hosted_runners_test.go index f1a45a5691a..1bff9ccf8c7 100644 --- a/github/enterprise_actions_hosted_runners_test.go +++ b/github/enterprise_actions_hosted_runners_test.go @@ -81,6 +81,8 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { t.Errorf("Enterprise.ListHostedRunners returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} + want := &HostedRunners{ TotalCount: 2, Runners: []*HostedRunner{ @@ -109,7 +111,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, }, { ID: Ptr(int64(7)), @@ -130,7 +132,7 @@ func TestEnterpriseService_ListHostedRunners(t *testing.T) { MaximumRunners: Ptr(int64(20)), PublicIPEnabled: Ptr(false), PublicIPs: []*HostedRunnerPublicIP{}, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, }, }, } @@ -207,6 +209,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { t.Errorf("Enterprise.CreateHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -232,7 +235,7 @@ func TestEnterpriseService_CreateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { @@ -621,6 +624,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { t.Errorf("Enterprise.GetHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -646,7 +650,7 @@ func TestEnterpriseService_GetHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { @@ -717,6 +721,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { t.Errorf("Enterprise.UpdateHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -742,7 +747,7 @@ func TestEnterpriseService_UpdateHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) { @@ -805,6 +810,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { t.Errorf("Enterprise.GetHostedRunner returned error: %v", err) } + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} want := &HostedRunner{ ID: Ptr(int64(5)), Name: Ptr("My hosted ubuntu runner"), @@ -830,7 +836,7 @@ func TestEnterpriseService_DeleteHostedRunner(t *testing.T) { Length: 31, }, }, - LastActiveOn: Ptr(Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)}), + LastActiveOn: &lastActiveOn, } if !cmp.Equal(hostedRunner, want) {