Merge requests

You can use merge requests to notify a project that a branch is ready for merging. The owner of the target projet can accept the merge request.

Examples

List MRs for a project:

mrs = gl.project_mergerequests.list(project_id=1)
# or
mrs = project.mergerequests.list()

You can filter and sort the returned list with the following parameters:

  • iid: iid (unique ID for the project) of the MR
  • state: state of the MR. It can be one of all, merged, ‘opened or closed
  • order_by: sort by created_at or updated_at
  • sort: sort order (asc or desc)

For example:

mrs = gl.project_mergerequests.list(project_id=1)
# or
mrs = project.mergerequests.list()

Get a single MR:

mr = gl.project_mergerequests.get(mr_id, project_id=1)
# or
mr = project.mergerequests.get(mr_id)

Create a MR:

mr = gl.project_mergerequests.create({'source_branch': 'cool_feature',
                                      'target_branch': 'master',
                                      'title': 'merge cool feature'},
                                     project_id=1)
# or
mr = project.mergerequests.create({'source_branch': 'cool_feature',
                                   'target_branch': 'master',
                                   'title': 'merge cool feature'})

Update a MR:

mr.description = 'New description'
mr.save()

Change the state of a MR (close or reopen):

mr.state_event = 'close'  # or 'reopen'
mr.save()

Delete a MR:

gl.project_mergerequests.delete(mr_id, project_id=1)
# or
project.mergerequests.delete(mr_id)
# or
mr.delete()

Accept a MR:

mr.merge()

Cancel a MR when the build succeeds:

mr.cancel_merge_when_build_succeeds()

List issues that will close on merge:

mr.closes_issues()

Subscribe/unsubscribe a MR:

mr.subscribe()
mr.unsubscribe()

Mark a MR as todo:

mr.todo()

List the diffs for a merge request:

diffs = mr.diffs.list()

Get a diff for a merge request:

diff = mr.diffs.get(diff_id)