55

I created a merge request on gitlab (local) server. Now whenever I click on the merge request, the request times out with error 500. Before that I used to get an error code 504 and I applied the change mentioned in this gitlab support topic.

All I want to do is remove the merge request. Is there a manual way of doing this?

AHiggins
  • 7,029
  • 6
  • 36
  • 54
Sanj
  • 3,770
  • 6
  • 26
  • 31

4 Answers4

80

Web UI Option

Today I discovered a way to do this with the Web UI.

So for Merge Request 14

https://gitlab.example.com/MyGroup/MyProject/merge_requests/14/edit

On the bottom Right you should see a red Delete button.

Gitlab Delete Merge Request Screen Shot

PowerShell Option

Invoke-RestMethod -Method Delete -Uri 'https://gitlab.example.com/api/v4/projects/PROJECT_ID_GOES_HERE/merge_requests/14' -Headers @{'PRIVATE-TOKEN'='PRIVATE_TOKEN_GOES_HERE'}

Community
  • 1
  • 1
Eric D. Johnson
  • 10,219
  • 9
  • 39
  • 46
  • 38
    FYI: The Delete button is only available if you have permission Owner. Unfortunately not documented yet: GitLab permissions - https://docs.gitlab.com/ee/user/permissions.html but indirect permission hint here: Delete a merge request - https://docs.gitlab.com/ee/api/merge_requests.html#delete-a-merge-request – Doctor Rudolf May 17 '18 at 09:00
  • 4
    Good clarity @DoctorRudolf .Yeah, if you're only at `Master` or `Developer` permissions levels you can't delete via the web UI. – Eric D. Johnson May 23 '18 at 12:28
  • 1
    `Maintainer` level also doesn't seem to have this option. Then again I'm not the admin of the GitLab instance so it might have been deactivated by the owner/admin. – rbaleksandar Apr 20 '22 at 05:39
15

Yes, there is.... I could not find a way to remove the merge request in the user interface, but you can simply delete it from the database.

(Please note, that I only tested this on gitlab CE 8.4.0-ce.0 on Ubuntu 14.04.3 LTS.. Other versions may have a different database structure)

At a command prompt, execute the following command (as root):

sudo -u gitlab-psql /opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql -d gitlabhq_production

This will bring up a PostgreSQL command terminal. Next, you'll have to find the merge request you'd like to delete. Type the following at the PostgreSQL command terminal:

select id, title from merge_requests;

You'll get a list of merge request ids and titles. Find the one you'd like to delete and note the id

OK, let's say you've found the merge request you'd like to delete and the id is 5. You're simply going to delete all the data associated with that merge request using the following SQL commands. (Substitute 5 in the commands below with your actual merge request id)

delete from merge_requests where id = 5;
delete from merge_request_diffs where merge_request_id = 5;
delete from notes where noteable_type = 'MergeRequest' and noteable_id = 5;

You can now exit out of the PostgreSQL command terminal by typing:

\q

Your merge request should now be gone from the web interface.

Ray Perea
  • 5,640
  • 1
  • 35
  • 38
  • 3
    This procedure still works on Gitlab CE 8.5.8 (46bb47a). So I suppose that also at least on all versions betweens 8.4.0 and 8.5.8 too. – Greg Dubicki Mar 21 '16 at 09:24
  • 2
    I think the solution proposed by @thomas-keller is cleaner. Fiddling directly in the DB is error-prone and you must be 100% sure that you properly clean everything. Using the API shifts this responsibility to the GitLab developers who undoubtedly have a better understanding of what should (and shouldn't) happen when deleting a MR. – exhuma Aug 03 '17 at 08:12
  • I think nowadays the preferred solution should be going through the Web UI as proposed by Eric. https://stackoverflow.com/a/49779365/968531 – NobodysNightmare Jul 08 '20 at 06:06
11

I don't know if this works with CE as well, but at least EE has an API endpoint to delete merge requests:

curl --request DELETE --header "PRIVATE-TOKEN: <private_token>" https://gitlab.example.com/api/v3/projects/4/merge_request/85
Rakesh
  • 3,370
  • 2
  • 23
  • 41
Thomas Keller
  • 5,933
  • 6
  • 48
  • 80
  • 1
    There is a new API version. https://docs.gitlab.com/ee/api/merge_requests.html#delete-a-merge-request. The URL has changed to `https://gitlab.example.com/api/v4/projects/4/merge_requests/85` – David Lilue Nov 24 '20 at 19:10
  • This worked with CE, but with @DavidLilue 's url – Savandy Apr 20 '21 at 12:15
-4

Go to the destination repository, find the merge request on that repo and just click "Close Merge Request". Since it is your merge request, you have the rights to do so.

Warren
  • 37
  • 3
  • 7
    Closing is not quite the same as deleting. Closing the MR keeps it in the DB for posterity. Sometimes you might want to completely get rid of it though (for example when you open MR to test something out). – exhuma Aug 03 '17 at 08:10