diff --git a/app/controllers/info_controller.rb b/app/controllers/info_controller.rb new file mode 100644 index 000000000..01b4a6a82 --- /dev/null +++ b/app/controllers/info_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class InfoController < ActionController::API + def release + render plain: ENV.fetch('HEROKU_SLUG_COMMIT', 'unknown') + end +end diff --git a/config/routes.rb b/config/routes.rb index 264f7765f..56c04b11b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,6 +27,8 @@ root to: 'projects#index' end + get '/info/release', to: 'info#release' + post '/test/reseed', to: 'test_utilities#reseed' post '/test/enable_feature', to: 'test_utilities#enable_feature' post '/test/disable_feature', to: 'test_utilities#disable_feature' diff --git a/spec/requests/info_controller_spec.rb b/spec/requests/info_controller_spec.rb new file mode 100644 index 000000000..816fc8a06 --- /dev/null +++ b/spec/requests/info_controller_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe InfoController do + describe 'GET /info/release' do + subject(:request) { get '/info/release' } + + it 'returns the deployed commit sha as text' do + ClimateControl.modify(HEROKU_SLUG_COMMIT: 'abc123') do + request + expect(response.body).to eq('abc123') + end + end + + it 'returns unknown when the sha is unavailable' do + ClimateControl.modify(HEROKU_SLUG_COMMIT: nil) do + request + expect(response.body).to eq('unknown') + end + end + end +end