Skip to content
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

Add Ptr function to use generics for allocating pointers #1788

Merged
merged 4 commits into from
Nov 13, 2023
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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ to list all projects for user "svanharmelen":

```go
git := gitlab.NewClient("yourtokengoeshere")
opt := &gitlab.ListProjectsOptions{Search: gitlab.String("svanharmelen")}
opt := &gitlab.ListProjectsOptions{Search: gitlab.Ptr("svanharmelen")}
projects, _, err := git.Projects.ListProjects(opt)
```

Expand All @@ -159,11 +159,11 @@ func main() {

// Create new project
p := &gitlab.CreateProjectOptions{
Name: gitlab.String("My Project"),
Description: gitlab.String("Just a test project to play with"),
MergeRequestsEnabled: gitlab.Bool(true),
SnippetsEnabled: gitlab.Bool(true),
Visibility: gitlab.Visibility(gitlab.PublicVisibility),
Name: gitlab.Ptr("My Project"),
Description: gitlab.Ptr("Just a test project to play with"),
MergeRequestsEnabled: gitlab.Ptr(true),
SnippetsEnabled: gitlab.Ptr(true),
Visibility: gitlab.Ptr(gitlab.PublicVisibility),
}
project, _, err := git.Projects.CreateProject(p)
if err != nil {
Expand All @@ -172,10 +172,10 @@ func main() {

// Add a new snippet
s := &gitlab.CreateProjectSnippetOptions{
Title: gitlab.String("Dummy Snippet"),
FileName: gitlab.String("snippet.go"),
Content: gitlab.String("package main...."),
Visibility: gitlab.Visibility(gitlab.PublicVisibility),
Title: gitlab.Ptr("Dummy Snippet"),
FileName: gitlab.Ptr("snippet.go"),
Content: gitlab.Ptr("package main...."),
Visibility: gitlab.Ptr(gitlab.PublicVisibility),
}
_, _, err = git.ProjectSnippets.CreateSnippet(project.ID, s)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions access_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestApproveProjectAccessRequest(t *testing.T) {
}

opt := &ApproveAccessRequestOptions{
AccessLevel: AccessLevel(DeveloperPermissions),
AccessLevel: Ptr(DeveloperPermissions),
}

request, resp, err := client.AccessRequests.ApproveProjectAccessRequest(1, 10, opt)
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestApproveGroupAccessRequest(t *testing.T) {
}

opt := &ApproveAccessRequestOptions{
AccessLevel: AccessLevel(DeveloperPermissions),
AccessLevel: Ptr(DeveloperPermissions),
}

request, resp, err := client.AccessRequests.ApproveGroupAccessRequest(1, 10, opt)
Expand Down
2 changes: 1 addition & 1 deletion applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestCreateApplication(t *testing.T) {
)

opt := &CreateApplicationOptions{
Name: String("testApplication"),
Name: Ptr("testApplication"),
}
app, _, err := client.Applications.CreateApplication(opt)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetAvatar(t *testing.T) {
},
)

opt := &GetAvatarOptions{Email: String("sander@vanharmelen.nnl")}
opt := &GetAvatarOptions{Email: Ptr("sander@vanharmelen.nnl")}
avatar, resp, err := client.Avatar.GetAvatar(opt)
if err != nil {
t.Fatalf("Avatar.GetAvatar returned error: %v", err)
Expand Down
24 changes: 12 additions & 12 deletions broadcast_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ func TestCreateBroadcastMessages(t *testing.T) {
})

opt := &CreateBroadcastMessageOptions{
Message: String("Some Message"),
Message: Ptr("Some Message"),
StartsAt: &wantedStartsAt,
EndsAt: &wantedEndsAt,
Color: String("#E75E40"),
Font: String("#FFFFFF"),
Color: Ptr("#E75E40"),
Font: Ptr("#FFFFFF"),
TargetAccessLevels: []AccessLevelValue{GuestPermissions, DeveloperPermissions},
TargetPath: String("*/welcome"),
BroadcastType: String("banner"),
Dismissable: Bool(false),
TargetPath: Ptr("*/welcome"),
BroadcastType: Ptr("banner"),
Dismissable: Ptr(false),
}

got, _, err := client.BroadcastMessage.CreateBroadcastMessage(opt)
Expand Down Expand Up @@ -227,15 +227,15 @@ func TestUpdateBroadcastMessages(t *testing.T) {
})

opt := &UpdateBroadcastMessageOptions{
Message: String("Some Message Updated"),
Message: Ptr("Some Message Updated"),
StartsAt: &wantedStartsAt,
EndsAt: &wantedEndsAt,
Color: String("#E75E40"),
Font: String("#FFFFFF"),
Color: Ptr("#E75E40"),
Font: Ptr("#FFFFFF"),
TargetAccessLevels: []AccessLevelValue{GuestPermissions, DeveloperPermissions},
TargetPath: String("*/welcome"),
BroadcastType: String("banner"),
Dismissable: Bool(false),
TargetPath: Ptr("*/welcome"),
BroadcastType: Ptr("banner"),
Dismissable: Ptr(false),
}

got, _, err := client.BroadcastMessage.UpdateBroadcastMessage(1, opt)
Expand Down
28 changes: 14 additions & 14 deletions cluster_agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func ListClusterAgents(t *testing.T) {
NameWithNamespace: "Administrator / test",
Path: "test",
PathWithNamespace: "root/test",
CreatedAt: Time(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
},
CreatedAt: Time(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedByUserID: 42,
},
{
Expand All @@ -97,9 +97,9 @@ func ListClusterAgents(t *testing.T) {
NameWithNamespace: "Administrator / test",
Path: "test",
PathWithNamespace: "root/test",
CreatedAt: Time(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
},
CreatedAt: Time(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedByUserID: 42,
},
}
Expand Down Expand Up @@ -148,9 +148,9 @@ func GetClusterAgent(t *testing.T) {
NameWithNamespace: "Administrator / test",
Path: "test",
PathWithNamespace: "root/test",
CreatedAt: Time(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
},
CreatedAt: Time(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedByUserID: 42,
}
if !reflect.DeepEqual(want, clusterAgent) {
Expand Down Expand Up @@ -182,7 +182,7 @@ func RegisterClusterAgent(t *testing.T) {
`)
})

opt := &RegisterAgentOptions{Name: String("agent-1")}
opt := &RegisterAgentOptions{Name: Ptr("agent-1")}
clusterAgent, _, err := client.ClusterAgents.RegisterAgent(20, opt)
if err != nil {
t.Errorf("ClusterAgents.RegisterClusterAgent returned error: %v", err)
Expand All @@ -198,9 +198,9 @@ func RegisterClusterAgent(t *testing.T) {
NameWithNamespace: "Administrator / test",
Path: "test",
PathWithNamespace: "root/test",
CreatedAt: Time(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
},
CreatedAt: Time(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.April, 20, 20, 42, 40, 221000000, time.UTC)),
CreatedByUserID: 42,
}
if !reflect.DeepEqual(want, clusterAgent) {
Expand Down Expand Up @@ -250,7 +250,7 @@ func ListAgentTokens(t *testing.T) {
Description: "Some token",
AgentID: 5,
Status: "active",
CreatedAt: Time(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedByUserID: 1,
},
{
Expand All @@ -259,7 +259,7 @@ func ListAgentTokens(t *testing.T) {
Description: "",
AgentID: 5,
Status: "active",
CreatedAt: Time(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedByUserID: 1,
},
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func GetAgentToken(t *testing.T) {
Description: "Some token",
AgentID: 5,
Status: "active",
CreatedAt: Time(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedByUserID: 1,
LastUsedAt: nil,
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func RegisterAgentToken(t *testing.T) {
`)
})

opt := &CreateAgentTokenOptions{Name: String("abcd"), Description: String("Some token")}
opt := &CreateAgentTokenOptions{Name: Ptr("abcd"), Description: Ptr("Some token")}
clusterAgentToken, _, err := client.ClusterAgents.CreateAgentToken(20, 5, opt)
if err != nil {
t.Errorf("ClusterAgents.CreateAgentToken returned error: %v", err)
Expand All @@ -340,7 +340,7 @@ func RegisterAgentToken(t *testing.T) {
Description: "Some token",
AgentID: 5,
Status: "active",
CreatedAt: Time(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedAt: Ptr(time.Date(2022, time.March, 25, 14, 12, 11, 497000000, time.UTC)),
CreatedByUserID: 1,
LastUsedAt: nil,
Token: "qeY8UVRisx9y3Loxo1scLxFuRxYcgeX3sxsdrpP_fR3Loq4xyg",
Expand Down
30 changes: 15 additions & 15 deletions commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestGetCommit(t *testing.T) {
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
Status: Ptr(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
Expand All @@ -83,10 +83,10 @@ func TestGetCommitStatuses(t *testing.T) {
})

opt := &GetCommitStatusesOptions{
Ref: String("master"),
Stage: String("test"),
Name: String("ci/jenkins"),
All: Bool(true),
Ref: Ptr("master"),
Stage: Ptr("test"),
Name: Ptr("ci/jenkins"),
All: Ptr(true),
}
statuses, _, err := client.Commits.GetCommitStatuses("1", "b0b3a907f41409829b307a28b82fdbd552ee5a27", opt)
if err != nil {
Expand Down Expand Up @@ -119,11 +119,11 @@ func TestSetCommitStatus(t *testing.T) {
cov := 99.9
opt := &SetCommitStatusOptions{
State: Running,
Ref: String("master"),
Name: String("ci/jenkins"),
Context: String(""),
TargetURL: String("http://abc"),
Description: String("build"),
Ref: Ptr("master"),
Name: Ptr("ci/jenkins"),
Context: Ptr(""),
TargetURL: Ptr("http://abc"),
Description: Ptr("build"),
Coverage: &cov,
}
status, _, err := client.Commits.SetCommitStatus("1", "b0b3a907f41409829b307a28b82fdbd552ee5a27", opt)
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestRevertCommit_NoOptions(t *testing.T) {
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
Status: Ptr(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestRevertCommit_WithOptions(t *testing.T) {
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
Status: Ptr(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestCommitsService_ListCommits(t *testing.T) {
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
Status: Ptr(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestCommitsService_CreateCommit(t *testing.T) {
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
Status: Ptr(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
Expand Down Expand Up @@ -896,7 +896,7 @@ func TestCommitsService_CherryPickCommit(t *testing.T) {
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
Status: Ptr(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
Expand Down
16 changes: 8 additions & 8 deletions deploy_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func TestAddDeployKey(t *testing.T) {
})

opt := &AddDeployKeyOptions{
Key: String("ssh-rsa AAAA..."),
Title: String("My deploy key"),
CanPush: Bool(true),
Key: Ptr("ssh-rsa AAAA..."),
Title: Ptr("My deploy key"),
CanPush: Ptr(true),
}
deployKey, _, err := client.DeployKeys.AddDeployKey(5, opt)
if err != nil {
Expand All @@ -245,9 +245,9 @@ func TestAddDeployKey(t *testing.T) {
}

want := &ProjectDeployKey{
Title: *String("My deploy key"),
Title: "My deploy key",
ID: 12,
Key: *String("ssh-rsa AAAA..."),
Key: "ssh-rsa AAAA...",
CreatedAt: &createdAt,
CanPush: true,
}
Expand Down Expand Up @@ -318,8 +318,8 @@ func TestUpdateDeployKey(t *testing.T) {
})

opt := &UpdateDeployKeyOptions{
Title: String("New deploy key"),
CanPush: Bool(true),
Title: Ptr("New deploy key"),
CanPush: Ptr(true),
}
deployKey, _, err := client.DeployKeys.UpdateDeployKey(5, 11, opt)
if err != nil {
Expand All @@ -333,7 +333,7 @@ func TestUpdateDeployKey(t *testing.T) {

want := &ProjectDeployKey{
ID: 11,
Title: *String("New deploy key"),
Title: "New deploy key",
Key: "ssh-rsa AAAA...",
CreatedAt: &createdAt,
CanPush: true,
Expand Down
8 changes: 4 additions & 4 deletions deploy_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ func TestCreateProjectDeployToken(t *testing.T) {
expiresAt := time.Date(2021, 0o1, 0o1, 0, 0, 0, 0, time.UTC)

deployToken, _, err := client.DeployTokens.CreateProjectDeployToken(5, &CreateProjectDeployTokenOptions{
Name: String("My deploy token"),
Username: String("custom-user"),
Name: Ptr("My deploy token"),
Username: Ptr("custom-user"),
ExpiresAt: &expiresAt,
Scopes: &[]string{
"read_repository",
Expand Down Expand Up @@ -342,8 +342,8 @@ func TestCreateGroupDeployToken(t *testing.T) {
expiresAt := time.Date(2021, 0o1, 0o1, 0, 0, 0, 0, time.UTC)

deployToken, _, err := client.DeployTokens.CreateGroupDeployToken(5, &CreateGroupDeployTokenOptions{
Name: String("My deploy token"),
Username: String("custom-user"),
Name: Ptr("My deploy token"),
Username: Ptr("custom-user"),
ExpiresAt: &expiresAt,
Scopes: &[]string{
"read_repository",
Expand Down
4 changes: 2 additions & 2 deletions deployments_merge_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestDeploymentMergeRequestsService_ListDeploymentMergeRequests(t *testing.T

opts := ListMergeRequestsOptions{
AssigneeID: AssigneeID(UserIDAny),
WithLabelsDetails: Bool(true),
WithMergeStatusRecheck: Bool(true),
WithLabelsDetails: Ptr(true),
WithMergeStatusRecheck: Ptr(true),
}

mergeRequests, _, err := client.DeploymentMergeRequests.ListDeploymentMergeRequests(278964, 2, &opts)
Expand Down
Loading
Loading