Commit d4b79d57 authored by Alishan Ladhani's avatar Alishan Ladhani

Add deployment approval fields to internal API

- Add tier and required_approval_count to environment
- Add pending_approval_count to deployment
parent 7408e873
......@@ -73,3 +73,5 @@ class DeploymentEntity < Grape::Entity
request.try(:project) || options[:project]
end
end
DeploymentEntity.prepend_mod
......@@ -20,6 +20,7 @@ class EnvironmentEntity < Grape::Entity
expose :last_deployment, using: DeploymentEntity
expose :stop_action_available?, as: :has_stop_action
expose :rollout_status, if: -> (*) { can_read_deploy_board? }, using: RolloutStatusEntity
expose :tier
expose :upcoming_deployment, if: -> (environment) { environment.upcoming_deployment } do |environment, ops|
DeploymentEntity.represent(environment.upcoming_deployment,
......
# frozen_string_literal: true
module EE
module DeploymentEntity
extend ActiveSupport::Concern
prepended do
expose :pending_approval_count
end
end
end
......@@ -7,6 +7,7 @@ module EE
prepended do
expose :has_opened_alert?, if: -> (*) { can_read_alert_management_alert? }, expose_nil: false, as: :has_opened_alert
expose :required_approval_count
end
private
......
{
"type": "object",
"allOf": [
{
"$ref": "../../../../../spec/fixtures/api/schemas/deployment.json"
},
{
"properties": {
"pending_approval_count": {
"type": "integer"
}
}
}
]
}
......@@ -80,6 +80,8 @@
},
"delete_path": {
"type": "string"
}
},
"tier": { "type": "string" },
"required_approval_count": { "type": "integer" }
}
}
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe DeploymentEntity do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:environment) { create(:environment, project: project) }
let_it_be(:deployment) { create(:deployment, :blocked, project: project, environment: environment) }
let_it_be(:request) { EntityRequest.new(project: project, current_user: create(:user)) }
subject { described_class.new(deployment, request: request).as_json }
before do
stub_licensed_features(protected_environments: true)
create(:protected_environment, name: environment.name, project: project, required_approval_count: 3)
create(:deployment_approval, deployment: deployment)
end
describe '#pending_approval_count' do
it 'exposes pending_approval_count' do
expect(subject[:pending_approval_count]).to eq(2)
end
end
end
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe EnvironmentEntity do
let(:user) { create(:user) }
let(:environment) { create(:environment) }
let(:environment) { create(:environment, project: project) }
let(:project) { create(:project) }
let(:entity) do
......@@ -76,5 +76,16 @@ RSpec.describe EnvironmentEntity do
it_behaves_like 'protected environments access', developer_access: false
end
end
context 'required_approval_count' do
before do
stub_licensed_features(protected_environments: true)
create(:protected_environment, name: environment.name, project: project, required_approval_count: 2)
end
it 'exposes required_approval_count' do
expect(subject[:required_approval_count]).to eq(2)
end
end
end
end
......@@ -64,6 +64,5 @@
"items": { "$ref": "job/job.json" }
},
"status": { "type": "string" }
},
"additionalProperties": false
}
}
......@@ -35,6 +35,8 @@
"auto_stop_at": { "type": "string", "format": "date-time" },
"can_stop": { "type": "boolean" },
"has_opened_alert": { "type": "boolean" },
"tier": { "type": "string" },
"required_approval_count": { "type": "integer" },
"cluster_type": { "type": "types/nullable_string.json" },
"terminal_path": { "type": "types/nullable_string.json" },
"rollout_status": {
......
......@@ -31,7 +31,7 @@ RSpec.describe EnvironmentEntity do
end
it 'exposes core elements of environment' do
expect(subject).to include(:id, :global_id, :name, :state, :environment_path)
expect(subject).to include(:id, :global_id, :name, :state, :environment_path, :tier)
end
it 'exposes folder path' 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