Skip to content

Commit e4ba731

Browse files
committed
fix: Merge Request Approvals API did not match official API
Updated the function headers to match the official API. BREAKING CHANGE: Updated Approvals API support to match https://docs.gitlab.com/ee/api/merge_request_approvals.html
1 parent 97dd060 commit e4ba731

File tree

1 file changed

+168
-72
lines changed

1 file changed

+168
-72
lines changed

src/services/MergeRequests.ts

Lines changed: 168 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,142 @@
11
import { BaseService, RequestHelper } from '../infrastructure';
2-
import { RequestOptions } from '../infrastructure/RequestHelper';
3-
4-
export type MergeRequestId = string | number;
52

63
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);
910

10-
return RequestHelper.put(this, `projects/${pId}/merge_requests/${mId}/merge`, options);
11+
return RequestHelper.put(this, `projects/${pId}/merge_requests/${mIId}/merge`, options);
1112
}
1213

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);
1521

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`, {
1723
duration,
24+
...options,
1825
});
1926
}
2027

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);
2335

24-
return RequestHelper.post(this, `projects/${pId}/issues/${mId}/time_estimate`, {
36+
return RequestHelper.post(this, `projects/${pId}/merge_requests/${mIId}/time_estimate`, {
2537
duration,
38+
...options,
2639
});
2740
}
2841

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+
}
3156

32-
return RequestHelper.post(this, `projects/${pId}/merge_requests/${mId}/approve`, { sha });
57+
return RequestHelper.get(this, url, options);
3358
}
3459

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);
3866

39-
return RequestHelper.get(this, `projects/${pId}/${mergeRequest}/approvals`);
67+
return RequestHelper.post(this, `projects/${pId}/merge_requests/${mIId}/approve`, options);
4068
}
4169

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+
}
4483

4584
return RequestHelper.get(this, url, options);
4685
}
4786

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+
}
50102

51-
return RequestHelper.put(this, `projects/${pId}/merge_requests/${mId}/cancel_merge_when_pipeline_succeeds`);
103+
return RequestHelper.put(this, url, { approverIds, approverGroupIds, ...options });
52104
}
53105

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);
56108

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+
);
58114
}
59115

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);
62118

63-
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mId}/closes_issues`);
119+
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mIId}/changes`, options);
64120
}
65121

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);
68124

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);
70132
}
71133

72134
create(
73135
projectId: ProjectId,
74136
sourceBranch: string,
75137
targetBranch: string,
76138
title: string,
77-
options: RequestOptions,
139+
options?: CreateMergeRequestOptions & BaseRequestOptions,
78140
) {
79141
const pId = encodeURIComponent(projectId);
80142

@@ -87,24 +149,37 @@ class MergeRequests extends BaseService {
87149
});
88150
}
89151

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);
92158

93-
return RequestHelper.put(this, `projects/${pId}/merge_requests/${mId}`, options);
159+
return RequestHelper.put(this, `projects/${pId}/merge_requests/${mIId}`, options);
94160
}
95161

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;
99169

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);
101177
}
102178

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);
106181

107-
return RequestHelper.put(this, `projects/${pId}/${mergeRequest}approvers`, options);
182+
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mIId}/participants`, options);
108183
}
109184

110185
pipelines(projectId: ProjectId, { mergerequestId }: { mergerequestId?: string } = {}) {
@@ -114,58 +189,79 @@ class MergeRequests extends BaseService {
114189
return RequestHelper.get(this, `projects/${pId}/${mergeRequest}/pipelines`);
115190
}
116191

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);
119194

120-
return RequestHelper.delete(this, `projects/${pId}/merge_requests/${mId}`);
195+
return RequestHelper.del(this, `projects/${pId}/merge_requests/${mIId}`, options);
121196
}
122197

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);
125200

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+
);
127206
}
128207

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);
131210

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+
);
133216
}
134217

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);
137224

138-
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mId}`);
225+
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mIId}`, options);
139226
}
140227

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);
143230

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);
145232
}
146233

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);
149241

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+
);
151247
}
152248

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);
155251

156-
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mId}/versions`);
252+
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mIId}/versions`, options);
157253
}
158254

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);
161257

162-
return RequestHelper.post(this, `projects/${pId}/merge_requests/${mId}/approve`);
258+
return RequestHelper.post(this, `projects/${pId}/merge_requests/${mIId}/approve`, options);
163259
}
164260

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);
167263

168-
return RequestHelper.delete(this, `projects/${pId}/merge_requests/${mId}/unsubscribe`);
264+
return RequestHelper.del(this, `projects/${pId}/merge_requests/${mIId}/unsubscribe`, options);
169265
}
170266
}
171267

0 commit comments

Comments
 (0)