Skip to content
Open
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
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ See [#3644][] and [#3887][] for background discussion.
#### Creating Pointers

Pointer fields are common because many request and response fields are
optional. Use the generic `Ptr` helper to take the address of a literal
optional. Use the `new` builtin to take the address of a literal
instead of declaring an intermediate variable:

```go
repo := &Repository{
Name: Ptr("go-github"),
Private: Ptr(true),
ID: Ptr(int64(1)),
Name: new("go-github"),
Private: new(true),
ID: new(int64(1)),
}
```

Expand Down Expand Up @@ -548,7 +548,7 @@ func TestRepositoriesService_GetByID(t *testing.T) {
t.Fatalf("Repositories.GetByID returned error: %v", err)
}

want := &Repository{ID: Ptr(int64(1)), Name: Ptr("n")}
want := &Repository{ID: new(int64(1)), Name: new("n")}
if !cmp.Equal(got, want) {
t.Errorf("Repositories.GetByID returned %+v, want %+v", got, want)
}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ go-github tracks [Go's version support policy][support-policy] supporting any
minor version of the latest two major releases of Go and the go directive in
go.mod reflects that.
We do our best not to break older versions of Go if we don't have to, but we
don't explicitly test older versions and as of Go 1.23 the go directive in
don't explicitly test older versions and as of Go 1.26 the go directive in
go.mod declares a hard required _minimum_ version of Go to use with this module
and this _must_ be greater than or equal to the go line of all dependencies so
go-github will require the N-1 major release of Go by default.
Expand Down Expand Up @@ -332,14 +332,14 @@ recommended when making requests using short-lived credentials such as a

All structs for GitHub resources use pointer values for all non-repeated fields.
This allows distinguishing between unset fields and those set to a zero-value.
Helper functions have been provided to easily create these pointers for string,
Use the `new` builtin to easily create these pointers for string,
bool, and int values. For example:

```go
// create a new private repository named "foo"
repo := &github.Repository{
Name: github.Ptr("foo"),
Private: github.Ptr(true),
Name: new("foo"),
Private: new(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 @@ -47,7 +47,7 @@ func main() {

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

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

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

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

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

actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("all")}
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: new(true), AllowedActions: new("all")}
_, _, err = client.Repositories.UpdateActionsPermissions(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 @@ -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: &file, Type: github.Ptr("blob"), Content: github.Ptr(string(content)), Mode: github.Ptr("100644")})
entries = append(entries, &github.TreeEntry{Path: &file, Type: new("blob"), Content: new(string(content)), Mode: new("100644")})
}

tree, _, err = client.Git.CreateTree(ctx, *sourceOwner, *sourceRepo, *ref.Object.SHA, entries)
Expand Down Expand Up @@ -173,7 +173,7 @@ func pushCommit(ref *github.Reference, tree *github.Tree) (err error) {
ref.Object.SHA = newCommit.SHA
_, _, err = client.Git.UpdateRef(ctx, *sourceOwner, *sourceRepo, *ref.Ref, github.UpdateRef{
SHA: *newCommit.SHA,
Force: github.Ptr(false),
Force: new(false),
})
return err
}
Expand All @@ -200,7 +200,7 @@ func createPR() (err error) {
HeadRepo: repoBranch,
Base: *prBranch,
Body: prDescription,
MaintainerCanModify: github.Ptr(true),
MaintainerCanModify: new(true),
}

pr, _, err := client.PullRequests.Create(ctx, *prRepoOwner, *prRepo, newPR)
Expand Down
2 changes: 1 addition & 1 deletion example/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/google/go-github/v90/example

go 1.25.8
go 1.26.0

require (
github.com/ProtonMail/go-crypto v1.4.1
Expand Down
2 changes: 1 addition & 1 deletion example/newfilewithappauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
"example/foo.txt",
&github.RepositoryContentFileOptions{
Content: []byte("foo"),
Message: github.Ptr("sample commit"),
Message: new("sample commit"),
SHA: nil,
},
)
Expand Down
16 changes: 8 additions & 8 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: Ptr("TheArtifact"),
Name: new("TheArtifact"),
ListOptions: ListOptions{Page: 2},
}
ctx := t.Context()
Expand All @@ -41,7 +41,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
t.Errorf("Actions.ListArtifacts returned error: %v", err)
}

want := &ArtifactList{TotalCount: Ptr(int64(1)), Artifacts: []*Artifact{{ID: Ptr(int64(1))}}}
want := &ArtifactList{TotalCount: new(int64(1)), Artifacts: []*Artifact{{ID: new(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: Ptr(int64(1)), Artifacts: []*Artifact{{ID: Ptr(int64(1))}}}
want := &ArtifactList{TotalCount: new(int64(1)), Artifacts: []*Artifact{{ID: new(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: Ptr(int64(1)),
NodeID: Ptr("xyz"),
Name: Ptr("a"),
SizeInBytes: Ptr(int64(5)),
ArchiveDownloadURL: Ptr("u"),
ID: new(int64(1)),
NodeID: new("xyz"),
Name: new("a"),
SizeInBytes: new(int64(5)),
ArchiveDownloadURL: new("u"),
}
if !cmp.Equal(artifact, want) {
t.Errorf("Actions.GetArtifact returned %+v, want %+v", artifact, want)
Expand Down
14 changes: 7 additions & 7 deletions github/actions_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestActionsService_ListCaches(t *testing.T) {
t.Errorf("Actions.ListCaches returned error: %v", err)
}

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

ctx := t.Context()
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", Ptr("main"))
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", new("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", Ptr("\n"))
_, err = client.Actions.DeleteCachesByKey(ctx, "\n", "\n", "\n", new("\n"))
return err
})

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

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

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

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

ctx := t.Context()
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "%", "1", Ptr("main"))
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "%", "1", new("main"))
testURLParseError(t, err)
}

Expand All @@ -149,7 +149,7 @@ func TestActionsService_DeleteCachesByKey_notFound(t *testing.T) {
})

ctx := t.Context()
resp, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", Ptr("main"))
resp, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", new("main"))
if err == nil {
t.Error("Expected HTTP 404 response")
}
Expand Down
Loading
Loading