Commit 7f4236ca authored by Jeroen Muis's avatar Jeroen Muis Committed by charlie ablett

Add a test report summary resource to the GitLab pipeline API (v4)

parent 1c75f317
...@@ -207,6 +207,59 @@ Sample response: ...@@ -207,6 +207,59 @@ Sample response:
} }
``` ```
### Get a pipeline's test report summary
> Introduced in [GitLab 14.2](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65471)
NOTE:
This API route is part of the [Unit test report](../ci/unit_test_reports.md) feature.
```plaintext
GET /projects/:id/pipelines/:pipeline_id/test_report_summary
```
| Attribute | Type | Required | Description |
|------------|---------|----------|---------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding) owned by the authenticated user |
| `pipeline_id` | integer | yes | The ID of a pipeline |
Sample request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/pipelines/46/test_report_summary"
```
Sample response:
```json
{
"total": {
"time": 1904,
"count": 3363,
"success": 3351,
"failed": 0,
"skipped": 12,
"error": 0,
"suite_error": null
},
"test_suites": [
{
"name": "test",
"total_time": 1904,
"total_count": 3363,
"success_count": 3351,
"failed_count": 0,
"skipped_count": 12,
"error_count": 0,
"build_ids": [
66004
],
"suite_error": null
}
]
}
```
## Create a new pipeline ## Create a new pipeline
```plaintext ```plaintext
......
...@@ -187,6 +187,19 @@ module API ...@@ -187,6 +187,19 @@ module API
present pipeline.test_reports, with: TestReportEntity, details: true present pipeline.test_reports, with: TestReportEntity, details: true
end end
desc 'Gets the test report summary for a given pipeline' do
detail 'This feature was introduced in GitLab 14.2'
success TestReportSummaryEntity
end
params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
end
get ':id/pipelines/:pipeline_id/test_report_summary' do
authorize! :read_build, pipeline
present pipeline.test_report_summary, with: TestReportSummaryEntity
end
desc 'Deletes a pipeline' do desc 'Deletes a pipeline' do
detail 'This feature was introduced in GitLab 11.6' detail 'This feature was introduced in GitLab 11.6'
http_codes [[204, 'Pipeline was deleted'], [403, 'Forbidden']] http_codes [[204, 'Pipeline was deleted'], [403, 'Forbidden']]
......
...@@ -1150,4 +1150,43 @@ RSpec.describe API::Ci::Pipelines do ...@@ -1150,4 +1150,43 @@ RSpec.describe API::Ci::Pipelines do
end end
end end
end end
describe 'GET /projects/:id/pipelines/:pipeline_id/test_report_summary' do
subject { get api("/projects/#{project.id}/pipelines/#{pipeline.id}/test_report_summary", current_user) }
context 'authorized user' do
let(:current_user) { user }
let(:pipeline) { create(:ci_pipeline, project: project) }
context 'when pipeline does not have a test report summary' do
it 'returns an empty test report summary' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['total']['count']).to eq(0)
end
end
context 'when pipeline has a test report summary' do
let(:pipeline) { create(:ci_pipeline, :with_report_results, project: project) }
it 'returns the test report summary' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['total']['count']).to eq(2)
end
end
end
context 'unauthorized user' do
it 'does not return project pipelines' do
get api("/projects/#{project.id}/pipelines/#{pipeline.id}/test_report_summary", non_member)
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq '404 Project Not Found'
end
end
end
end end
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