Commit 4d0bfa24 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch '24488-expose-tag-list' into 'master'

Expose the tag_list in the Jobs API

See merge request gitlab-org/gitlab!44859
parents 5a823600 fc8d0598
...@@ -228,7 +228,7 @@ module Ci ...@@ -228,7 +228,7 @@ module Ci
end end
def with_preloads def with_preloads
preload(:job_artifacts_archive, :job_artifacts, project: [:namespace]) preload(:job_artifacts_archive, :job_artifacts, :tags, project: [:namespace])
end end
end end
......
---
title: Add tag_list attribute to the JSON output for Jobs API
merge_request: 44859
author: Alon Liszt
type: added
...@@ -54,6 +54,9 @@ Example of response ...@@ -54,6 +54,9 @@ Example of response
{"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"} {"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"}
], ],
"artifacts_expire_at": "2016-01-23T17:54:27.895Z", "artifacts_expire_at": "2016-01-23T17:54:27.895Z",
"tag_list": [
"docker runner", "ubuntu18"
],
"id": 7, "id": 7,
"name": "teaspoon", "name": "teaspoon",
"pipeline": { "pipeline": {
...@@ -104,6 +107,9 @@ Example of response ...@@ -104,6 +107,9 @@ Example of response
"finished_at": "2015-12-24T17:54:24.921Z", "finished_at": "2015-12-24T17:54:24.921Z",
"duration": 0.192, "duration": 0.192,
"artifacts_expire_at": "2016-01-23T17:54:24.921Z", "artifacts_expire_at": "2016-01-23T17:54:24.921Z",
"tag_list": [
"docker runner", "win10-2004"
],
"id": 6, "id": 6,
"name": "rspec:other", "name": "rspec:other",
"pipeline": { "pipeline": {
...@@ -179,6 +185,9 @@ Example of response ...@@ -179,6 +185,9 @@ Example of response
"finished_at": "2015-12-24T17:54:24.921Z", "finished_at": "2015-12-24T17:54:24.921Z",
"duration": 0.192, "duration": 0.192,
"artifacts_expire_at": "2016-01-23T17:54:24.921Z", "artifacts_expire_at": "2016-01-23T17:54:24.921Z",
"tag_list": [
"docker runner", "ubuntu18"
],
"id": 6, "id": 6,
"name": "rspec:other", "name": "rspec:other",
"pipeline": { "pipeline": {
...@@ -239,6 +248,9 @@ Example of response ...@@ -239,6 +248,9 @@ Example of response
{"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"} {"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"}
], ],
"artifacts_expire_at": "2016-01-23T17:54:27.895Z", "artifacts_expire_at": "2016-01-23T17:54:27.895Z",
"tag_list": [
"docker runner", "ubuntu18"
],
"id": 7, "id": 7,
"name": "teaspoon", "name": "teaspoon",
"pipeline": { "pipeline": {
...@@ -399,6 +411,9 @@ Example of response ...@@ -399,6 +411,9 @@ Example of response
"finished_at": "2015-12-24T17:54:31.198Z", "finished_at": "2015-12-24T17:54:31.198Z",
"duration": 0.465, "duration": 0.465,
"artifacts_expire_at": "2016-01-23T17:54:31.198Z", "artifacts_expire_at": "2016-01-23T17:54:31.198Z",
"tag_list": [
"docker runner", "macos-10.15"
],
"id": 8, "id": 8,
"name": "rubocop", "name": "rubocop",
"pipeline": { "pipeline": {
......
...@@ -9,6 +9,9 @@ module API ...@@ -9,6 +9,9 @@ module API
expose :job_artifacts, as: :artifacts, using: ::API::Entities::Ci::JobArtifact expose :job_artifacts, as: :artifacts, using: ::API::Entities::Ci::JobArtifact
expose :runner, with: ::API::Entities::Runner expose :runner, with: ::API::Entities::Runner
expose :artifacts_expire_at expose :artifacts_expire_at
expose :tag_list do |job|
job.tags.map(&:name).sort
end
end end
end end
end end
......
...@@ -45,7 +45,7 @@ module API ...@@ -45,7 +45,7 @@ module API
builds = user_project.builds.order('id DESC') builds = user_project.builds.order('id DESC')
builds = filter_builds(builds, params[:scope]) builds = filter_builds(builds, params[:scope])
builds = builds.preload(:user, :job_artifacts_archive, :job_artifacts, :runner, pipeline: :project) builds = builds.preload(:user, :job_artifacts_archive, :job_artifacts, :runner, :tags, pipeline: :project)
present paginate(builds), with: Entities::Ci::Job present paginate(builds), with: Entities::Ci::Job
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"web_url", "web_url",
"artifacts", "artifacts",
"artifacts_expire_at", "artifacts_expire_at",
"tag_list",
"runner" "runner"
], ],
"properties": { "properties": {
...@@ -53,6 +54,9 @@ ...@@ -53,6 +54,9 @@
] ]
}, },
"artifacts_expire_at": { "type": ["null", "string"] }, "artifacts_expire_at": { "type": ["null", "string"] },
"tag_list": {
"type": "array"
},
"runner": { "runner": {
"oneOf": [ "oneOf": [
{ "type": "null" }, { "type": "null" },
......
...@@ -17,7 +17,7 @@ RSpec.describe API::Jobs do ...@@ -17,7 +17,7 @@ RSpec.describe API::Jobs do
end end
let!(:job) do let!(:job) do
create(:ci_build, :success, pipeline: pipeline, create(:ci_build, :success, :tags, pipeline: pipeline,
artifacts_expire_at: 1.day.since) artifacts_expire_at: 1.day.since)
end end
...@@ -50,6 +50,7 @@ RSpec.describe API::Jobs do ...@@ -50,6 +50,7 @@ RSpec.describe API::Jobs do
expect(json_response).not_to be_empty expect(json_response).not_to be_empty
expect(json_response.first['commit']['id']).to eq project.commit.id expect(json_response.first['commit']['id']).to eq project.commit.id
expect(Time.parse(json_response.first['artifacts_expire_at'])).to be_like_time(job.artifacts_expire_at) expect(Time.parse(json_response.first['artifacts_expire_at'])).to be_like_time(job.artifacts_expire_at)
expect(json_response.first['tag_list'].sort).to eq job.tag_list.sort
end end
context 'without artifacts and trace' do context 'without artifacts and trace' 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