Sha256: ec2626e13b13801e1df426b0fa4c23b9e960c8951599fe43365cab95ea83afae
Contents?: true
Size: 1.92 KB
Versions: 23
Compression:
Stored size: 1.92 KB
Contents
require 'roo_on_rails/checks/env_specific' require 'roo_on_rails/checks/git/origin' require 'roo_on_rails/checks/heroku/token' require 'active_support/core_ext/enumerable' module RooOnRails module Checks module Heroku # Check if a corresponding app exists on Heroku (for a given environment) # # Input context # - git_repo: the name of the repository # - heroku.api_client: a connected PlatformAPI client # - app_name_stem (optional): a name override # # Output context: # - heroku.app.{env}: an app name. class AppExists < EnvSpecific ACCEPTABLE_ENV_NAMES = { 'production' => %w(prd production), 'staging' => %w(stg staging) }.freeze requires Git::Origin, Heroku::Token def intro "Checking if #{bold env} app exist..." end def call all_apps = client.app.list.map { |a| a['name'] } matches = all_apps.select { |a| candidates.include?(a) } if matches.empty? fail! "no apps with matching names detected" end if matches.many? list = candidates.map { |c| bold c }.join(', ') final_fail! "multiple matching apps detected: #{list}" end context.heroku.app![env] = matches.first pass "found app #{bold matches.first}" end private def name_stem context.app_name_stem || context.git_repo.delete('.') end def env_suffixes ACCEPTABLE_ENV_NAMES.fetch(env, [env]) end def candidates [ ['deliveroo', 'roo', nil], [name_stem], env_suffixes, ].tap { |a| a.replace a.first.product(*a[1..-1]) }.map { |c| c.compact.join('-') } end def client context.heroku.api_client end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems