From 2bf9d39f65785339c935b4db61bd98a9f231b3e4 Mon Sep 17 00:00:00 2001 From: Matt Meng Date: Tue, 15 Mar 2022 11:51:45 -0600 Subject: [PATCH] Add an API endpoint for merge request deletion. --- lib/gitlab/client/merge_requests.rb | 12 ++++++++++++ spec/gitlab/client/merge_requests_spec.rb | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/gitlab/client/merge_requests.rb b/lib/gitlab/client/merge_requests.rb index 12ec16711..62443cd53 100644 --- a/lib/gitlab/client/merge_requests.rb +++ b/lib/gitlab/client/merge_requests.rb @@ -332,6 +332,18 @@ def delete_merge_request_discussion_note(project, merge_request_id, discussion_i delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}") end + # Delete a merge request + # + # @example + # Gitlab.delete_merge_request(5, 1) + # Gitlab.delete_merge_request('gitlab', 1) + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a merge request. + # @return [Gitlab::ObjectifiedHash] An empty response. + def delete_merge_request(project, merge_request_id) + delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}") + end + # Gets a list of merge request diff versions # # @example diff --git a/spec/gitlab/client/merge_requests_spec.rb b/spec/gitlab/client/merge_requests_spec.rb index b05bf4364..a24fe2e63 100644 --- a/spec/gitlab/client/merge_requests_spec.rb +++ b/spec/gitlab/client/merge_requests_spec.rb @@ -388,6 +388,21 @@ end end + describe '.delete_merge_request' do + before do + stub_request(:delete, 'https://api.example.com/projects/3/merge_requests/2').to_return(body: '') + @merge_request = Gitlab.delete_merge_request(3, 2) + end + + it 'deletes the correct resource' do + expect(a_delete('/projects/3/merge_requests/2')).to have_been_made + end + + it 'returns nothing' do + expect(@merge_request).to be_falsy + end + end + describe '.merge_request_diff_versions' do before do stub_get('/projects/3/merge_requests/105/versions', 'merge_request_diff_versions')