Commit dbfcccaf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '22367-add-pipeline-id-build' into 'master'

Expose pipeline data in builds API

Exposes pipeline data in builds API, as suggested by #22367.
The fields exposed were 'id', 'status', 'ref', and 'sha'.

Closes #22367

See merge request !6502
parents 7a779981 e80e4cb8
...@@ -14,6 +14,7 @@ v 8.13.0 (unreleased) ...@@ -14,6 +14,7 @@ v 8.13.0 (unreleased)
- Update ruby-prof to 0.16.2. !6026 (Elan Ruusamäe) - Update ruby-prof to 0.16.2. !6026 (Elan Ruusamäe)
- Add organization field to user profile - Add organization field to user profile
- Optimize GitHub importing for speed and memory - Optimize GitHub importing for speed and memory
- API: expose pipeline data in builds API (!6502, Guilherme Salazar)
v 8.12.2 (unreleased) v 8.12.2 (unreleased)
- Added University content to doc/university - Added University content to doc/university
......
...@@ -40,6 +40,12 @@ Example of response ...@@ -40,6 +40,12 @@ Example of response
"finished_at": "2015-12-24T17:54:27.895Z", "finished_at": "2015-12-24T17:54:27.895Z",
"id": 7, "id": 7,
"name": "teaspoon", "name": "teaspoon",
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
}
"ref": "master", "ref": "master",
"runner": null, "runner": null,
"stage": "test", "stage": "test",
...@@ -78,6 +84,12 @@ Example of response ...@@ -78,6 +84,12 @@ Example of response
"finished_at": "2015-12-24T17:54:24.921Z", "finished_at": "2015-12-24T17:54:24.921Z",
"id": 6, "id": 6,
"name": "spinach:other", "name": "spinach:other",
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
}
"ref": "master", "ref": "master",
"runner": null, "runner": null,
"stage": "test", "stage": "test",
...@@ -146,6 +158,12 @@ Example of response ...@@ -146,6 +158,12 @@ Example of response
"finished_at": "2016-01-11T10:14:09.526Z", "finished_at": "2016-01-11T10:14:09.526Z",
"id": 69, "id": 69,
"name": "rubocop", "name": "rubocop",
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
}
"ref": "master", "ref": "master",
"runner": null, "runner": null,
"stage": "test", "stage": "test",
...@@ -170,6 +188,12 @@ Example of response ...@@ -170,6 +188,12 @@ Example of response
"finished_at": "2015-12-24T17:54:33.913Z", "finished_at": "2015-12-24T17:54:33.913Z",
"id": 9, "id": 9,
"name": "brakeman", "name": "brakeman",
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
}
"ref": "master", "ref": "master",
"runner": null, "runner": null,
"stage": "test", "stage": "test",
...@@ -231,6 +255,12 @@ Example of response ...@@ -231,6 +255,12 @@ Example of response
"finished_at": "2015-12-24T17:54:31.198Z", "finished_at": "2015-12-24T17:54:31.198Z",
"id": 8, "id": 8,
"name": "rubocop", "name": "rubocop",
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
}
"ref": "master", "ref": "master",
"runner": null, "runner": null,
"stage": "test", "stage": "test",
......
...@@ -545,6 +545,10 @@ module API ...@@ -545,6 +545,10 @@ module API
expose :filename, :size expose :filename, :size
end end
class PipelineBasic < Grape::Entity
expose :id, :sha, :ref, :status
end
class Build < Grape::Entity class Build < Grape::Entity
expose :id, :status, :stage, :name, :ref, :tag, :coverage expose :id, :status, :stage, :name, :ref, :tag, :coverage
expose :created_at, :started_at, :finished_at expose :created_at, :started_at, :finished_at
...@@ -552,6 +556,7 @@ module API ...@@ -552,6 +556,7 @@ module API
expose :artifacts_file, using: BuildArtifactFile, if: -> (build, opts) { build.artifacts? } expose :artifacts_file, using: BuildArtifactFile, if: -> (build, opts) { build.artifacts? }
expose :commit, with: RepoCommit expose :commit, with: RepoCommit
expose :runner, with: Runner expose :runner, with: Runner
expose :pipeline, with: PipelineBasic
end end
class Trigger < Grape::Entity class Trigger < Grape::Entity
...@@ -562,8 +567,8 @@ module API ...@@ -562,8 +567,8 @@ module API
expose :key, :value expose :key, :value
end end
class Pipeline < Grape::Entity class Pipeline < PipelineBasic
expose :id, :status, :ref, :sha, :before_sha, :tag, :yaml_errors expose :before_sha, :tag, :yaml_errors
expose :user, with: Entities::UserBasic expose :user, with: Entities::UserBasic
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
......
...@@ -30,6 +30,15 @@ describe API::API, api: true do ...@@ -30,6 +30,15 @@ describe API::API, api: true do
expect(json_response.first['commit']['id']).to eq project.commit.id expect(json_response.first['commit']['id']).to eq project.commit.id
end end
it 'returns pipeline data' do
json_build = json_response.first
expect(json_build['pipeline']).not_to be_empty
expect(json_build['pipeline']['id']).to eq build.pipeline.id
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
expect(json_build['pipeline']['status']).to eq build.pipeline.status
end
context 'filter project with one scope element' do context 'filter project with one scope element' do
let(:query) { 'scope=pending' } let(:query) { 'scope=pending' }
...@@ -91,6 +100,15 @@ describe API::API, api: true do ...@@ -91,6 +100,15 @@ describe API::API, api: true do
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq 2 expect(json_response.size).to eq 2
end end
it 'returns pipeline data' do
json_build = json_response.first
expect(json_build['pipeline']).not_to be_empty
expect(json_build['pipeline']['id']).to eq build.pipeline.id
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
expect(json_build['pipeline']['status']).to eq build.pipeline.status
end
end end
context 'when pipeline has no builds' do context 'when pipeline has no builds' do
...@@ -133,6 +151,15 @@ describe API::API, api: true do ...@@ -133,6 +151,15 @@ describe API::API, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq('test') expect(json_response['name']).to eq('test')
end end
it 'returns pipeline data' do
json_build = json_response
expect(json_build['pipeline']).not_to be_empty
expect(json_build['pipeline']['id']).to eq build.pipeline.id
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
expect(json_build['pipeline']['status']).to eq build.pipeline.status
end
end end
context 'unauthorized user' do context 'unauthorized user' 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