<commit_before>require 'spaceship'

module WatchBuild
  class Runner
    attr_accessor :spaceship

    # Uses the spaceship to create or download a provisioning profile
    # returns the path the newly created provisioning profile (in /tmp usually)
    def run
      FastlaneCore::PrintTable.print_values(config: WatchBuild.config,
                                         hide_keys: [],
                                             title: "Summary for WatchBuild #{WatchBuild::VERSION}")

      Helper.log.info "Starting login with user '#{WatchBuild.config[:username]}'"
      Spaceship::Tunes.login(WatchBuild.config[:username], nil)
      Helper.log.info "Successfully logged in"

      start = Time.now
      build = wait_for_build
      minutes = ((Time.now - start) / 60).round
      notification(build, minutes)
    end

    def wait_for_build
      raise "Could not find app with app identiifer #{WatchBuild.config[:app_identifier]}".red unless app

      loop do
        build = find_build
        return build if build.processing == false

        Helper.log.info "Waiting iTunes Connect processing for build #{build.train_version} (#{build.build_version})... this might take a while..."
        sleep 30
      end
      nil
    end

    def notification(build, minutes)<commit_msg>Improved handling of server errors<commit_after>require 'spaceship'

module WatchBuild
  class Runner
    attr_accessor :spaceship

    # Uses the spaceship to create or download a provisioning profile
    # returns the path the newly created provisioning profile (in /tmp usually)
    def run
      FastlaneCore::PrintTable.print_values(config: WatchBuild.config,
                                         hide_keys: [],
                                             title: "Summary for WatchBuild #{WatchBuild::VERSION}")

      Helper.log.info "Starting login with user '#{WatchBuild.config[:username]}'"
      Spaceship::Tunes.login(WatchBuild.config[:username], nil)
      Helper.log.info "Successfully logged in"

      start = Time.now
      build = wait_for_build
      minutes = ((Time.now - start) / 60).round
      notification(build, minutes)
    end

    def wait_for_build
      raise "Could not find app with app identiifer #{WatchBuild.config[:app_identifier]}".red unless app

      loop do
        begin
          build = find_build
          return build if build.processing == false
          Helper.log.info "Waiting iTunes Connect processing for build #{build.train_version} (#{build.build_version})... this might take a while..."
        rescue => ex
          Helper.log.error ex
          Helper.log.info "Something failed... trying again to recover"
        end
        sleep 30
      end
      nil
    end

    def notification(build, minutes)
{'fraction_non_alphanumeric': 0.08366533864541832, 'fraction_numerical': 0.002897500905469033, 'mean_word_length': 2.3478787878787877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4086941', 'n_tokens_mistral': 725, 'n_tokens_neox': 688, 'n_words': 228}