<commit_before>require_relative 'go_cd/http'
require 'go_cd/last_green_build_fetcher'

class ButtonHandler

  def initialize(config)
    @config = config
    @fetcher = GoCD::LastGreenBuildFetcher.new(:protocol => 'https',
                                        :host => @config.server.host,
                                        :port => 443,
                                        :username => @config.auth_options[:username],
                                        :password => @config.auth_options[:password],
                                        :pipeline_name => @config.upstream_pipeline.name,
                                        :stage_name => @config.upstream_pipeline.stage)
  end

  def open
    deployment_materials = upstream_materials
    upstream_pipeline_counter = deployment_materials[@config.upstream_pipeline.name].split('/')[1]
    `say "about to deploy version from #{@config.upstream_pipeline.name} #{upstream_pipeline_counter.split('').join(' ')}"`
    @iminent_deploy_url = deploy_url(to_params(deployment_materials))
    puts "  will deploy with materials: #{deployment_materials.inspect}"
  end

  def push
    return unless @iminent_deploy_url
    Thread.new do
      begin
        @deploying = true
        puts "deploying in #{@config.countdown_in_seconds} seconds..."
        `say "Deploying in #{@config.countdown_in_seconds}"`
        (1..@config.countdown_in_seconds-1).to_a.reverse.each do |n|
          puts n
          `say #{n}`
          sleep 1
          if @cancel_requested
            cancel
            @cancel_requested = false
            @deploying = false
            return
          end
        end
        puts "deployment API request: #{@iminent_deploy_url}"
        GoCD::Http.post(@iminent_deploy_url, @config.auth_options) do |response|
          puts response.parsed_response
          @deployed = true
          `say "Go is now deploying."`
        end
      rescue => e<commit_msg>fixed cancelling since return is not valid inside a block<commit_after>require_relative 'go_cd/http'
require 'go_cd/last_green_build_fetcher'

class ButtonHandler

  def initialize(config)
    @config = config
    @fetcher = GoCD::LastGreenBuildFetcher.new(:protocol => 'https',
                                        :host => @config.server.host,
                                        :port => 443,
                                        :username => @config.auth_options[:username],
                                        :password => @config.auth_options[:password],
                                        :pipeline_name => @config.upstream_pipeline.name,
                                        :stage_name => @config.upstream_pipeline.stage)
  end

  def open
    deployment_materials = upstream_materials
    upstream_pipeline_counter = deployment_materials[@config.upstream_pipeline.name].split('/')[1]
    `say "about to deploy version from #{@config.upstream_pipeline.name} #{upstream_pipeline_counter.split('').join(' ')}"`
    @iminent_deploy_url = deploy_url(to_params(deployment_materials))
    puts "  will deploy with materials: #{deployment_materials.inspect}"
  end

  def push
    return unless @iminent_deploy_url
    Thread.new do
      begin
        @deploying = true
        puts "deploying in #{@config.countdown_in_seconds} seconds..."
        `say "Deploying in #{@config.countdown_in_seconds}"`
        (1..@config.countdown_in_seconds-1).to_a.reverse.each do |n|
          puts n
          `say #{n}`
          sleep 1
          if @cancel_requested
            cancel
            @cancel_requested = false
            @deploying = false
            break
          end
        end

        if @deploying
          puts "deployment API request: #{@iminent_deploy_url}"
          GoCD::Http.post(@iminent_deploy_url, @config.auth_options) do |response|
            puts response.parsed_response
            @deployed = true
            `say "Go is now deploying."`
          end
        else
          puts "cancelled"
        end
      rescue => e
{'fraction_non_alphanumeric': 0.09602977667493796, 'fraction_numerical': 0.0034739454094292804, 'mean_word_length': 1.9231327048585931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '771500', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1076, 'n_words': 230}