Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 66ff9ee

Browse files
committed
feat: support merging in gitlab
Implement accept merge request api. Relates to #166
1 parent 6340781 commit 66ff9ee

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/provider/gitlab/api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface GitLab {
1414
getMergeRequest(id: string, mr_iid: number): Promise<GitLabResponse<MergeRequest>>;
1515
createMergeRequest(id: string, body: CreateMergeRequestBody): Promise<GitLabResponse<MergeRequest>>;
1616
updateMergeRequest(id: string, mr_iid: number, body: UpdateMergeRequestBody): Promise<GitLabResponse<MergeRequest>>;
17+
acceptMergeRequest(id: string, mr_iid: number, body: AcceptMergeRequestBody)
18+
: Promise<GitLabResponse<AcceptMergeRequestResponse>>;
1719
getProjectIssues(id: string, body: ProjectIssuesBody): Promise<GitLabResponse<Issue[]>>;
1820
searchUser(parameters?: SearchUsersParameters): Promise<GitLabResponse<UserResponse[]>>;
1921
}
@@ -24,6 +26,16 @@ export interface GitLabResponse<T> {
2426
body: T;
2527
}
2628

29+
export interface AcceptMergeRequestBody {
30+
should_remove_source_branch?: boolean;
31+
}
32+
33+
export interface AcceptMergeRequestResponse {
34+
title: string;
35+
state: 'merged';
36+
sha: string;
37+
}
38+
2739
export interface SearchUsersParameters {
2840
username?: string;
2941
}
@@ -190,6 +202,9 @@ namespace impl {
190202
@Put('/projects/:id/merge_requests/:merge_request_iid')
191203
public updateMergeRequest(): any {/* */}
192204

205+
@Put('/projects/:id/merge_requests/:merge_request_iid/merge')
206+
public acceptMergeRequest(): any {/* */}
207+
193208
@Get('/projects/:id/issues')
194209
public getProjectIssues(): any {/* */}
195210

src/provider/gitlab/merge-request.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getConfiguration } from '../../helper';
12
import { Response } from '../client';
23
import {
34
PullRequest,
@@ -102,7 +103,20 @@ export class GitLabMergeRequest implements PullRequest {
102103
}
103104

104105
public async merge(_body: MergeBody): Promise<Response<MergeResult>> {
105-
throw new Error('Method not implemented.');
106+
const response = await this.client.acceptMergeRequest(
107+
encodeURIComponent(this.repository.pathWithNamespace),
108+
this.mergeRequest.iid,
109+
{
110+
should_remove_source_branch: getConfiguration('gitlab').removeSourceBranch
111+
}
112+
);
113+
return {
114+
body: {
115+
message: response.body.title,
116+
merged: response.body.state === 'merged',
117+
sha: response.body.sha
118+
}
119+
};
106120
}
107121

108122
public async assign(assignees: GitLabUser[]): Promise<void> {

0 commit comments

Comments
 (0)