From 08bd52a1b1a0f300199afb4f58b0194844736821 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 27 Nov 2024 07:53:35 +0100 Subject: [PATCH] Add pagination options to all supported endpoints in sdk (#4463) --- cli/admin/registry/registry_list.go | 5 +- cli/cron/cron_list.go | 4 +- cli/org/registry/registry_list.go | 5 +- cli/repo/registry/registry_list.go | 5 +- cli/secret/secret_list.go | 8 +- cli/user/user_list.go | 5 +- pipeline/rpc/proto/woodpecker.pb.go | 470 ++++---------------- pipeline/rpc/proto/woodpecker_grpc.pb.go | 46 +- woodpecker-go/woodpecker/global_registry.go | 12 +- woodpecker-go/woodpecker/global_secret.go | 12 +- woodpecker-go/woodpecker/interface.go | 16 +- woodpecker-go/woodpecker/mocks/client.go | 144 +++--- woodpecker-go/woodpecker/org.go | 19 +- woodpecker-go/woodpecker/repo.go | 34 +- woodpecker-go/woodpecker/user.go | 11 +- woodpecker-go/woodpecker/user_test.go | 2 +- 16 files changed, 286 insertions(+), 512 deletions(-) diff --git a/cli/admin/registry/registry_list.go b/cli/admin/registry/registry_list.go index 6f5788967..72332b9a0 100644 --- a/cli/admin/registry/registry_list.go +++ b/cli/admin/registry/registry_list.go @@ -23,6 +23,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) var registryListCmd = &cli.Command{ @@ -42,7 +43,9 @@ func registryList(ctx context.Context, c *cli.Command) error { return err } - list, err := client.GlobalRegistryList() + opt := woodpecker.RegistryListOptions{} + + list, err := client.GlobalRegistryList(opt) if err != nil { return err } diff --git a/cli/cron/cron_list.go b/cli/cron/cron_list.go index b51a7aaee..6925b784d 100644 --- a/cli/cron/cron_list.go +++ b/cli/cron/cron_list.go @@ -23,6 +23,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) var cronListCmd = &cli.Command{ @@ -52,7 +53,8 @@ func cronList(ctx context.Context, c *cli.Command) error { if err != nil { return err } - list, err := client.CronList(repoID) + opt := woodpecker.CronListOptions{} + list, err := client.CronList(repoID, opt) if err != nil { return err } diff --git a/cli/org/registry/registry_list.go b/cli/org/registry/registry_list.go index 1829d0401..a905d2128 100644 --- a/cli/org/registry/registry_list.go +++ b/cli/org/registry/registry_list.go @@ -23,6 +23,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) var registryListCmd = &cli.Command{ @@ -49,7 +50,9 @@ func registryList(ctx context.Context, c *cli.Command) error { return err } - list, err := client.OrgRegistryList(orgID) + opt := woodpecker.RegistryListOptions{} + + list, err := client.OrgRegistryList(orgID, opt) if err != nil { return err } diff --git a/cli/repo/registry/registry_list.go b/cli/repo/registry/registry_list.go index 0cb6f80b8..d76bcc18b 100644 --- a/cli/repo/registry/registry_list.go +++ b/cli/repo/registry/registry_list.go @@ -23,6 +23,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) var registryListCmd = &cli.Command{ @@ -49,7 +50,9 @@ func registryList(ctx context.Context, c *cli.Command) error { return err } - list, err := client.RegistryList(repoID) + opt := woodpecker.RegistryListOptions{} + + list, err := client.RegistryList(repoID, opt) if err != nil { return err } diff --git a/cli/secret/secret_list.go b/cli/secret/secret_list.go index 4645089bc..7c971631d 100644 --- a/cli/secret/secret_list.go +++ b/cli/secret/secret_list.go @@ -56,20 +56,22 @@ func secretList(ctx context.Context, c *cli.Command) error { return err } + opt := woodpecker.SecretListOptions{} + var list []*woodpecker.Secret switch { case global: - list, err = client.GlobalSecretList() + list, err = client.GlobalSecretList(opt) if err != nil { return err } case orgID != -1: - list, err = client.OrgSecretList(orgID) + list, err = client.OrgSecretList(orgID, opt) if err != nil { return err } default: - list, err = client.SecretList(repoID) + list, err = client.SecretList(repoID, opt) if err != nil { return err } diff --git a/cli/user/user_list.go b/cli/user/user_list.go index 4e721f0f4..894ec02df 100644 --- a/cli/user/user_list.go +++ b/cli/user/user_list.go @@ -23,6 +23,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/cli/internal" + "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" ) var userListCmd = &cli.Command{ @@ -39,7 +40,9 @@ func userList(ctx context.Context, c *cli.Command) error { return err } - users, err := client.UserList() + opt := woodpecker.UserListOptions{} + + users, err := client.UserList(opt) if err != nil || len(users) == 0 { return err } diff --git a/pipeline/rpc/proto/woodpecker.pb.go b/pipeline/rpc/proto/woodpecker.pb.go index d7fca2aa8..8f5f059c4 100644 --- a/pipeline/rpc/proto/woodpecker.pb.go +++ b/pipeline/rpc/proto/woodpecker.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v4.25.4 +// protoc-gen-go v1.35.2 +// protoc v4.24.4 // source: woodpecker.proto package proto @@ -50,11 +50,9 @@ type StepState struct { func (x *StepState) Reset() { *x = StepState{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *StepState) String() string { @@ -65,7 +63,7 @@ func (*StepState) ProtoMessage() {} func (x *StepState) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -134,11 +132,9 @@ type WorkflowState struct { func (x *WorkflowState) Reset() { *x = WorkflowState{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *WorkflowState) String() string { @@ -149,7 +145,7 @@ func (*WorkflowState) ProtoMessage() {} func (x *WorkflowState) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -199,11 +195,9 @@ type LogEntry struct { func (x *LogEntry) Reset() { *x = LogEntry{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *LogEntry) String() string { @@ -214,7 +208,7 @@ func (*LogEntry) ProtoMessage() {} func (x *LogEntry) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -274,11 +268,9 @@ type Filter struct { func (x *Filter) Reset() { *x = Filter{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *Filter) String() string { @@ -289,7 +281,7 @@ func (*Filter) ProtoMessage() {} func (x *Filter) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -323,11 +315,9 @@ type Workflow struct { func (x *Workflow) Reset() { *x = Workflow{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *Workflow) String() string { @@ -338,7 +328,7 @@ func (*Workflow) ProtoMessage() {} func (x *Workflow) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -384,11 +374,9 @@ type NextRequest struct { func (x *NextRequest) Reset() { *x = NextRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *NextRequest) String() string { @@ -399,7 +387,7 @@ func (*NextRequest) ProtoMessage() {} func (x *NextRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -432,11 +420,9 @@ type InitRequest struct { func (x *InitRequest) Reset() { *x = InitRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *InitRequest) String() string { @@ -447,7 +433,7 @@ func (*InitRequest) ProtoMessage() {} func (x *InitRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -486,11 +472,9 @@ type WaitRequest struct { func (x *WaitRequest) Reset() { *x = WaitRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *WaitRequest) String() string { @@ -501,7 +485,7 @@ func (*WaitRequest) ProtoMessage() {} func (x *WaitRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -534,11 +518,9 @@ type DoneRequest struct { func (x *DoneRequest) Reset() { *x = DoneRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *DoneRequest) String() string { @@ -549,7 +531,7 @@ func (*DoneRequest) ProtoMessage() {} func (x *DoneRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -588,11 +570,9 @@ type ExtendRequest struct { func (x *ExtendRequest) Reset() { *x = ExtendRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *ExtendRequest) String() string { @@ -603,7 +583,7 @@ func (*ExtendRequest) ProtoMessage() {} func (x *ExtendRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[9] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -636,11 +616,9 @@ type UpdateRequest struct { func (x *UpdateRequest) Reset() { *x = UpdateRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[10] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *UpdateRequest) String() string { @@ -651,7 +629,7 @@ func (*UpdateRequest) ProtoMessage() {} func (x *UpdateRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[10] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -690,11 +668,9 @@ type LogRequest struct { func (x *LogRequest) Reset() { *x = LogRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[11] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *LogRequest) String() string { @@ -705,7 +681,7 @@ func (*LogRequest) ProtoMessage() {} func (x *LogRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[11] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -735,11 +711,9 @@ type Empty struct { func (x *Empty) Reset() { *x = Empty{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[12] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *Empty) String() string { @@ -750,7 +724,7 @@ func (*Empty) ProtoMessage() {} func (x *Empty) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[12] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -775,11 +749,9 @@ type ReportHealthRequest struct { func (x *ReportHealthRequest) Reset() { *x = ReportHealthRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[13] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *ReportHealthRequest) String() string { @@ -790,7 +762,7 @@ func (*ReportHealthRequest) ProtoMessage() {} func (x *ReportHealthRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[13] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -826,11 +798,9 @@ type AgentInfo struct { func (x *AgentInfo) Reset() { *x = AgentInfo{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[14] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *AgentInfo) String() string { @@ -841,7 +811,7 @@ func (*AgentInfo) ProtoMessage() {} func (x *AgentInfo) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[14] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -901,11 +871,9 @@ type RegisterAgentRequest struct { func (x *RegisterAgentRequest) Reset() { *x = RegisterAgentRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[15] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *RegisterAgentRequest) String() string { @@ -916,7 +884,7 @@ func (*RegisterAgentRequest) ProtoMessage() {} func (x *RegisterAgentRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[15] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -949,11 +917,9 @@ type VersionResponse struct { func (x *VersionResponse) Reset() { *x = VersionResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[16] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *VersionResponse) String() string { @@ -964,7 +930,7 @@ func (*VersionResponse) ProtoMessage() {} func (x *VersionResponse) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[16] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -1003,11 +969,9 @@ type NextResponse struct { func (x *NextResponse) Reset() { *x = NextResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[17] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *NextResponse) String() string { @@ -1018,7 +982,7 @@ func (*NextResponse) ProtoMessage() {} func (x *NextResponse) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[17] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -1050,11 +1014,9 @@ type RegisterAgentResponse struct { func (x *RegisterAgentResponse) Reset() { *x = RegisterAgentResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[18] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *RegisterAgentResponse) String() string { @@ -1065,7 +1027,7 @@ func (*RegisterAgentResponse) ProtoMessage() {} func (x *RegisterAgentResponse) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[18] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -1098,11 +1060,9 @@ type AuthRequest struct { func (x *AuthRequest) Reset() { *x = AuthRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[19] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *AuthRequest) String() string { @@ -1113,7 +1073,7 @@ func (*AuthRequest) ProtoMessage() {} func (x *AuthRequest) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[19] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -1154,11 +1114,9 @@ type AuthResponse struct { func (x *AuthResponse) Reset() { *x = AuthResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_woodpecker_proto_msgTypes[20] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_woodpecker_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *AuthResponse) String() string { @@ -1169,7 +1127,7 @@ func (*AuthResponse) ProtoMessage() {} func (x *AuthResponse) ProtoReflect() protoreflect.Message { mi := &file_woodpecker_proto_msgTypes[20] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -1379,7 +1337,7 @@ func file_woodpecker_proto_rawDescGZIP() []byte { } var file_woodpecker_proto_msgTypes = make([]protoimpl.MessageInfo, 23) -var file_woodpecker_proto_goTypes = []interface{}{ +var file_woodpecker_proto_goTypes = []any{ (*StepState)(nil), // 0: proto.StepState (*WorkflowState)(nil), // 1: proto.WorkflowState (*LogEntry)(nil), // 2: proto.LogEntry @@ -1450,260 +1408,6 @@ func file_woodpecker_proto_init() { if File_woodpecker_proto != nil { return } - if !protoimpl.UnsafeEnabled { - file_woodpecker_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*StepState); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*WorkflowState); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LogEntry); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Filter); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Workflow); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*NextRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*InitRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*WaitRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoneRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExtendRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UpdateRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LogRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Empty); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReportHealthRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AgentInfo); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RegisterAgentRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VersionResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*NextResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RegisterAgentResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AuthRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_woodpecker_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AuthResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/pipeline/rpc/proto/woodpecker_grpc.pb.go b/pipeline/rpc/proto/woodpecker_grpc.pb.go index 64437aeb1..63ab920b6 100644 --- a/pipeline/rpc/proto/woodpecker_grpc.pb.go +++ b/pipeline/rpc/proto/woodpecker_grpc.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v4.25.4 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v4.24.4 // source: woodpecker.proto package proto @@ -30,8 +30,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Woodpecker_Version_FullMethodName = "/proto.Woodpecker/Version" @@ -186,7 +186,7 @@ func (c *woodpeckerClient) ReportHealth(ctx context.Context, in *ReportHealthReq // WoodpeckerServer is the server API for Woodpecker service. // All implementations must embed UnimplementedWoodpeckerServer -// for forward compatibility +// for forward compatibility. // // Woodpecker Server Service type WoodpeckerServer interface { @@ -204,9 +204,12 @@ type WoodpeckerServer interface { mustEmbedUnimplementedWoodpeckerServer() } -// UnimplementedWoodpeckerServer must be embedded to have forward compatible implementations. -type UnimplementedWoodpeckerServer struct { -} +// UnimplementedWoodpeckerServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedWoodpeckerServer struct{} func (UnimplementedWoodpeckerServer) Version(context.Context, *Empty) (*VersionResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Version not implemented") @@ -242,6 +245,7 @@ func (UnimplementedWoodpeckerServer) ReportHealth(context.Context, *ReportHealth return nil, status.Errorf(codes.Unimplemented, "method ReportHealth not implemented") } func (UnimplementedWoodpeckerServer) mustEmbedUnimplementedWoodpeckerServer() {} +func (UnimplementedWoodpeckerServer) testEmbeddedByValue() {} // UnsafeWoodpeckerServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to WoodpeckerServer will @@ -251,6 +255,13 @@ type UnsafeWoodpeckerServer interface { } func RegisterWoodpeckerServer(s grpc.ServiceRegistrar, srv WoodpeckerServer) { + // If the following call pancis, it indicates UnimplementedWoodpeckerServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Woodpecker_ServiceDesc, srv) } @@ -539,20 +550,24 @@ func (c *woodpeckerAuthClient) Auth(ctx context.Context, in *AuthRequest, opts . // WoodpeckerAuthServer is the server API for WoodpeckerAuth service. // All implementations must embed UnimplementedWoodpeckerAuthServer -// for forward compatibility +// for forward compatibility. type WoodpeckerAuthServer interface { Auth(context.Context, *AuthRequest) (*AuthResponse, error) mustEmbedUnimplementedWoodpeckerAuthServer() } -// UnimplementedWoodpeckerAuthServer must be embedded to have forward compatible implementations. -type UnimplementedWoodpeckerAuthServer struct { -} +// UnimplementedWoodpeckerAuthServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedWoodpeckerAuthServer struct{} func (UnimplementedWoodpeckerAuthServer) Auth(context.Context, *AuthRequest) (*AuthResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Auth not implemented") } func (UnimplementedWoodpeckerAuthServer) mustEmbedUnimplementedWoodpeckerAuthServer() {} +func (UnimplementedWoodpeckerAuthServer) testEmbeddedByValue() {} // UnsafeWoodpeckerAuthServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to WoodpeckerAuthServer will @@ -562,6 +577,13 @@ type UnsafeWoodpeckerAuthServer interface { } func RegisterWoodpeckerAuthServer(s grpc.ServiceRegistrar, srv WoodpeckerAuthServer) { + // If the following call pancis, it indicates UnimplementedWoodpeckerAuthServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&WoodpeckerAuth_ServiceDesc, srv) } diff --git a/woodpecker-go/woodpecker/global_registry.go b/woodpecker-go/woodpecker/global_registry.go index 3818b902d..1936b7b47 100644 --- a/woodpecker-go/woodpecker/global_registry.go +++ b/woodpecker-go/woodpecker/global_registry.go @@ -1,6 +1,9 @@ package woodpecker -import "fmt" +import ( + "fmt" + "net/url" +) const ( pathGlobalRegistries = "%s/api/registries" @@ -16,10 +19,11 @@ func (c *client) GlobalRegistry(registry string) (*Registry, error) { } // GlobalRegistryList returns a list of all global registries. -func (c *client) GlobalRegistryList() ([]*Registry, error) { +func (c *client) GlobalRegistryList(opt RegistryListOptions) ([]*Registry, error) { var out []*Registry - uri := fmt.Sprintf(pathGlobalRegistries, c.addr) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathGlobalRegistries, c.addr)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } diff --git a/woodpecker-go/woodpecker/global_secret.go b/woodpecker-go/woodpecker/global_secret.go index 1e9a07031..1be6053fa 100644 --- a/woodpecker-go/woodpecker/global_secret.go +++ b/woodpecker-go/woodpecker/global_secret.go @@ -1,6 +1,9 @@ package woodpecker -import "fmt" +import ( + "fmt" + "net/url" +) const ( pathGlobalSecrets = "%s/api/secrets" @@ -16,10 +19,11 @@ func (c *client) GlobalSecret(secret string) (*Secret, error) { } // GlobalSecretList returns a list of all global secrets. -func (c *client) GlobalSecretList() ([]*Secret, error) { +func (c *client) GlobalSecretList(opt SecretListOptions) ([]*Secret, error) { var out []*Secret - uri := fmt.Sprintf(pathGlobalSecrets, c.addr) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathGlobalSecrets, c.addr)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } diff --git a/woodpecker-go/woodpecker/interface.go b/woodpecker-go/woodpecker/interface.go index 0ffed90ba..611318e31 100644 --- a/woodpecker-go/woodpecker/interface.go +++ b/woodpecker-go/woodpecker/interface.go @@ -35,7 +35,7 @@ type Client interface { User(string) (*User, error) // UserList returns a list of all registered users. - UserList() ([]*User, error) + UserList(opt UserListOptions) ([]*User, error) // UserPost creates a new user account. UserPost(*User) (*User, error) @@ -125,7 +125,7 @@ type Client interface { Registry(repoID int64, hostname string) (*Registry, error) // RegistryList returns a list of all repository registries. - RegistryList(repoID int64) ([]*Registry, error) + RegistryList(repoID int64, opt RegistryListOptions) ([]*Registry, error) // RegistryCreate creates a registry. RegistryCreate(repoID int64, registry *Registry) (*Registry, error) @@ -140,7 +140,7 @@ type Client interface { OrgRegistry(orgID int64, registry string) (*Registry, error) // OrgRegistryList returns a list of all organization registries. - OrgRegistryList(orgID int64) ([]*Registry, error) + OrgRegistryList(orgID int64, opt RegistryListOptions) ([]*Registry, error) // OrgRegistryCreate creates an organization registry. OrgRegistryCreate(orgID int64, registry *Registry) (*Registry, error) @@ -155,7 +155,7 @@ type Client interface { GlobalRegistry(registry string) (*Registry, error) // GlobalRegistryList returns a list of all global registries. - GlobalRegistryList() ([]*Registry, error) + GlobalRegistryList(opt RegistryListOptions) ([]*Registry, error) // GlobalRegistryCreate creates a global registry. GlobalRegistryCreate(registry *Registry) (*Registry, error) @@ -170,7 +170,7 @@ type Client interface { Secret(repoID int64, secret string) (*Secret, error) // SecretList returns a list of all repository secrets. - SecretList(repoID int64) ([]*Secret, error) + SecretList(repoID int64, opt SecretListOptions) ([]*Secret, error) // SecretCreate creates a secret. SecretCreate(repoID int64, secret *Secret) (*Secret, error) @@ -191,7 +191,7 @@ type Client interface { OrgSecret(orgID int64, secret string) (*Secret, error) // OrgSecretList returns a list of all organization secrets. - OrgSecretList(orgID int64) ([]*Secret, error) + OrgSecretList(orgID int64, opt SecretListOptions) ([]*Secret, error) // OrgSecretCreate creates an organization secret. OrgSecretCreate(orgID int64, secret *Secret) (*Secret, error) @@ -206,7 +206,7 @@ type Client interface { GlobalSecret(secret string) (*Secret, error) // GlobalSecretList returns a list of all global secrets. - GlobalSecretList() ([]*Secret, error) + GlobalSecretList(opt SecretListOptions) ([]*Secret, error) // GlobalSecretCreate creates a global secret. GlobalSecretCreate(secret *Secret) (*Secret, error) @@ -227,7 +227,7 @@ type Client interface { SetLogLevel(logLevel *LogLevel) (*LogLevel, error) // CronList list all cron jobs of a repo. - CronList(repoID int64) ([]*Cron, error) + CronList(repoID int64, opt CronListOptions) ([]*Cron, error) // CronGet get a specific cron job of a repo by id. CronGet(repoID, cronID int64) (*Cron, error) diff --git a/woodpecker-go/woodpecker/mocks/client.go b/woodpecker-go/woodpecker/mocks/client.go index 3850520b1..0ce17b6e0 100644 --- a/woodpecker-go/woodpecker/mocks/client.go +++ b/woodpecker-go/woodpecker/mocks/client.go @@ -263,9 +263,9 @@ func (_m *Client) CronGet(repoID int64, cronID int64) (*woodpecker.Cron, error) return r0, r1 } -// CronList provides a mock function with given fields: repoID -func (_m *Client) CronList(repoID int64) ([]*woodpecker.Cron, error) { - ret := _m.Called(repoID) +// CronList provides a mock function with given fields: repoID, opt +func (_m *Client) CronList(repoID int64, opt woodpecker.CronListOptions) ([]*woodpecker.Cron, error) { + ret := _m.Called(repoID, opt) if len(ret) == 0 { panic("no return value specified for CronList") @@ -273,19 +273,19 @@ func (_m *Client) CronList(repoID int64) ([]*woodpecker.Cron, error) { var r0 []*woodpecker.Cron var r1 error - if rf, ok := ret.Get(0).(func(int64) ([]*woodpecker.Cron, error)); ok { - return rf(repoID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.CronListOptions) ([]*woodpecker.Cron, error)); ok { + return rf(repoID, opt) } - if rf, ok := ret.Get(0).(func(int64) []*woodpecker.Cron); ok { - r0 = rf(repoID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.CronListOptions) []*woodpecker.Cron); ok { + r0 = rf(repoID, opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Cron) } } - if rf, ok := ret.Get(1).(func(int64) error); ok { - r1 = rf(repoID) + if rf, ok := ret.Get(1).(func(int64, woodpecker.CronListOptions) error); ok { + r1 = rf(repoID, opt) } else { r1 = ret.Error(1) } @@ -431,9 +431,9 @@ func (_m *Client) GlobalRegistryDelete(registry string) error { return r0 } -// GlobalRegistryList provides a mock function with given fields: -func (_m *Client) GlobalRegistryList() ([]*woodpecker.Registry, error) { - ret := _m.Called() +// GlobalRegistryList provides a mock function with given fields: opt +func (_m *Client) GlobalRegistryList(opt woodpecker.RegistryListOptions) ([]*woodpecker.Registry, error) { + ret := _m.Called(opt) if len(ret) == 0 { panic("no return value specified for GlobalRegistryList") @@ -441,19 +441,19 @@ func (_m *Client) GlobalRegistryList() ([]*woodpecker.Registry, error) { var r0 []*woodpecker.Registry var r1 error - if rf, ok := ret.Get(0).(func() ([]*woodpecker.Registry, error)); ok { - return rf() + if rf, ok := ret.Get(0).(func(woodpecker.RegistryListOptions) ([]*woodpecker.Registry, error)); ok { + return rf(opt) } - if rf, ok := ret.Get(0).(func() []*woodpecker.Registry); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(woodpecker.RegistryListOptions) []*woodpecker.Registry); ok { + r0 = rf(opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Registry) } } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(woodpecker.RegistryListOptions) error); ok { + r1 = rf(opt) } else { r1 = ret.Error(1) } @@ -569,9 +569,9 @@ func (_m *Client) GlobalSecretDelete(secret string) error { return r0 } -// GlobalSecretList provides a mock function with given fields: -func (_m *Client) GlobalSecretList() ([]*woodpecker.Secret, error) { - ret := _m.Called() +// GlobalSecretList provides a mock function with given fields: opt +func (_m *Client) GlobalSecretList(opt woodpecker.SecretListOptions) ([]*woodpecker.Secret, error) { + ret := _m.Called(opt) if len(ret) == 0 { panic("no return value specified for GlobalSecretList") @@ -579,19 +579,19 @@ func (_m *Client) GlobalSecretList() ([]*woodpecker.Secret, error) { var r0 []*woodpecker.Secret var r1 error - if rf, ok := ret.Get(0).(func() ([]*woodpecker.Secret, error)); ok { - return rf() + if rf, ok := ret.Get(0).(func(woodpecker.SecretListOptions) ([]*woodpecker.Secret, error)); ok { + return rf(opt) } - if rf, ok := ret.Get(0).(func() []*woodpecker.Secret); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(woodpecker.SecretListOptions) []*woodpecker.Secret); ok { + r0 = rf(opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Secret) } } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(woodpecker.SecretListOptions) error); ok { + r1 = rf(opt) } else { r1 = ret.Error(1) } @@ -815,9 +815,9 @@ func (_m *Client) OrgRegistryDelete(orgID int64, registry string) error { return r0 } -// OrgRegistryList provides a mock function with given fields: orgID -func (_m *Client) OrgRegistryList(orgID int64) ([]*woodpecker.Registry, error) { - ret := _m.Called(orgID) +// OrgRegistryList provides a mock function with given fields: orgID, opt +func (_m *Client) OrgRegistryList(orgID int64, opt woodpecker.RegistryListOptions) ([]*woodpecker.Registry, error) { + ret := _m.Called(orgID, opt) if len(ret) == 0 { panic("no return value specified for OrgRegistryList") @@ -825,19 +825,19 @@ func (_m *Client) OrgRegistryList(orgID int64) ([]*woodpecker.Registry, error) { var r0 []*woodpecker.Registry var r1 error - if rf, ok := ret.Get(0).(func(int64) ([]*woodpecker.Registry, error)); ok { - return rf(orgID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.RegistryListOptions) ([]*woodpecker.Registry, error)); ok { + return rf(orgID, opt) } - if rf, ok := ret.Get(0).(func(int64) []*woodpecker.Registry); ok { - r0 = rf(orgID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.RegistryListOptions) []*woodpecker.Registry); ok { + r0 = rf(orgID, opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Registry) } } - if rf, ok := ret.Get(1).(func(int64) error); ok { - r1 = rf(orgID) + if rf, ok := ret.Get(1).(func(int64, woodpecker.RegistryListOptions) error); ok { + r1 = rf(orgID, opt) } else { r1 = ret.Error(1) } @@ -953,9 +953,9 @@ func (_m *Client) OrgSecretDelete(orgID int64, secret string) error { return r0 } -// OrgSecretList provides a mock function with given fields: orgID -func (_m *Client) OrgSecretList(orgID int64) ([]*woodpecker.Secret, error) { - ret := _m.Called(orgID) +// OrgSecretList provides a mock function with given fields: orgID, opt +func (_m *Client) OrgSecretList(orgID int64, opt woodpecker.SecretListOptions) ([]*woodpecker.Secret, error) { + ret := _m.Called(orgID, opt) if len(ret) == 0 { panic("no return value specified for OrgSecretList") @@ -963,19 +963,19 @@ func (_m *Client) OrgSecretList(orgID int64) ([]*woodpecker.Secret, error) { var r0 []*woodpecker.Secret var r1 error - if rf, ok := ret.Get(0).(func(int64) ([]*woodpecker.Secret, error)); ok { - return rf(orgID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.SecretListOptions) ([]*woodpecker.Secret, error)); ok { + return rf(orgID, opt) } - if rf, ok := ret.Get(0).(func(int64) []*woodpecker.Secret); ok { - r0 = rf(orgID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.SecretListOptions) []*woodpecker.Secret); ok { + r0 = rf(orgID, opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Secret) } } - if rf, ok := ret.Get(1).(func(int64) error); ok { - r1 = rf(orgID) + if rf, ok := ret.Get(1).(func(int64, woodpecker.SecretListOptions) error); ok { + r1 = rf(orgID, opt) } else { r1 = ret.Error(1) } @@ -1427,9 +1427,9 @@ func (_m *Client) RegistryDelete(repoID int64, hostname string) error { return r0 } -// RegistryList provides a mock function with given fields: repoID -func (_m *Client) RegistryList(repoID int64) ([]*woodpecker.Registry, error) { - ret := _m.Called(repoID) +// RegistryList provides a mock function with given fields: repoID, opt +func (_m *Client) RegistryList(repoID int64, opt woodpecker.RegistryListOptions) ([]*woodpecker.Registry, error) { + ret := _m.Called(repoID, opt) if len(ret) == 0 { panic("no return value specified for RegistryList") @@ -1437,19 +1437,19 @@ func (_m *Client) RegistryList(repoID int64) ([]*woodpecker.Registry, error) { var r0 []*woodpecker.Registry var r1 error - if rf, ok := ret.Get(0).(func(int64) ([]*woodpecker.Registry, error)); ok { - return rf(repoID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.RegistryListOptions) ([]*woodpecker.Registry, error)); ok { + return rf(repoID, opt) } - if rf, ok := ret.Get(0).(func(int64) []*woodpecker.Registry); ok { - r0 = rf(repoID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.RegistryListOptions) []*woodpecker.Registry); ok { + r0 = rf(repoID, opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Registry) } } - if rf, ok := ret.Get(1).(func(int64) error); ok { - r1 = rf(repoID) + if rf, ok := ret.Get(1).(func(int64, woodpecker.RegistryListOptions) error); ok { + r1 = rf(repoID, opt) } else { r1 = ret.Error(1) } @@ -1799,9 +1799,9 @@ func (_m *Client) SecretDelete(repoID int64, secret string) error { return r0 } -// SecretList provides a mock function with given fields: repoID -func (_m *Client) SecretList(repoID int64) ([]*woodpecker.Secret, error) { - ret := _m.Called(repoID) +// SecretList provides a mock function with given fields: repoID, opt +func (_m *Client) SecretList(repoID int64, opt woodpecker.SecretListOptions) ([]*woodpecker.Secret, error) { + ret := _m.Called(repoID, opt) if len(ret) == 0 { panic("no return value specified for SecretList") @@ -1809,19 +1809,19 @@ func (_m *Client) SecretList(repoID int64) ([]*woodpecker.Secret, error) { var r0 []*woodpecker.Secret var r1 error - if rf, ok := ret.Get(0).(func(int64) ([]*woodpecker.Secret, error)); ok { - return rf(repoID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.SecretListOptions) ([]*woodpecker.Secret, error)); ok { + return rf(repoID, opt) } - if rf, ok := ret.Get(0).(func(int64) []*woodpecker.Secret); ok { - r0 = rf(repoID) + if rf, ok := ret.Get(0).(func(int64, woodpecker.SecretListOptions) []*woodpecker.Secret); ok { + r0 = rf(repoID, opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.Secret) } } - if rf, ok := ret.Get(1).(func(int64) error); ok { - r1 = rf(repoID) + if rf, ok := ret.Get(1).(func(int64, woodpecker.SecretListOptions) error); ok { + r1 = rf(repoID, opt) } else { r1 = ret.Error(1) } @@ -2025,9 +2025,9 @@ func (_m *Client) UserDel(_a0 string) error { return r0 } -// UserList provides a mock function with given fields: -func (_m *Client) UserList() ([]*woodpecker.User, error) { - ret := _m.Called() +// UserList provides a mock function with given fields: opt +func (_m *Client) UserList(opt woodpecker.UserListOptions) ([]*woodpecker.User, error) { + ret := _m.Called(opt) if len(ret) == 0 { panic("no return value specified for UserList") @@ -2035,19 +2035,19 @@ func (_m *Client) UserList() ([]*woodpecker.User, error) { var r0 []*woodpecker.User var r1 error - if rf, ok := ret.Get(0).(func() ([]*woodpecker.User, error)); ok { - return rf() + if rf, ok := ret.Get(0).(func(woodpecker.UserListOptions) ([]*woodpecker.User, error)); ok { + return rf(opt) } - if rf, ok := ret.Get(0).(func() []*woodpecker.User); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(woodpecker.UserListOptions) []*woodpecker.User); ok { + r0 = rf(opt) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*woodpecker.User) } } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(woodpecker.UserListOptions) error); ok { + r1 = rf(opt) } else { r1 = ret.Error(1) } diff --git a/woodpecker-go/woodpecker/org.go b/woodpecker-go/woodpecker/org.go index a653e303c..5d00b86d9 100644 --- a/woodpecker-go/woodpecker/org.go +++ b/woodpecker-go/woodpecker/org.go @@ -1,6 +1,9 @@ package woodpecker -import "fmt" +import ( + "fmt" + "net/url" +) const ( pathOrg = "%s/api/orgs/%d" @@ -36,10 +39,11 @@ func (c *client) OrgSecret(orgID int64, secret string) (*Secret, error) { } // OrgSecretList returns a list of all organization secrets. -func (c *client) OrgSecretList(orgID int64) ([]*Secret, error) { +func (c *client) OrgSecretList(orgID int64, opt SecretListOptions) ([]*Secret, error) { var out []*Secret - uri := fmt.Sprintf(pathOrgSecrets, c.addr, orgID) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathOrgSecrets, c.addr, orgID)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } @@ -74,10 +78,11 @@ func (c *client) OrgRegistry(orgID int64, registry string) (*Registry, error) { } // OrgRegistryList returns a list of all organization registries. -func (c *client) OrgRegistryList(orgID int64) ([]*Registry, error) { +func (c *client) OrgRegistryList(orgID int64, opt RegistryListOptions) ([]*Registry, error) { var out []*Registry - uri := fmt.Sprintf(pathOrgRegistries, c.addr, orgID) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathOrgRegistries, c.addr, orgID)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } diff --git a/woodpecker-go/woodpecker/repo.go b/woodpecker-go/woodpecker/repo.go index d46077ee7..af5d0ca95 100644 --- a/woodpecker-go/woodpecker/repo.go +++ b/woodpecker-go/woodpecker/repo.go @@ -35,6 +35,18 @@ type PipelineListOptions struct { After time.Time } +type CronListOptions struct { + ListOptions +} + +type RegistryListOptions struct { + ListOptions +} + +type SecretListOptions struct { + ListOptions +} + type DeployOptions struct { DeployTo string // override the target deploy value Params map[string]string // custom KEY=value parameters to be injected into the step environment @@ -128,7 +140,6 @@ func (c *client) RepoPost(opt RepoPostOptions) (*Repo, error) { out := new(Repo) uri, _ := url.Parse(fmt.Sprintf(pathRepoPost, c.addr)) uri.RawQuery = opt.QueryEncode() - fmt.Println("!!!!!!!!!!", uri.String()) err := c.post(uri.String(), nil, out) return out, err } @@ -178,10 +189,11 @@ func (c *client) Registry(repoID int64, hostname string) (*Registry, error) { } // RegistryList returns a list of all repository registries. -func (c *client) RegistryList(repoID int64) ([]*Registry, error) { +func (c *client) RegistryList(repoID int64, opt RegistryListOptions) ([]*Registry, error) { var out []*Registry - uri := fmt.Sprintf(pathRepoRegistries, c.addr, repoID) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathRepoRegistries, c.addr, repoID)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } @@ -216,10 +228,11 @@ func (c *client) Secret(repoID int64, secret string) (*Secret, error) { } // SecretList returns a list of all repository secrets. -func (c *client) SecretList(repoID int64) ([]*Secret, error) { +func (c *client) SecretList(repoID int64, opt SecretListOptions) ([]*Secret, error) { var out []*Secret - uri := fmt.Sprintf(pathRepoSecrets, c.addr, repoID) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathRepoSecrets, c.addr, repoID)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } @@ -246,10 +259,11 @@ func (c *client) SecretDelete(repoID int64, secret string) error { } // CronList returns a list of cronjobs for the specified repository. -func (c *client) CronList(repoID int64) ([]*Cron, error) { +func (c *client) CronList(repoID int64, opt CronListOptions) ([]*Cron, error) { out := make([]*Cron, 0, 5) - uri := fmt.Sprintf(pathRepoCrons, c.addr, repoID) - return out, c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathRepoCrons, c.addr, repoID)) + uri.RawQuery = opt.getURLQuery().Encode() + return out, c.get(uri.String(), &out) } // CronCreate creates a new cron job for the specified repository. diff --git a/woodpecker-go/woodpecker/user.go b/woodpecker-go/woodpecker/user.go index 448c28706..144280aef 100644 --- a/woodpecker-go/woodpecker/user.go +++ b/woodpecker-go/woodpecker/user.go @@ -16,6 +16,10 @@ type RepoListOptions struct { All bool // query all repos, including inactive ones } +type UserListOptions struct { + ListOptions +} + // QueryEncode returns the URL query parameters for the RepoListOptions. func (opt *RepoListOptions) QueryEncode() string { query := make(url.Values) @@ -42,10 +46,11 @@ func (c *client) User(login string) (*User, error) { } // UserList returns a list of all registered users. -func (c *client) UserList() ([]*User, error) { +func (c *client) UserList(opt UserListOptions) ([]*User, error) { var out []*User - uri := fmt.Sprintf(pathUsers, c.addr) - err := c.get(uri, &out) + uri, _ := url.Parse(fmt.Sprintf(pathUsers, c.addr)) + uri.RawQuery = opt.getURLQuery().Encode() + err := c.get(uri.String(), &out) return out, err } diff --git a/woodpecker-go/woodpecker/user_test.go b/woodpecker-go/woodpecker/user_test.go index 01d2666a0..709ca66b0 100644 --- a/woodpecker-go/woodpecker/user_test.go +++ b/woodpecker-go/woodpecker/user_test.go @@ -52,7 +52,7 @@ func TestClient_UserList(t *testing.T) { defer ts.Close() client := NewClient(ts.URL, http.DefaultClient) - users, err := client.UserList() + users, err := client.UserList(UserListOptions{}) if tt.wantErr { assert.Error(t, err)