Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Deprecate and replace Bool,Int,Int64,String with Ptr using generics #3355

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Deprecate and replace Bool,Int,Int64,String with Ptr using gene…
…rics
  • Loading branch information
alexandear committed Nov 22, 2024

Verified

This commit was signed with the committer’s verified signature.
pmalouin Patrick Malouin
commit d2545da66f788d1f87ac853160466d40394e0e5e
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -279,8 +279,8 @@ bool, and int values. For example:
```go
// create a new private repository named "foo"
repo := &github.Repository{
Name: github.String("foo"),
Private: github.Bool(true),
Name: github.Ptr("foo"),
Private: github.Ptr(true),
}
client.Repositories.Create(ctx, "", repo)
```
6 changes: 3 additions & 3 deletions example/actionpermissions/main.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ func main() {

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

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

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

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

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

actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Bool(true), AllowedActions: github.String("all")}
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("all")}
_, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
if err != nil {
log.Fatal(err)
6 changes: 3 additions & 3 deletions example/commitpr/main.go
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ func getRef() (ref *github.Reference, err error) {
if baseRef, _, err = client.Git.GetRef(ctx, *sourceOwner, *sourceRepo, "refs/heads/"+*baseBranch); err != nil {
return nil, err
}
newRef := &github.Reference{Ref: github.String("refs/heads/" + *commitBranch), Object: &github.GitObject{SHA: baseRef.Object.SHA}}
newRef := &github.Reference{Ref: github.Ptr("refs/heads/" + *commitBranch), Object: &github.GitObject{SHA: baseRef.Object.SHA}}
ref, _, err = client.Git.CreateRef(ctx, *sourceOwner, *sourceRepo, newRef)
return ref, err
}
@@ -98,7 +98,7 @@ func getTree(ref *github.Reference) (tree *github.Tree, err error) {
if err != nil {
return nil, err
}
entries = append(entries, &github.TreeEntry{Path: github.String(file), Type: github.String("blob"), Content: github.String(string(content)), Mode: github.String("100644")})
entries = append(entries, &github.TreeEntry{Path: github.Ptr(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)
@@ -190,7 +190,7 @@ func createPR() (err error) {
HeadRepo: repoBranch,
Base: prBranch,
Body: prDescription,
MaintainerCanModify: github.Bool(true),
MaintainerCanModify: github.Ptr(true),
}

pr, _, err := client.PullRequests.Create(ctx, *prRepoOwner, *prRepo, newPR)
2 changes: 1 addition & 1 deletion example/newfilewithappauth/main.go
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ func main() {
"example/foo.txt",
&github.RepositoryContentFileOptions{
Content: []byte("foo"),
Message: github.String("sample commit"),
Message: github.Ptr("sample commit"),
SHA: nil,
})
if err != nil {
66 changes: 33 additions & 33 deletions github/actions_artifacts_test.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
})

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

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

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

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

u := &Artifact{
ID: Int64(1),
NodeID: String("nid"),
Name: String("n"),
SizeInBytes: Int64(1),
URL: String("u"),
ArchiveDownloadURL: String("a"),
Expired: Bool(false),
ID: Ptr(int64(1)),
NodeID: Ptr("nid"),
Name: Ptr("n"),
SizeInBytes: Ptr(int64(1)),
URL: Ptr("u"),
ArchiveDownloadURL: Ptr("a"),
Expired: Ptr(false),
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
ExpiresAt: &Timestamp{referenceTime},
WorkflowRun: &ArtifactWorkflowRun{
ID: Int64(1),
RepositoryID: Int64(1),
HeadRepositoryID: Int64(1),
HeadBranch: String("b"),
HeadSHA: String("s"),
ID: Ptr(int64(1)),
RepositoryID: Ptr(int64(1)),
HeadRepositoryID: Ptr(int64(1)),
HeadBranch: Ptr("b"),
HeadSHA: Ptr("s"),
},
}

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

u := &ArtifactList{
TotalCount: Int64(1),
TotalCount: Ptr(int64(1)),
Artifacts: []*Artifact{
{
ID: Int64(1),
NodeID: String("nid"),
Name: String("n"),
SizeInBytes: Int64(1),
URL: String("u"),
ArchiveDownloadURL: String("a"),
Expired: Bool(false),
ID: Ptr(int64(1)),
NodeID: Ptr("nid"),
Name: Ptr("n"),
SizeInBytes: Ptr(int64(1)),
URL: Ptr("u"),
ArchiveDownloadURL: Ptr("a"),
Expired: Ptr(false),
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
ExpiresAt: &Timestamp{referenceTime},
WorkflowRun: &ArtifactWorkflowRun{
ID: Int64(1),
RepositoryID: Int64(1),
HeadRepositoryID: Int64(1),
HeadBranch: String("b"),
HeadSHA: String("s"),
ID: Ptr(int64(1)),
RepositoryID: Ptr(int64(1)),
HeadRepositoryID: Ptr(int64(1)),
HeadBranch: Ptr("b"),
HeadSHA: Ptr("s"),
},
},
},
38 changes: 19 additions & 19 deletions github/actions_cache_test.go
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ func TestActionsService_ListCaches(t *testing.T) {
t.Errorf("Actions.ListCaches returned error: %v", err)
}

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

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

const methodName = "DeleteCachesByKey"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.DeleteCachesByKey(ctx, "\n", "\n", "\n", String("\n"))
_, err = client.Actions.DeleteCachesByKey(ctx, "\n", "\n", "\n", Ptr("\n"))
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", String("main"))
return client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", Ptr("main"))
})
}

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

ctx := context.Background()
_, err := client.Actions.DeleteCachesByKey(ctx, "%", "r", "1", String("main"))
_, err := client.Actions.DeleteCachesByKey(ctx, "%", "r", "1", Ptr("main"))
testURLParseError(t, err)
}

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

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

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

u := &ActionsCache{
ID: Int64(1),
Ref: String("refAction"),
Key: String("key1"),
Version: String("alpha"),
ID: Ptr(int64(1)),
Ref: Ptr("refAction"),
Key: Ptr("key1"),
Version: Ptr("alpha"),
LastAccessedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
SizeInBytes: Int64(1),
SizeInBytes: Ptr(int64(1)),
}

want := `{
@@ -551,19 +551,19 @@ func TestActionsCacheList_Marshal(t *testing.T) {
TotalCount: 2,
ActionsCaches: []*ActionsCache{
{
ID: Int64(1),
Key: String("key1"),
Version: String("alpha"),
ID: Ptr(int64(1)),
Key: Ptr("key1"),
Version: Ptr("alpha"),
LastAccessedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
SizeInBytes: Int64(1),
SizeInBytes: Ptr(int64(1)),
},
{
ID: Int64(2),
Ref: String("refAction"),
ID: Ptr(int64(2)),
Ref: Ptr("refAction"),
LastAccessedAt: &Timestamp{referenceTime},
CreatedAt: &Timestamp{referenceTime},
SizeInBytes: Int64(1),
SizeInBytes: Ptr(int64(1)),
},
},
}
8 changes: 4 additions & 4 deletions github/actions_oidc_test.go
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ func TestActionsService_GetRepoOIDCSubjectClaimCustomTemplate(t *testing.T) {
t.Errorf("Actions.GetRepoOIDCSubjectClaimCustomTemplate returned error: %v", err)
}

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

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

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

u := &OIDCSubjectClaimCustomTemplate{
UseDefault: Bool(false),
UseDefault: Ptr(false),
IncludeClaimKeys: []string{"s"},
}

Loading
Loading