Skip to content

Commit

Permalink
Add the merge_request_dependencies method
Browse files Browse the repository at this point in the history
  • Loading branch information
ddieulivol committed Aug 23, 2024
1 parent dfffe94 commit cf69b6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/gitlab/client/merge_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def merge_request_pipelines(project, id)
get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines")
end

# Shows information about the merge request dependencies that must be resolved before merging.
#
# @example
# Gitlab.merge_request_dependencies(5, 36)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of a merge request.
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_request_dependencies(project, id)
get("/projects/#{url_encode project}/merge_requests/#{id}/blocks")
end

# Create a new pipeline for a merge request.
# A pipeline created via this endpoint doesnt run a regular branch/tag pipeline.
# It requires .gitlab-ci.yml to be configured with only: [merge_requests] to create jobs.
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/merge_request_dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1234,"blocking_merge_request":{"id":2,"target_branch":"master","source_branch":"api2","project_id":3,"title":"New feature 2","closed":false,"merged":false,"author":{"id":1,"email":"[email protected]","name":"John Smith","blocked":false,"created_at":"2012-10-19T05:56:05Z"},"assignee":{"id":2,"email":"[email protected]","name":"Jack Smith","blocked":false,"created_at":"2012-10-19T05:56:14Z"}},"blocked_merge_request":{"id":1,"target_branch":"master","source_branch":"api","project_id":3,"title":"New feature","closed":false,"merged":false,"author":{"id":1,"email":"[email protected]","name":"John Smith","blocked":false,"created_at":"2012-10-19T05:56:05Z"},"assignee":{"id":2,"email":"[email protected]","name":"Jack Smith","blocked":false,"created_at":"2012-10-19T05:56:14Z"}}}]
16 changes: 16 additions & 0 deletions spec/gitlab/client/merge_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@
end
end

describe '.merge_request_dependencies' do
before do
stub_get('/projects/3/merge_requests/1/blocks', 'merge_request_dependencies')
@pipelines = Gitlab.merge_request_dependencies(3, 1)
end

it 'gets the correct resource' do
expect(a_get('/projects/3/merge_requests/1/blocks')).to have_been_made
end

it 'returns information about merge request dependencies' do
expect(@pipelines.first.id).to eq(1234)
expect(@pipelines.first.keys).to include('blocking_merge_request', 'blocked_merge_request')
end
end

describe '.create_merge_request_pipeline' do
before do
stub_post('/projects/3/merge_requests/2/pipelines', 'pipeline_create')
Expand Down

0 comments on commit cf69b6e

Please sign in to comment.