Skip to content

Commit

Permalink
feat(): add review-app support for branches
Browse files Browse the repository at this point in the history
  • Loading branch information
rieg-ec committed Jan 10, 2022
1 parent 38c1df9 commit d6ac825
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
12 changes: 11 additions & 1 deletion lib/heroku/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ def review_app?
private

def heroku_pipeline_stage
return ENV.fetch('HEROKU_APP_NAME')[/pr-(\d*)/] if review_app?
return branch || pull_request if review_app?

dev_or_test = Rails.env.development? || Rails.env.test?
dev_or_test ? '' : ENV.fetch('HEROKU_APP_NAME')[/staging|production/]
rescue KeyError
raise $!, enable_dyno_metadata_message($!), $!.backtrace
end

def branch
app_name = ENV.fetch('HEROKU_APP_NAME')

return "br-#{app_name.split('-br-')[1]}" if app_name.include? '-br-'
end

def pull_request
ENV.fetch('HEROKU_APP_NAME')[/pr-(\d*)/]
end

def enable_dyno_metadata_message(exception)
<<-USAGE
#{exception.message}
Expand Down
32 changes: 24 additions & 8 deletions spec/heroku-stage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,35 @@
end

describe 'on review app' do
before(:each) do
allow(ENV).to receive(:[]).with("HEROKU_PARENT_APP_NAME").and_return("myapp-staging")
allow(ENV).to receive(:fetch).with('HEROKU_APP_NAME').and_return('myapp-staging-pr-766')
end

it 'get the correct stage' do
expect(Heroku.stage).to eq('pr-766')
end

describe '#review_app?' do
it 'returns true' do
expect(Heroku.review_app?).to be(true)
end
end

describe '#heroku_pipeline_stage' do
context 'when app is created from pull request' do
before(:each) do
allow(ENV).to receive(:[]).with("HEROKU_PARENT_APP_NAME").and_return("myapp-staging")
allow(ENV).to receive(:fetch).with('HEROKU_APP_NAME').and_return('myapp-staging-pr-766')
end

it 'get the correct stage' do
expect(Heroku.stage).to eq('pr-766')
end
end

context 'when app is created from branch' do
before(:each) do
allow(ENV).to receive(:[]).with("HEROKU_PARENT_APP_NAME").and_return("myapp-staging")
allow(ENV).to receive(:fetch).with('HEROKU_APP_NAME').and_return('myapp-staging-br-new-feature')
end

it 'get the correct stage' do
expect(Heroku.stage).to eq('br-new-feature')
end
end
end
end
end

0 comments on commit d6ac825

Please sign in to comment.