Skip to content

Commit f66ed85

Browse files
authored
feat: Deprecate and replace Bool,Int,Int64,String with Ptr using generics (#3355)
1 parent f349af0 commit f66ed85

File tree

175 files changed

+15076
-15050
lines changed

Some content is hidden

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

175 files changed

+15076
-15050
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ bool, and int values. For example:
279279
```go
280280
// create a new private repository named "foo"
281281
repo := &github.Repository{
282-
Name: github.String("foo"),
283-
Private: github.Bool(true),
282+
Name: github.Ptr("foo"),
283+
Private: github.Ptr(true),
284284
}
285285
client.Repositories.Create(ctx, "", repo)
286286
```

example/actionpermissions/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444

4545
fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String())
4646

47-
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Bool(true), AllowedActions: github.String("selected")}
47+
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("selected")}
4848
_, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
4949
if err != nil {
5050
log.Fatal(err)
@@ -59,15 +59,15 @@ func main() {
5959

6060
fmt.Printf("Current ActionsAllowed %s\n", actionsAllowed.String())
6161

62-
actionsAllowed = &github.ActionsAllowed{GithubOwnedAllowed: github.Bool(true), VerifiedAllowed: github.Bool(false), PatternsAllowed: []string{"a/b"}}
62+
actionsAllowed = &github.ActionsAllowed{GithubOwnedAllowed: github.Ptr(true), VerifiedAllowed: github.Ptr(false), PatternsAllowed: []string{"a/b"}}
6363
_, _, err = client.Repositories.EditActionsAllowed(ctx, *owner, *name, *actionsAllowed)
6464
if err != nil {
6565
log.Fatal(err)
6666
}
6767

6868
fmt.Printf("Current ActionsAllowed %s\n", actionsAllowed.String())
6969

70-
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Bool(true), AllowedActions: github.String("all")}
70+
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("all")}
7171
_, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
7272
if err != nil {
7373
log.Fatal(err)

example/commitpr/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func getRef() (ref *github.Reference, err error) {
8181
if baseRef, _, err = client.Git.GetRef(ctx, *sourceOwner, *sourceRepo, "refs/heads/"+*baseBranch); err != nil {
8282
return nil, err
8383
}
84-
newRef := &github.Reference{Ref: github.String("refs/heads/" + *commitBranch), Object: &github.GitObject{SHA: baseRef.Object.SHA}}
84+
newRef := &github.Reference{Ref: github.Ptr("refs/heads/" + *commitBranch), Object: &github.GitObject{SHA: baseRef.Object.SHA}}
8585
ref, _, err = client.Git.CreateRef(ctx, *sourceOwner, *sourceRepo, newRef)
8686
return ref, err
8787
}
@@ -98,7 +98,7 @@ func getTree(ref *github.Reference) (tree *github.Tree, err error) {
9898
if err != nil {
9999
return nil, err
100100
}
101-
entries = append(entries, &github.TreeEntry{Path: github.String(file), Type: github.String("blob"), Content: github.String(string(content)), Mode: github.String("100644")})
101+
entries = append(entries, &github.TreeEntry{Path: github.Ptr(file), Type: github.Ptr("blob"), Content: github.Ptr(string(content)), Mode: github.Ptr("100644")})
102102
}
103103

104104
tree, _, err = client.Git.CreateTree(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA, entries)
@@ -190,7 +190,7 @@ func createPR() (err error) {
190190
HeadRepo: repoBranch,
191191
Base: prBranch,
192192
Body: prDescription,
193-
MaintainerCanModify: github.Bool(true),
193+
MaintainerCanModify: github.Ptr(true),
194194
}
195195

196196
pr, _, err := client.PullRequests.Create(ctx, *prRepoOwner, *prRepo, newPR)

example/newfilewithappauth/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func main() {
7979
"example/foo.txt",
8080
&github.RepositoryContentFileOptions{
8181
Content: []byte("foo"),
82-
Message: github.String("sample commit"),
82+
Message: github.Ptr("sample commit"),
8383
SHA: nil,
8484
})
8585
if err != nil {

github/actions_artifacts_test.go

+33-33
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
3232
})
3333

3434
opts := &ListArtifactsOptions{
35-
Name: String("TheArtifact"),
35+
Name: Ptr("TheArtifact"),
3636
ListOptions: ListOptions{Page: 2},
3737
}
3838
ctx := context.Background()
@@ -41,7 +41,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
4141
t.Errorf("Actions.ListArtifacts returned error: %v", err)
4242
}
4343

44-
want := &ArtifactList{TotalCount: Int64(1), Artifacts: []*Artifact{{ID: Int64(1)}}}
44+
want := &ArtifactList{TotalCount: Ptr(int64(1)), Artifacts: []*Artifact{{ID: Ptr(int64(1))}}}
4545
if !cmp.Equal(artifacts, want) {
4646
t.Errorf("Actions.ListArtifacts returned %+v, want %+v", artifacts, want)
4747
}
@@ -123,7 +123,7 @@ func TestActionsService_ListWorkflowRunArtifacts(t *testing.T) {
123123
t.Errorf("Actions.ListWorkflowRunArtifacts returned error: %v", err)
124124
}
125125

126-
want := &ArtifactList{TotalCount: Int64(1), Artifacts: []*Artifact{{ID: Int64(1)}}}
126+
want := &ArtifactList{TotalCount: Ptr(int64(1)), Artifacts: []*Artifact{{ID: Ptr(int64(1))}}}
127127
if !cmp.Equal(artifacts, want) {
128128
t.Errorf("Actions.ListWorkflowRunArtifacts returned %+v, want %+v", artifacts, want)
129129
}
@@ -205,11 +205,11 @@ func TestActionsService_GetArtifact(t *testing.T) {
205205
}
206206

207207
want := &Artifact{
208-
ID: Int64(1),
209-
NodeID: String("xyz"),
210-
Name: String("a"),
211-
SizeInBytes: Int64(5),
212-
ArchiveDownloadURL: String("u"),
208+
ID: Ptr(int64(1)),
209+
NodeID: Ptr("xyz"),
210+
Name: Ptr("a"),
211+
SizeInBytes: Ptr(int64(5)),
212+
ArchiveDownloadURL: Ptr("u"),
213213
}
214214
if !cmp.Equal(artifact, want) {
215215
t.Errorf("Actions.GetArtifact returned %+v, want %+v", artifact, want)
@@ -438,22 +438,22 @@ func TestArtifact_Marshal(t *testing.T) {
438438
testJSONMarshal(t, &Artifact{}, "{}")
439439

440440
u := &Artifact{
441-
ID: Int64(1),
442-
NodeID: String("nid"),
443-
Name: String("n"),
444-
SizeInBytes: Int64(1),
445-
URL: String("u"),
446-
ArchiveDownloadURL: String("a"),
447-
Expired: Bool(false),
441+
ID: Ptr(int64(1)),
442+
NodeID: Ptr("nid"),
443+
Name: Ptr("n"),
444+
SizeInBytes: Ptr(int64(1)),
445+
URL: Ptr("u"),
446+
ArchiveDownloadURL: Ptr("a"),
447+
Expired: Ptr(false),
448448
CreatedAt: &Timestamp{referenceTime},
449449
UpdatedAt: &Timestamp{referenceTime},
450450
ExpiresAt: &Timestamp{referenceTime},
451451
WorkflowRun: &ArtifactWorkflowRun{
452-
ID: Int64(1),
453-
RepositoryID: Int64(1),
454-
HeadRepositoryID: Int64(1),
455-
HeadBranch: String("b"),
456-
HeadSHA: String("s"),
452+
ID: Ptr(int64(1)),
453+
RepositoryID: Ptr(int64(1)),
454+
HeadRepositoryID: Ptr(int64(1)),
455+
HeadBranch: Ptr("b"),
456+
HeadSHA: Ptr("s"),
457457
},
458458
}
459459

@@ -485,25 +485,25 @@ func TestArtifactList_Marshal(t *testing.T) {
485485
testJSONMarshal(t, &ArtifactList{}, "{}")
486486

487487
u := &ArtifactList{
488-
TotalCount: Int64(1),
488+
TotalCount: Ptr(int64(1)),
489489
Artifacts: []*Artifact{
490490
{
491-
ID: Int64(1),
492-
NodeID: String("nid"),
493-
Name: String("n"),
494-
SizeInBytes: Int64(1),
495-
URL: String("u"),
496-
ArchiveDownloadURL: String("a"),
497-
Expired: Bool(false),
491+
ID: Ptr(int64(1)),
492+
NodeID: Ptr("nid"),
493+
Name: Ptr("n"),
494+
SizeInBytes: Ptr(int64(1)),
495+
URL: Ptr("u"),
496+
ArchiveDownloadURL: Ptr("a"),
497+
Expired: Ptr(false),
498498
CreatedAt: &Timestamp{referenceTime},
499499
UpdatedAt: &Timestamp{referenceTime},
500500
ExpiresAt: &Timestamp{referenceTime},
501501
WorkflowRun: &ArtifactWorkflowRun{
502-
ID: Int64(1),
503-
RepositoryID: Int64(1),
504-
HeadRepositoryID: Int64(1),
505-
HeadBranch: String("b"),
506-
HeadSHA: String("s"),
502+
ID: Ptr(int64(1)),
503+
RepositoryID: Ptr(int64(1)),
504+
HeadRepositoryID: Ptr(int64(1)),
505+
HeadBranch: Ptr("b"),
506+
HeadSHA: Ptr("s"),
507507
},
508508
},
509509
},

github/actions_cache_test.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestActionsService_ListCaches(t *testing.T) {
3636
t.Errorf("Actions.ListCaches returned error: %v", err)
3737
}
3838

39-
want := &ActionsCacheList{TotalCount: 1, ActionsCaches: []*ActionsCache{{ID: Int64(1)}}}
39+
want := &ActionsCacheList{TotalCount: 1, ActionsCaches: []*ActionsCache{{ID: Ptr(int64(1))}}}
4040
if !cmp.Equal(cacheList, want) {
4141
t.Errorf("Actions.ListCaches returned %+v, want %+v", cacheList, want)
4242
}
@@ -106,19 +106,19 @@ func TestActionsService_DeleteCachesByKey(t *testing.T) {
106106
})
107107

108108
ctx := context.Background()
109-
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", String("main"))
109+
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", Ptr("main"))
110110
if err != nil {
111111
t.Errorf("Actions.DeleteCachesByKey return error: %v", err)
112112
}
113113

114114
const methodName = "DeleteCachesByKey"
115115
testBadOptions(t, methodName, func() (err error) {
116-
_, err = client.Actions.DeleteCachesByKey(ctx, "\n", "\n", "\n", String("\n"))
116+
_, err = client.Actions.DeleteCachesByKey(ctx, "\n", "\n", "\n", Ptr("\n"))
117117
return err
118118
})
119119

120120
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
121-
return client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", String("main"))
121+
return client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", Ptr("main"))
122122
})
123123
}
124124

@@ -127,7 +127,7 @@ func TestActionsService_DeleteCachesByKey_invalidOwner(t *testing.T) {
127127
client, _, _ := setup(t)
128128

129129
ctx := context.Background()
130-
_, err := client.Actions.DeleteCachesByKey(ctx, "%", "r", "1", String("main"))
130+
_, err := client.Actions.DeleteCachesByKey(ctx, "%", "r", "1", Ptr("main"))
131131
testURLParseError(t, err)
132132
}
133133

@@ -136,7 +136,7 @@ func TestActionsService_DeleteCachesByKey_invalidRepo(t *testing.T) {
136136
client, _, _ := setup(t)
137137

138138
ctx := context.Background()
139-
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "%", "1", String("main"))
139+
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "%", "1", Ptr("main"))
140140
testURLParseError(t, err)
141141
}
142142
func TestActionsService_DeleteCachesByKey_notFound(t *testing.T) {
@@ -149,7 +149,7 @@ func TestActionsService_DeleteCachesByKey_notFound(t *testing.T) {
149149
})
150150

151151
ctx := context.Background()
152-
resp, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", String("main"))
152+
resp, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", Ptr("main"))
153153
if err == nil {
154154
t.Errorf("Expected HTTP 404 response")
155155
}
@@ -521,13 +521,13 @@ func TestActionsCache_Marshal(t *testing.T) {
521521
testJSONMarshal(t, &ActionsCache{}, "{}")
522522

523523
u := &ActionsCache{
524-
ID: Int64(1),
525-
Ref: String("refAction"),
526-
Key: String("key1"),
527-
Version: String("alpha"),
524+
ID: Ptr(int64(1)),
525+
Ref: Ptr("refAction"),
526+
Key: Ptr("key1"),
527+
Version: Ptr("alpha"),
528528
LastAccessedAt: &Timestamp{referenceTime},
529529
CreatedAt: &Timestamp{referenceTime},
530-
SizeInBytes: Int64(1),
530+
SizeInBytes: Ptr(int64(1)),
531531
}
532532

533533
want := `{
@@ -551,19 +551,19 @@ func TestActionsCacheList_Marshal(t *testing.T) {
551551
TotalCount: 2,
552552
ActionsCaches: []*ActionsCache{
553553
{
554-
ID: Int64(1),
555-
Key: String("key1"),
556-
Version: String("alpha"),
554+
ID: Ptr(int64(1)),
555+
Key: Ptr("key1"),
556+
Version: Ptr("alpha"),
557557
LastAccessedAt: &Timestamp{referenceTime},
558558
CreatedAt: &Timestamp{referenceTime},
559-
SizeInBytes: Int64(1),
559+
SizeInBytes: Ptr(int64(1)),
560560
},
561561
{
562-
ID: Int64(2),
563-
Ref: String("refAction"),
562+
ID: Ptr(int64(2)),
563+
Ref: Ptr("refAction"),
564564
LastAccessedAt: &Timestamp{referenceTime},
565565
CreatedAt: &Timestamp{referenceTime},
566-
SizeInBytes: Int64(1),
566+
SizeInBytes: Ptr(int64(1)),
567567
},
568568
},
569569
}

github/actions_oidc_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestActionsService_GetRepoOIDCSubjectClaimCustomTemplate(t *testing.T) {
6464
t.Errorf("Actions.GetRepoOIDCSubjectClaimCustomTemplate returned error: %v", err)
6565
}
6666

67-
want := &OIDCSubjectClaimCustomTemplate{UseDefault: Bool(false), IncludeClaimKeys: []string{"repo", "context"}}
67+
want := &OIDCSubjectClaimCustomTemplate{UseDefault: Ptr(false), IncludeClaimKeys: []string{"repo", "context"}}
6868
if !cmp.Equal(template, want) {
6969
t.Errorf("Actions.GetOrgOIDCSubjectClaimCustomTemplate returned %+v, want %+v", template, want)
7070
}
@@ -128,7 +128,7 @@ func TestActionsService_SetRepoOIDCSubjectClaimCustomTemplate(t *testing.T) {
128128
})
129129

130130
input := &OIDCSubjectClaimCustomTemplate{
131-
UseDefault: Bool(false),
131+
UseDefault: Ptr(false),
132132
IncludeClaimKeys: []string{"repo", "context"},
133133
}
134134
ctx := context.Background()
@@ -161,7 +161,7 @@ func TestActionService_SetRepoOIDCSubjectClaimCustomTemplateToDefault(t *testing
161161
})
162162

163163
input := &OIDCSubjectClaimCustomTemplate{
164-
UseDefault: Bool(true),
164+
UseDefault: Ptr(true),
165165
}
166166
ctx := context.Background()
167167
_, err := client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
@@ -185,7 +185,7 @@ func TestOIDCSubjectClaimCustomTemplate_Marshal(t *testing.T) {
185185
testJSONMarshal(t, &OIDCSubjectClaimCustomTemplate{}, "{}")
186186

187187
u := &OIDCSubjectClaimCustomTemplate{
188-
UseDefault: Bool(false),
188+
UseDefault: Ptr(false),
189189
IncludeClaimKeys: []string{"s"},
190190
}
191191

0 commit comments

Comments
 (0)