@@ -32,65 +32,84 @@ func (p *PullRequestService) Get(ctx context.Context, scope dto.Scope, repoID st
32
32
return pr , nil
33
33
}
34
34
35
+ // setDefaultPaginationForPR sets default pagination values for PullRequestOptions
36
+ // We don't use the generic functions here since it follows a different naming
37
+ // (uses page and limit instead of page and size)
38
+ func setDefaultPaginationForPR (opts * dto.PullRequestOptions ) {
39
+ if opts == nil {
40
+ return
41
+ }
42
+ if opts .Page <= 0 {
43
+ opts .Page = 1
44
+ }
45
+
46
+ if opts .Limit <= 0 {
47
+ opts .Limit = defaultPageSize
48
+ } else if opts .Limit > maxPageSize {
49
+ opts .Limit = maxPageSize
50
+ }
51
+ }
52
+
35
53
func (p * PullRequestService ) List (ctx context.Context , scope dto.Scope , repoID string , opts * dto.PullRequestOptions ) ([]* dto.PullRequest , error ) {
36
54
path := fmt .Sprintf (pullRequestListPath , repoID )
37
55
params := make (map [string ]string )
38
56
addScope (scope , params )
39
57
40
- // Add query parameters from options
41
- if opts != nil {
42
- if len (opts .State ) > 0 {
43
- params ["state" ] = strings .Join (opts .State , "," )
44
- }
45
- if opts .SourceRepoRef != "" {
46
- params ["source_repo_ref" ] = opts .SourceRepoRef
47
- }
48
- if opts .SourceBranch != "" {
49
- params ["source_branch" ] = opts .SourceBranch
50
- }
51
- if opts .TargetBranch != "" {
52
- params ["target_branch" ] = opts .TargetBranch
53
- }
54
- if opts .Query != "" {
55
- params ["query" ] = opts .Query
56
- }
57
- if len (opts .CreatedBy ) > 0 {
58
- createdByStrings := make ([]string , len (opts .CreatedBy ))
59
- for i , id := range opts .CreatedBy {
60
- createdByStrings [i ] = fmt .Sprintf ("%d" , id )
61
- }
62
- params ["created_by" ] = strings .Join (createdByStrings , "," )
63
- }
64
- if opts .Order != "" {
65
- params ["order" ] = opts .Order
66
- }
67
- if opts .Sort != "" {
68
- params ["sort" ] = opts .Sort
69
- }
70
- if opts .CreatedLt > 0 {
71
- params ["created_lt" ] = fmt .Sprintf ("%d" , opts .CreatedLt )
72
- }
73
- if opts .CreatedGt > 0 {
74
- params ["created_gt" ] = fmt .Sprintf ("%d" , opts .CreatedGt )
75
- }
76
- if opts .UpdatedLt > 0 {
77
- params ["updated_lt" ] = fmt .Sprintf ("%d" , opts .UpdatedLt )
78
- }
79
- if opts .UpdatedGt > 0 {
80
- params ["updated_gt" ] = fmt .Sprintf ("%d" , opts .UpdatedGt )
81
- }
82
- if opts .Page > 0 {
83
- params ["page" ] = fmt .Sprintf ("%d" , opts .Page )
84
- }
85
- if opts .Limit > 0 {
86
- params ["limit" ] = fmt .Sprintf ("%d" , opts .Limit )
87
- }
88
- if opts .AuthorID > 0 {
89
- params ["author_id" ] = fmt .Sprintf ("%d" , opts .AuthorID )
90
- }
91
- if opts .IncludeChecks {
92
- params ["include_checks" ] = "true"
58
+ // Handle nil options by creating default options
59
+ if opts == nil {
60
+ opts = & dto.PullRequestOptions {}
61
+ }
62
+
63
+ setDefaultPaginationForPR (opts )
64
+
65
+ params ["page" ] = fmt .Sprintf ("%d" , opts .Page )
66
+ params ["limit" ] = fmt .Sprintf ("%d" , opts .Limit )
67
+
68
+ if len (opts .State ) > 0 {
69
+ params ["state" ] = strings .Join (opts .State , "," )
70
+ }
71
+ if opts .SourceRepoRef != "" {
72
+ params ["source_repo_ref" ] = opts .SourceRepoRef
73
+ }
74
+ if opts .SourceBranch != "" {
75
+ params ["source_branch" ] = opts .SourceBranch
76
+ }
77
+ if opts .TargetBranch != "" {
78
+ params ["target_branch" ] = opts .TargetBranch
79
+ }
80
+ if opts .Query != "" {
81
+ params ["query" ] = opts .Query
82
+ }
83
+ if len (opts .CreatedBy ) > 0 {
84
+ createdByStrings := make ([]string , len (opts .CreatedBy ))
85
+ for i , id := range opts .CreatedBy {
86
+ createdByStrings [i ] = fmt .Sprintf ("%d" , id )
93
87
}
88
+ params ["created_by" ] = strings .Join (createdByStrings , "," )
89
+ }
90
+ if opts .Order != "" {
91
+ params ["order" ] = opts .Order
92
+ }
93
+ if opts .Sort != "" {
94
+ params ["sort" ] = opts .Sort
95
+ }
96
+ if opts .CreatedLt > 0 {
97
+ params ["created_lt" ] = fmt .Sprintf ("%d" , opts .CreatedLt )
98
+ }
99
+ if opts .CreatedGt > 0 {
100
+ params ["created_gt" ] = fmt .Sprintf ("%d" , opts .CreatedGt )
101
+ }
102
+ if opts .UpdatedLt > 0 {
103
+ params ["updated_lt" ] = fmt .Sprintf ("%d" , opts .UpdatedLt )
104
+ }
105
+ if opts .UpdatedGt > 0 {
106
+ params ["updated_gt" ] = fmt .Sprintf ("%d" , opts .UpdatedGt )
107
+ }
108
+ if opts .AuthorID > 0 {
109
+ params ["author_id" ] = fmt .Sprintf ("%d" , opts .AuthorID )
110
+ }
111
+ if opts .IncludeChecks {
112
+ params ["include_checks" ] = "true"
94
113
}
95
114
96
115
var prs []* dto.PullRequest
0 commit comments