diff --git a/doc/api/environments.md b/doc/api/environments.md index ed638a7853bc9708f923a269c89971f8389fd95f..1f76d4c1c787ac4d4dfaa238e0ae402b3a571e4b 100644 --- a/doc/api/environments.md +++ b/doc/api/environments.md @@ -45,7 +45,8 @@ Example response: "created_at": "2019-05-25T18:55:13.252Z", "updated_at": "2019-05-27T18:55:13.252Z", "enable_advanced_logs_querying": false, - "logs_api_path": "/project/-/logs/k8s.json?environment_name=review%2Ffix-foo" + "logs_api_path": "/project/-/logs/k8s.json?environment_name=review%2Ffix-foo", + "auto_stop_at": "2019-06-03T18:55:13.252Z" } ] ``` @@ -79,6 +80,7 @@ Example of response "updated_at": "2019-05-27T18:55:13.252Z", "enable_advanced_logs_querying": false, "logs_api_path": "/project/-/logs/k8s.json?environment_name=review%2Ffix-foo", + "auto_stop_at": "2019-06-03T18:55:13.252Z", "last_deployment": { "id": 100, "iid": 34, diff --git a/lib/api/entities/environment.rb b/lib/api/entities/environment.rb index dc9911d5acb4b131495beb74ec58afb4b8c9b8e2..92a87f92d6b6ae86a7ffdc08ad5c41d74871180e 100644 --- a/lib/api/entities/environment.rb +++ b/lib/api/entities/environment.rb @@ -9,6 +9,7 @@ class Environment < Entities::EnvironmentBasic expose :project, using: Entities::BasicProjectDetails expose :last_deployment, using: Entities::Deployment, if: { last_deployment: true } expose :state, documentation: { type: 'string', example: 'available' } + expose :auto_stop_at, documentation: { type: 'dateTime', example: '2019-05-25T18:55:13.252Z' } end end end diff --git a/spec/fixtures/api/schemas/public_api/v4/environment.json b/spec/fixtures/api/schemas/public_api/v4/environment.json index 21888d88598eefa097330ee7ec738a6c8342f3d5..a7455be9251df1e396b76ef5f92e427e5ea720f2 100644 --- a/spec/fixtures/api/schemas/public_api/v4/environment.json +++ b/spec/fixtures/api/schemas/public_api/v4/environment.json @@ -11,21 +11,56 @@ "updated_at" ], "properties": { - "id": { "type": "integer" }, - "name": { "type": "string" }, - "slug": { "type": "string" }, - "tier": { "type": "string" }, - "external_url": { "$ref": "../../types/nullable_string.json" }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "slug": { + "type": "string" + }, + "tier": { + "type": "string" + }, + "external_url": { + "$ref": "../../types/nullable_string.json" + }, "last_deployment": { "oneOf": [ - { "type": "null" }, - { "$ref": "deployment.json" } + { + "type": "null" + }, + { + "$ref": "deployment.json" + } ] }, - "state": { "type": "string" }, - "created_at": { "type": "string", "format": "date-time" }, - "updated_at": { "type": "string", "format": "date-time" }, - "project": { "$ref": "project.json" } + "state": { + "type": "string" + }, + "auto_stop_at": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "project": { + "$ref": "project.json" + } }, "additionalProperties": false } diff --git a/spec/requests/api/environments_spec.rb b/spec/requests/api/environments_spec.rb index e747fa528b654dbc07ac114d2dca6740ac75ba29..23ebe8d4e7c593ee6a10de7e29596916126453c4 100644 --- a/spec/requests/api/environments_spec.rb +++ b/spec/requests/api/environments_spec.rb @@ -418,6 +418,34 @@ expect(response).to have_gitlab_http_status(:ok) end end + + context "when auto_stop_at is present" do + before do + environment.update!(auto_stop_at: Time.current) + end + + it "returns the expected response" do + get api("/projects/#{project.id}/environments/#{environment.id}", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/environment') + expect(json_response['auto_stop_at']).to be_present + end + end + + context "when auto_stop_at is not present" do + before do + environment.update!(auto_stop_at: nil) + end + + it "returns the expected response" do + get api("/projects/#{project.id}/environments/#{environment.id}", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/environment') + expect(json_response['auto_stop_at']).to be_nil + end + end end context 'as non member' do