def build_trains(app_id, testing_type, tries = 5, platform: nil)
      raise "app_id is required" unless app_id
      url = "ra/apps/#{app_id}/trains/?testingType=#{testing_type}"
      url += "&platform=#{platform}" unless platform.nil?
      r = request(:get, url)
      return parse_response(r, 'data')
    rescue Spaceship::Client::UnexpectedResponse => ex
      # Build trains fail randomly very often
      # we need to catch those errors and retry
      # https://github.com/fastlane/fastlane/issues/6419
      retry_error_messages = [
        "ITC.response.error.OPERATION_FAILED",
        "Internal Server Error",
        "Service Unavailable"
      ].freeze

      if retry_error_messages.any? { |message| ex.to_s.include?(message) }
        tries -= 1
        if tries > 0
          logger.warn("Received temporary server error from App Store Connect. Retrying the request...")
          sleep(3) unless Object.const_defined?("SpecHelper")
          retry
        end
      end

      raise Spaceship::Client::UnexpectedResponse, "Temporary App Store Connect error: #{ex}"
    end
def build_trains(app_id, testing_type, tries = 5, platform: nil)
      raise "app_id is required" unless app_id
      url = "ra/apps/#{app_id}/trains/?testingType=#{testing_type}"
      url += "&platform=#{platform}" unless platform.nil?
      r = request(:get, url)
      return parse_response(r, 'data')
    rescue Spaceship::Client::UnexpectedResponse => ex
      # Build trains fail randomly very often
      # we need to catch those errors and retry
      # https://github.com/fastlane/fastlane/issues/6419
      retry_error_messages = [
        "ITC.response.error.OPERATION_FAILED",
        "Internal Server Error",
        "Service Unavailable"
      ].freeze

      if retry_error_messages.any? { |message| ex.to_s.include?(message) }
        tries -= 1
        if tries > 0
          logger.warn("Received temporary server error from App Store Connect. Retrying the request...")
          sleep(3) unless Object.const_defined?("SpecHelper")
          retry
        end
      end

      raise Spaceship::Client::UnexpectedResponse, "Temporary App Store Connect error: #{ex}"
    end
@!group Build Trains

 rubocop:disable Metrics/BlockNesting
 @param (testing_type) internal or external