Commit 06713cb7 authored by Sean McGivern's avatar Sean McGivern

Merge branch '39214__pipeline_api' into 'master'

Add `pipelines` endpoint to merge requests API

Closes #39214

See merge request gitlab-org/gitlab-ce!15454
parents 59adc07f 7ed08fcd
---
title: Add `pipelines` endpoint to merge requests API
merge_request: 15454
author: Tony Rom <thetonyrom@gmail.com>
type: added
......@@ -468,6 +468,30 @@ Parameters:
}
```
## List MR pipelines
Get a list of merge request pipelines.
```
GET /projects/:id/merge_requests/:merge_request_iid/pipelines
```
Parameters:
- `id` (required) - The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user
- `merge_request_iid` (required) - The internal ID of the merge request
```json
[
{
"id": 77,
"sha": "959e04d7c7a30600c894bd3c0cd0e1ce7f42c11d",
"ref": "master",
"status": "success"
}
]
```
## Create MR
Creates a new merge request.
......
......@@ -24,6 +24,13 @@ module API
.preload(:notes, :author, :assignee, :milestone, :latest_merge_request_diff, :labels, :timelogs)
end
def merge_request_pipelines_with_access
authorize! :read_pipeline, user_project
mr = find_merge_request_with_access(params[:merge_request_iid])
mr.all_pipelines
end
params :merge_requests_params do
optional :state, type: String, values: %w[opened closed merged all], default: 'all',
desc: 'Return opened, closed, merged, or all merge requests'
......@@ -214,6 +221,15 @@ module API
present merge_request, with: Entities::MergeRequestChanges, current_user: current_user
end
desc 'Get the merge request pipelines' do
success Entities::PipelineBasic
end
get ':id/merge_requests/:merge_request_iid/pipelines' do
pipelines = merge_request_pipelines_with_access
present paginate(pipelines), with: Entities::PipelineBasic
end
desc 'Update a merge request' do
success Entities::MergeRequest
end
......
{
"type": "array",
"items": { "$ref": "pipeline/basic.json" }
}
......@@ -551,6 +551,49 @@ describe API::MergeRequests do
end
end
describe 'GET /projects/:id/merge_requests/:merge_request_iid/pipelines' do
context 'when authorized' do
let!(:pipeline) { create(:ci_empty_pipeline, project: project, user: user, ref: merge_request.source_branch, sha: merge_request.diff_head_sha) }
let!(:pipeline2) { create(:ci_empty_pipeline, project: project) }
it 'returns a paginated array of corresponding pipelines' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines")
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.count).to eq(1)
expect(json_response.first['id']).to eq(pipeline.id)
end
it 'exposes basic attributes' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines")
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/pipelines')
end
it 'returns 404 if MR does not exist' do
get api("/projects/#{project.id}/merge_requests/777/pipelines")
expect(response).to have_gitlab_http_status(404)
end
end
context 'when unauthorized' do
it 'returns 403' do
project = create(:project, public_builds: false)
merge_request = create(:merge_request, :simple, source_project: project)
guest = create(:user)
project.team << [guest, :guest]
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines", guest)
expect(response).to have_gitlab_http_status(403)
end
end
end
describe "POST /projects/:id/merge_requests" do
context 'between branches projects' do
it "returns merge_request" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment