summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/unreleased/add-artifacts_expire_at-to-api.yml5
-rw-r--r--doc/api/jobs.md5
-rw-r--r--lib/api/entities.rb1
-rw-r--r--spec/requests/api/jobs_spec.rb8
4 files changed, 18 insertions, 1 deletions
diff --git a/changelogs/unreleased/add-artifacts_expire_at-to-api.yml b/changelogs/unreleased/add-artifacts_expire_at-to-api.yml
new file mode 100644
index 00000000000..7fe0d8b5720
--- /dev/null
+++ b/changelogs/unreleased/add-artifacts_expire_at-to-api.yml
@@ -0,0 +1,5 @@
+---
+title: Expose artifacts_expire_at field for job entity in api
+merge_request: 18872
+author: Semyon Pupkov
+type: added
diff --git a/doc/api/jobs.md b/doc/api/jobs.md
index e4e48edd9a7..0fbfc7cf0fd 100644
--- a/doc/api/jobs.md
+++ b/doc/api/jobs.md
@@ -38,6 +38,7 @@ Example of response
"size": 1000
},
"finished_at": "2015-12-24T17:54:27.895Z",
+ "artifacts_expire_at": "2016-01-23T17:54:27.895Z"
"id": 7,
"name": "teaspoon",
"pipeline": {
@@ -81,6 +82,7 @@ Example of response
"created_at": "2015-12-24T15:51:21.727Z",
"artifacts_file": null,
"finished_at": "2015-12-24T17:54:24.921Z",
+ "artifacts_expire_at": "2016-01-23T17:54:24.921Z",
"id": 6,
"name": "rspec:other",
"pipeline": {
@@ -152,6 +154,7 @@ Example of response
"size": 1000
},
"finished_at": "2015-12-24T17:54:27.895Z",
+ "artifacts_expire_at": "2016-01-23T17:54:27.895Z"
"id": 7,
"name": "teaspoon",
"pipeline": {
@@ -195,6 +198,7 @@ Example of response
"created_at": "2015-12-24T15:51:21.727Z",
"artifacts_file": null,
"finished_at": "2015-12-24T17:54:24.921Z",
+ "artifacts_expire_at": "2016-01-23T17:54:24.921Z"
"id": 6,
"name": "rspec:other",
"pipeline": {
@@ -261,6 +265,7 @@ Example of response
"created_at": "2015-12-24T15:51:21.880Z",
"artifacts_file": null,
"finished_at": "2015-12-24T17:54:31.198Z",
+ "artifacts_expire_at": "2016-01-23T17:54:31.198Z",
"id": 8,
"name": "rubocop",
"pipeline": {
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 174c5af91d5..3e615f7ac05 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1020,6 +1020,7 @@ module API
class Job < JobBasic
expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? }
expose :runner, with: Runner
+ expose :artifacts_expire_at
end
class JobBasicWithProject < JobBasic
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb
index 0a2963452e4..45082e644ca 100644
--- a/spec/requests/api/jobs_spec.rb
+++ b/spec/requests/api/jobs_spec.rb
@@ -13,7 +13,10 @@ describe API::Jobs do
ref: project.default_branch)
end
- let!(:job) { create(:ci_build, :success, pipeline: pipeline) }
+ let!(:job) do
+ create(:ci_build, :success, pipeline: pipeline,
+ artifacts_expire_at: 1.day.since)
+ end
let(:user) { create(:user) }
let(:api_user) { user }
@@ -43,6 +46,7 @@ describe API::Jobs do
it 'returns correct values' do
expect(json_response).not_to be_empty
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)
end
it 'returns pipeline data' do
@@ -128,6 +132,7 @@ describe API::Jobs do
it 'returns correct values' do
expect(json_response).not_to be_empty
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)
end
it 'returns pipeline data' do
@@ -201,6 +206,7 @@ describe API::Jobs do
expect(Time.parse(json_response['created_at'])).to be_like_time(job.created_at)
expect(Time.parse(json_response['started_at'])).to be_like_time(job.started_at)
expect(Time.parse(json_response['finished_at'])).to be_like_time(job.finished_at)
+ expect(Time.parse(json_response['artifacts_expire_at'])).to be_like_time(job.artifacts_expire_at)
expect(json_response['duration']).to eq(job.duration)
end