Commit a6e9175f authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '57662-api-updates-to-mr-and-pipeline' into 'master'

Expose pipeline in the related merge requests

Closes #57662

See merge request gitlab-org/gitlab-ce!26367
parents cdce2074 f4adb50e
...@@ -690,6 +690,10 @@ module API ...@@ -690,6 +690,10 @@ module API
# Deprecated # Deprecated
expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? } expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? }
expose :reference do |merge_request, options|
merge_request.to_reference(options[:project])
end
expose :web_url do |merge_request| expose :web_url do |merge_request|
Gitlab::UrlBuilder.build(merge_request) Gitlab::UrlBuilder.build(merge_request)
end end
...@@ -726,6 +730,8 @@ module API ...@@ -726,6 +730,8 @@ module API
merge_request.metrics&.pipeline merge_request.metrics&.pipeline
end end
expose :head_pipeline, using: 'API::Entities::Pipeline'
expose :diff_refs, using: Entities::DiffRefs expose :diff_refs, using: Entities::DiffRefs
# Allow the status of a rebase to be determined # Allow the status of a rebase to be determined
...@@ -1267,6 +1273,9 @@ module API ...@@ -1267,6 +1273,9 @@ module API
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration expose :duration
expose :coverage expose :coverage
expose :detailed_status, using: DetailedStatusEntity do |pipeline, options|
pipeline.detailed_status(options[:current_user])
end
end end
class PipelineSchedule < Grape::Entity class PipelineSchedule < Grape::Entity
......
...@@ -310,7 +310,7 @@ module API ...@@ -310,7 +310,7 @@ module API
.flatten .flatten
present paginate(::Kaminari.paginate_array(merge_requests)), present paginate(::Kaminari.paginate_array(merge_requests)),
with: Entities::MergeRequestBasic, with: Entities::MergeRequest,
current_user: current_user, current_user: current_user,
project: user_project project: user_project
end end
......
...@@ -119,6 +119,12 @@ ...@@ -119,6 +119,12 @@
"merge_status", "sha", "merge_commit_sha", "user_notes_count", "merge_status", "sha", "merge_commit_sha", "user_notes_count",
"should_remove_source_branch", "force_remove_source_branch", "should_remove_source_branch", "force_remove_source_branch",
"web_url", "squash" "web_url", "squash"
],
"head_pipeline": {
"oneOf": [
{ "type": "null" },
{ "$ref": "pipeline/detail.json" }
] ]
} }
}
} }
...@@ -13,6 +13,5 @@ ...@@ -13,6 +13,5 @@
"ref": { "type": "string" }, "ref": { "type": "string" },
"status": { "type": "string" }, "status": { "type": "string" },
"web_url": { "type": "string" } "web_url": { "type": "string" }
}, }
"additionalProperties": false
} }
{
"type": "object",
"allOf": [
{ "$ref": "basic.json" },
{
"properties": {
"before_sha": { "type": ["string", "null"] },
"tag": { "type": ["boolean"] },
"yaml_errors": { "type": ["string", "null"] },
"user": {
"anyOf": [
{ "type": ["object", "null"] },
{ "$ref": "../user/basic.json" }
]
},
"created_at": { "type": ["date", "null"] },
"updated_at": { "type": ["date", "null"] },
"started_at": { "type": ["date", "null"] },
"finished_at": { "type": ["date", "null"] },
"committed_at": { "type": ["date", "null"] },
"duration": { "type": ["number", "null"] },
"coverage": { "type": ["string", "null"] },
"detailed_status": {
"oneOf": [
{ "type": "null" },
{ "$ref": "../../../status/ci_detailed_status.json" }
]
}
}
}
]
}
...@@ -729,6 +729,14 @@ describe API::MergeRequests do ...@@ -729,6 +729,14 @@ describe API::MergeRequests do
end end
describe "GET /projects/:id/merge_requests/:merge_request_iid" do describe "GET /projects/:id/merge_requests/:merge_request_iid" do
it 'matches json schema' do
merge_request = create(:merge_request, :with_test_reports, milestone: milestone1, author: user, assignee: user, source_project: project, target_project: project, title: "Test", created_at: base_time)
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/merge_request')
end
it 'exposes known attributes' do it 'exposes known attributes' do
create(:award_emoji, :downvote, awardable: merge_request) create(:award_emoji, :downvote, awardable: merge_request)
create(:award_emoji, :upvote, awardable: merge_request) create(:award_emoji, :upvote, awardable: merge_request)
......
...@@ -399,6 +399,13 @@ describe API::Pipelines do ...@@ -399,6 +399,13 @@ describe API::Pipelines do
describe 'GET /projects/:id/pipelines/:pipeline_id' do describe 'GET /projects/:id/pipelines/:pipeline_id' do
context 'authorized user' do context 'authorized user' do
it 'exposes known attributes' do
get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/pipeline/detail')
end
it 'returns project pipelines' do it 'returns project pipelines' do
get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user)
......
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