<commit_before>require 'codeland/starter'
require 'platform-api'

module Codeland
  module Starter
    module Integrations
      class Heroku
        attr_reader :app

        def initialize
          token = if Configuration['heroku']
                    Configuration['heroku']['oauth_token']
                  else
                    yaml = Starter.config.yaml
                    message = "Missing heroku key in #{yaml}"
                    missing_config(message)
                  end
          @app = {}
          @success = false
          @api = PlatformAPI.connect_oauth(token)
        end

        def perform
          create
          output
        end

        def create
          begin
            @app = create_app(Starter.name)
            @success = true
          rescue Excon::Errors::Unauthorized
            yaml = Starter.config.yaml
            missing_config("Please verify the Heroku oauth key in #{yaml}")
          rescue Excon::Errors::UnprocessableEntity
            @app = create_random_app
            @success = true
          ensure
            add_git_remote
          end
        end

        def output
          if success?
            puts <<-MESSAGE.gsub(/^\s{12}/, '')
            Heroku created with
            URL: #{app['web_url']}
            Git remote: #{app['git_url']}
            MESSAGE
          else
            puts 'heroku failed'
            puts app
          end
        end

        private

        attr_reader :api

        def create_random_app
          puts 'Heroku app already in use. Using a random name'
          create_app
        end

        def create_app(app_name = nil)
          api.app.create({
            :name   => app_name,
            :region => 'us',
            :stack  => 'cedar'
          })
        end

        def success?
          @success
        end

        def missing_config(message)
          raise MissingYAML, message
        end

        def add_git_remote
          system("git remote add heroku #{app['git_url']}") if success?
        end
      end
    end
  end
end<commit_msg>Change Heroku stack to cedar-14<commit_after>require 'codeland/starter'
require 'platform-api'

module Codeland
  module Starter
    module Integrations
      class Heroku
        attr_reader :app

        def initialize
          token = if Configuration['heroku']
                    Configuration['heroku']['oauth_token']
                  else
                    yaml = Starter.config.yaml
                    message = "Missing heroku key in #{yaml}"
                    missing_config(message)
                  end
          @app = {}
          @success = false
          @api = PlatformAPI.connect_oauth(token)
        end

        def perform
          create
          output
        end

        def create
          begin
            @app = create_app(Starter.name)
            @success = true
          rescue Excon::Errors::Unauthorized
            yaml = Starter.config.yaml
            missing_config("Please verify the Heroku oauth key in #{yaml}")
          rescue Excon::Errors::UnprocessableEntity
            @app = create_random_app
            @success = true
          ensure
            add_git_remote
          end
        end

        def output
          if success?
            puts <<-MESSAGE.gsub(/^\s{12}/, '')
            Heroku created with
            URL: #{app['web_url']}
            Git remote: #{app['git_url']}
            MESSAGE
          else
            puts 'heroku failed'
            puts app
          end
        end

        private

        attr_reader :api

        def create_random_app
          puts 'Heroku app already in use. Using a random name'
          create_app
        end

        def create_app(app_name = nil)
          api.app.create({
            :name   => app_name,
            :region => 'us',
            :stack  => 'cedar-14'
          })
        end

        def success?
          @success
        end

        def missing_config(message)
          raise MissingYAML, message
        end

        def add_git_remote
          system("git remote add heroku #{app['git_url']}") if success?
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07352590116973025, 'fraction_numerical': 0.0019097636667462401, 'mean_word_length': 1.2784121805328983, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3509699', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1058, 'n_words': 295}