+
Skip to content

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

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
6 changes: 3 additions & 3 deletions example/actionpermissions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

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")}

Check warning on line 47 in example/actionpermissions/main.go

View check run for this annotation

Codecov / codecov/patch

example/actionpermissions/main.go#L47

Added line #L47 was not covered by tests
_, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
if err != nil {
log.Fatal(err)
Expand All @@ -59,15 +59,15 @@

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"}}

Check warning on line 62 in example/actionpermissions/main.go

View check run for this annotation

Codecov / codecov/patch

example/actionpermissions/main.go#L62

Added line #L62 was not covered by tests
_, _, 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")}

Check warning on line 70 in example/actionpermissions/main.go

View check run for this annotation

Codecov / codecov/patch

example/actionpermissions/main.go#L70

Added line #L70 was not covered by tests
_, _, err = client.Repositories.EditActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
if err != nil {
log.Fatal(err)
Expand Down
6 changes: 3 additions & 3 deletions example/commitpr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
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}}

Check warning on line 84 in example/commitpr/main.go

View check run for this annotation

Codecov / codecov/patch

example/commitpr/main.go#L84

Added line #L84 was not covered by tests
ref, _, err = client.Git.CreateRef(ctx, *sourceOwner, *sourceRepo, newRef)
return ref, err
}
Expand All @@ -98,7 +98,7 @@
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")})

Check warning on line 101 in example/commitpr/main.go

View check run for this annotation

Codecov / codecov/patch

example/commitpr/main.go#L101

Added line #L101 was not covered by tests
}

tree, _, err = client.Git.CreateTree(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA, entries)
Expand Down Expand Up @@ -190,7 +190,7 @@
HeadRepo: repoBranch,
Base: prBranch,
Body: prDescription,
MaintainerCanModify: github.Bool(true),
MaintainerCanModify: github.Ptr(true),

Check warning on line 193 in example/commitpr/main.go

View check run for this annotation

Codecov / codecov/patch

example/commitpr/main.go#L193

Added line #L193 was not covered by tests
}

pr, _, err := client.PullRequests.Create(ctx, *prRepoOwner, *prRepo, newPR)
Expand Down
2 changes: 1 addition & 1 deletion example/newfilewithappauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"example/foo.txt",
&github.RepositoryContentFileOptions{
Content: []byte("foo"),
Message: github.String("sample commit"),
Message: github.Ptr("sample commit"),

Check warning on line 82 in example/newfilewithappauth/main.go

View check run for this annotation

Codecov / codecov/patch

example/newfilewithappauth/main.go#L82

Added line #L82 was not covered by tests
SHA: nil,
})
if err != nil {
Expand Down
66 changes: 33 additions & 33 deletions github/actions_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
},
}

Expand Down Expand Up @@ -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"),
},
},
},
Expand Down
38 changes: 19 additions & 19 deletions github/actions_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"))
})
}

Expand All @@ -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)
}

Expand All @@ -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) {
Expand All @@ -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")
}
Expand Down Expand Up @@ -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 := `{
Expand All @@ -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)),
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions github/actions_oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -185,7 +185,7 @@ func TestOIDCSubjectClaimCustomTemplate_Marshal(t *testing.T) {
testJSONMarshal(t, &OIDCSubjectClaimCustomTemplate{}, "{}")

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

Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载