1
1
import { BaseService , RequestHelper } from '../infrastructure' ;
2
- import { RequestOptions } from '../infrastructure/RequestHelper' ;
3
-
4
- export type MergeRequestId = string | number ;
5
2
6
3
class MergeRequests extends BaseService {
7
- accept ( projectId : ProjectId , mergerequestId : MergeRequestId , options : RequestOptions ) {
8
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
4
+ accept (
5
+ projectId : ProjectId ,
6
+ mergerequestIId : MergeRequestId ,
7
+ options ?: AcceptMergeRequestOptions & BaseRequestOptions ,
8
+ ) {
9
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
9
10
10
- return RequestHelper . put ( this , `projects/${ pId } /merge_requests/${ mId } /merge` , options ) ;
11
+ return RequestHelper . put ( this , `projects/${ pId } /merge_requests/${ mIId } /merge` , options ) ;
11
12
}
12
13
13
- addSpentTime ( projectId : ProjectId , mergerequestId : MergeRequestId , duration : Duration ) {
14
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
14
+ addSpentTime (
15
+ projectId : ProjectId ,
16
+ mergerequestIId : MergeRequestId ,
17
+ duration : string ,
18
+ options ?: Sudo ,
19
+ ) {
20
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
15
21
16
- return RequestHelper . post ( this , `projects/${ pId } /issues /${ mId } /add_spent_time` , {
22
+ return RequestHelper . post ( this , `projects/${ pId } /merge_requests /${ mIId } /add_spent_time` , {
17
23
duration,
24
+ ...options ,
18
25
} ) ;
19
26
}
20
27
21
- addTimeEstimate ( projectId : ProjectId , mergerequestId : MergeRequestId , duration : Duration ) {
22
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
28
+ addTimeEstimate (
29
+ projectId : ProjectId ,
30
+ mergerequestIId : MergeRequestId ,
31
+ duration : string ,
32
+ options ?: Sudo ,
33
+ ) {
34
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
23
35
24
- return RequestHelper . post ( this , `projects/${ pId } /issues /${ mId } /time_estimate` , {
36
+ return RequestHelper . post ( this , `projects/${ pId } /merge_requests /${ mIId } /time_estimate` , {
25
37
duration,
38
+ ...options ,
26
39
} ) ;
27
40
}
28
41
29
- approve ( projectId : ProjectId , mergerequestId : MergeRequestId , { sha } : { sha : string } ) {
30
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
42
+ all ( {
43
+ projectId,
44
+ groupId,
45
+ ...options
46
+ } : ( { projectId : ProjectId } | { groupId : GroupId } | { } ) & PaginatedRequestOptions ) {
47
+ let url ;
48
+
49
+ if ( projectId ) {
50
+ url = `projects/${ encodeURIComponent ( projectId ) } /merge_requests` ;
51
+ } else if ( groupId ) {
52
+ url = `groups/${ encodeURIComponent ( groupId ) } /merge_requests` ;
53
+ } else {
54
+ url = 'merge_requests' ;
55
+ }
31
56
32
- return RequestHelper . post ( this , `projects/ ${ pId } /merge_requests/ ${ mId } /approve` , { sha } ) ;
57
+ return RequestHelper . get ( this , url , options ) ;
33
58
}
34
59
35
- approvals ( projectId : ProjectId , { mergerequestId } : { mergerequestId ?: MergeRequestId } = { } ) {
36
- const pId = encodeURIComponent ( projectId ) ;
37
- const mergeRequest = mergerequestId ? `merge_requests/${ encodeURIComponent ( mergerequestId ) } ` : '' ;
60
+ approve (
61
+ projectId : ProjectId ,
62
+ mergerequestIId : MergeRequestId ,
63
+ options : { sha ?: string } & BaseRequestOptions ,
64
+ ) {
65
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
38
66
39
- return RequestHelper . get ( this , `projects/${ pId } /${ mergeRequest } /approvals` ) ;
67
+ return RequestHelper . post ( this , `projects/${ pId } /merge_requests/ ${ mIId } /approve` , options ) ;
40
68
}
41
69
42
- all ( { projectId, ...options } : { projectId ?: ProjectId } = { } ) {
43
- const url = projectId ? `projects/${ encodeURIComponent ( projectId ) } /merge_requests` : 'merge_requests' ;
70
+ approvals (
71
+ projectId : ProjectId ,
72
+ { mergerequestIId, ...options } : { mergerequestIId ?: MergeRequestId } & BaseRequestOptions ,
73
+ ) {
74
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
75
+
76
+ let url ;
77
+
78
+ if ( mergerequestIId ) {
79
+ url = `projects/${ pId } /merge_requests/${ mIId } /approvals` ;
80
+ } else {
81
+ url = `projects/${ pId } /approvals` ;
82
+ }
44
83
45
84
return RequestHelper . get ( this , url , options ) ;
46
85
}
47
86
48
- cancelOnPipelineSucess ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
49
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
87
+ approvers (
88
+ projectId : ProjectId ,
89
+ approverIds : UserId [ ] ,
90
+ approverGroupIds : GroupId [ ] ,
91
+ { mergerequestIId, ...options } : { mergerequestIId ?: MergeRequestId } & BaseRequestOptions ,
92
+ ) {
93
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
94
+
95
+ let url ;
96
+
97
+ if ( mergerequestIId ) {
98
+ url = `projects/${ pId } /merge_requests/${ mIId } /approvers` ;
99
+ } else {
100
+ url = `projects/${ pId } /approvers` ;
101
+ }
50
102
51
- return RequestHelper . put ( this , `projects/ ${ pId } /merge_requests/ ${ mId } /cancel_merge_when_pipeline_succeeds` ) ;
103
+ return RequestHelper . put ( this , url , { approverIds , approverGroupIds , ... options } ) ;
52
104
}
53
105
54
- changes ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
55
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
106
+ cancelOnPipelineSucess ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
107
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
56
108
57
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } /changes` ) ;
109
+ return RequestHelper . put (
110
+ this ,
111
+ `projects/${ pId } /merge_requests/${ mIId } /cancel_merge_when_pipeline_succeeds` ,
112
+ options ,
113
+ ) ;
58
114
}
59
115
60
- closesIssues ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
61
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
116
+ changes ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
117
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
62
118
63
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } /closes_issues` ) ;
119
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mIId } /changes` , options ) ;
64
120
}
65
121
66
- commits ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
67
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
122
+ closesIssues ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
123
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
68
124
69
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } /commits` ) ;
125
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mIId } /closes_issues` , options ) ;
126
+ }
127
+
128
+ commits ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
129
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
130
+
131
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mIId } /commits` , options ) ;
70
132
}
71
133
72
134
create (
73
135
projectId : ProjectId ,
74
136
sourceBranch : string ,
75
137
targetBranch : string ,
76
138
title : string ,
77
- options : RequestOptions ,
139
+ options ?: CreateMergeRequestOptions & BaseRequestOptions ,
78
140
) {
79
141
const pId = encodeURIComponent ( projectId ) ;
80
142
@@ -87,24 +149,37 @@ class MergeRequests extends BaseService {
87
149
} ) ;
88
150
}
89
151
90
- edit ( projectId : ProjectId , mergerequestId : MergeRequestId , options : RequestOptions ) {
91
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
152
+ edit (
153
+ projectId : ProjectId ,
154
+ mergerequestIId : MergeRequestId ,
155
+ options ?: UpdateMergeRequestOptions & BaseRequestOptions ,
156
+ ) {
157
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
92
158
93
- return RequestHelper . put ( this , `projects/${ pId } /merge_requests/${ mId } ` , options ) ;
159
+ return RequestHelper . put ( this , `projects/${ pId } /merge_requests/${ mIId } ` , options ) ;
94
160
}
95
161
96
- editApprovals ( projectId : ProjectId , { mergerequestId, ...options } : temporaryAny ) {
97
- const pId = encodeURIComponent ( projectId ) ;
98
- const mergeRequest = mergerequestId ? `merge_requests/${ encodeURIComponent ( mergerequestId ) } /` : '' ;
162
+ editApprovals (
163
+ projectId : ProjectId ,
164
+ { mergerequestIId, ...options } : { mergerequestIId ?: MergeRequestId } & BaseRequestOptions ,
165
+ ) {
166
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
167
+
168
+ let url ;
99
169
100
- return RequestHelper . post ( this , `projects/${ pId } /${ mergeRequest } approvals` , options ) ;
170
+ if ( mergerequestIId ) {
171
+ url = `projects/${ pId } /merge_requests/${ mIId } /approvals` ;
172
+ } else {
173
+ url = `projects/${ pId } /approvals` ;
174
+ }
175
+
176
+ return RequestHelper . post ( this , url , options ) ;
101
177
}
102
178
103
- editApprovers ( projectId : ProjectId , { mergerequestId, ...options } : temporaryAny ) {
104
- const pId = encodeURIComponent ( projectId ) ;
105
- const mergeRequest = mergerequestId ? `merge_requests/${ encodeURIComponent ( mergerequestId ) } /` : '' ;
179
+ participants ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
180
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
106
181
107
- return RequestHelper . put ( this , `projects/${ pId } /${ mergeRequest } approvers ` , options ) ;
182
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/ ${ mIId } /participants ` , options ) ;
108
183
}
109
184
110
185
pipelines ( projectId : ProjectId , { mergerequestId } : { mergerequestId ?: string } = { } ) {
@@ -114,58 +189,79 @@ class MergeRequests extends BaseService {
114
189
return RequestHelper . get ( this , `projects/${ pId } /${ mergeRequest } /pipelines` ) ;
115
190
}
116
191
117
- remove ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
118
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
192
+ remove ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
193
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
119
194
120
- return RequestHelper . delete ( this , `projects/${ pId } /merge_requests/${ mId } ` ) ;
195
+ return RequestHelper . del ( this , `projects/${ pId } /merge_requests/${ mIId } ` , options ) ;
121
196
}
122
197
123
- resetSpentTime ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
124
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
198
+ resetSpentTime ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
199
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
125
200
126
- return RequestHelper . post ( this , `projects/${ pId } /merge_requests/${ mId } /reset_spent_time` ) ;
201
+ return RequestHelper . post (
202
+ this ,
203
+ `projects/${ pId } /merge_requests/${ mIId } /reset_spent_time` ,
204
+ options ,
205
+ ) ;
127
206
}
128
207
129
- resetTimeEstimate ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
130
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
208
+ resetTimeEstimate ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
209
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
131
210
132
- return RequestHelper . post ( this , `projects/${ pId } /merge_requests/${ mId } /reset_time_estimate` ) ;
211
+ return RequestHelper . post (
212
+ this ,
213
+ `projects/${ pId } /merge_requests/${ mIId } /reset_time_estimate` ,
214
+ options ,
215
+ ) ;
133
216
}
134
217
135
- show ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
136
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
218
+ show (
219
+ projectId : ProjectId ,
220
+ mergerequestIId : MergeRequestId ,
221
+ options ?: ShowMergeRequestOptions & BaseRequestOptions ,
222
+ ) {
223
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
137
224
138
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } ` ) ;
225
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mIId } ` , options ) ;
139
226
}
140
227
141
- timeStats ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
142
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
228
+ timeStats ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
229
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
143
230
144
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } /time_stats` ) ;
231
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mIId } /time_stats` , options ) ;
145
232
}
146
233
147
- version ( projectId : ProjectId , mergerequestId : MergeRequestId , versionId : string | number ) {
148
- const [ pId , mId , vId ] = [ projectId , mergerequestId , versionId ] . map ( encodeURIComponent ) ;
234
+ version (
235
+ projectId : ProjectId ,
236
+ mergerequestIId : MergeRequestId ,
237
+ versionId : number ,
238
+ options ?: Sudo ,
239
+ ) {
240
+ const [ pId , mIId , vId ] = [ projectId , mergerequestIId , versionId ] . map ( encodeURIComponent ) ;
149
241
150
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } /versions/${ vId } ` ) ;
242
+ return RequestHelper . get (
243
+ this ,
244
+ `projects/${ pId } /merge_requests/${ mIId } /versions/${ vId } ` ,
245
+ options ,
246
+ ) ;
151
247
}
152
248
153
- versions ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
154
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
249
+ versions ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
250
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
155
251
156
- return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mId } /versions` ) ;
252
+ return RequestHelper . get ( this , `projects/${ pId } /merge_requests/${ mIId } /versions` , options ) ;
157
253
}
158
254
159
- unapprove ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
160
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
255
+ unapprove ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
256
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
161
257
162
- return RequestHelper . post ( this , `projects/${ pId } /merge_requests/${ mId } /approve` ) ;
258
+ return RequestHelper . post ( this , `projects/${ pId } /merge_requests/${ mIId } /approve` , options ) ;
163
259
}
164
260
165
- unsubscribe ( projectId : ProjectId , mergerequestId : MergeRequestId ) {
166
- const [ pId , mId ] = [ projectId , mergerequestId ] . map ( encodeURIComponent ) ;
261
+ unsubscribe ( projectId : ProjectId , mergerequestIId : MergeRequestId , options ?: Sudo ) {
262
+ const [ pId , mIId ] = [ projectId , mergerequestIId ] . map ( encodeURIComponent ) ;
167
263
168
- return RequestHelper . delete ( this , `projects/${ pId } /merge_requests/${ mId } /unsubscribe` ) ;
264
+ return RequestHelper . del ( this , `projects/${ pId } /merge_requests/${ mIId } /unsubscribe` , options ) ;
169
265
}
170
266
}
171
267
0 commit comments