<commit_before>module Spaceship
  class Client
    class UserInterface
      # Shows the UI to select a team
      # @example teams value:
      #  [{"status"=>"active",
      #   "teamId"=>"5A997XAAAA",
      #   "type"=>"Company/Organization",
      #   "extendedTeamAttributes"=>{},
      #   "teamAgent"=>{
      #       "personId"=>15534241111, 
      #       "firstName"=>"Felix", 
      #       "lastName"=>"Krause", 
      #       "email"=>"<EMAIL>", 
      #       "developerStatus"=>"active", 
      #       "teamMemberId"=>"5Y354CXAAA"},
      #   "memberships"=>
      #    [{"membershipId"=>"HJ5WHYC5CE",
      #      "membershipProductId"=>"ds1",
      #      "status"=>"active",
      #      "inDeviceResetWindow"=>false,
      #      "inRenewalWindow"=>false,
      #      "dateStart"=>"11/20/14 07:59",
      #      "dateExpire"=>"11/20/15 07:59",
      #      "platform"=>"ios",
      #      "availableDeviceSlots"=>100,
      #      "name"=>"iOS Developer Program"}],
      #   "currentTeamMember"=>
      #    {"personId"=>nil, "firstName"=>nil, "lastName"=>nil, "email"=>nil, "developerStatus"=>nil, "privileges"=>{}, "roles"=>["TEAM_ADMIN"], "teamMemberId"=>"HQR8N4GAAA"},
      #   "name"=>"Company GmbH"},
      #     {...}
      #   ]

      def select_team
        teams = client.teams

        raise "Your account is in no teams" if teams.count == 0

        team_id = (ENV['FASTLANE_TEAM_ID'] || '').strip
        team_name = (ENV['FASTLANE_TEAM_NAME'] || '').strip

        if team_id.length > 0
          # User provided a value, let's see if it's valid
          teams.each_with_index do |team, i|
            return team_id if (team['teamId'].strip == team_id)
            return team_id if (team['currentTeamMember']['teamMemberId'].to_s.strip == team_id)
          end
          puts "Couldn't find team with ID '#{team_id}'"
        end

        if team_name.length > 0
          # User provided a value, let's see if it's valid
          teams.each_with_index do |team, i|
            return team['teamId'] if (team['name'].strip == team_name)
          end
          puts "Couldn't find team with Name '#{team_name}'"
        end


        return teams[0]['teamId'] if teams.count == 1 # user is just in one team<commit_msg>Fixed issue with team selection when using the Portal value<commit_after>module Spaceship
  class Client
    class UserInterface
      # Shows the UI to select a team
      # @example teams value:
      #  [{"status"=>"active",
      #   "teamId"=>"5A997XAAAA",
      #   "type"=>"Company/Organization",
      #   "extendedTeamAttributes"=>{},
      #   "teamAgent"=>{
      #       "personId"=>15534241111, 
      #       "firstName"=>"Felix", 
      #       "lastName"=>"Krause", 
      #       "email"=>"<EMAIL>", 
      #       "developerStatus"=>"active", 
      #       "teamMemberId"=>"5Y354CXAAA"},
      #   "memberships"=>
      #    [{"membershipId"=>"HJ5WHYC5CE",
      #      "membershipProductId"=>"ds1",
      #      "status"=>"active",
      #      "inDeviceResetWindow"=>false,
      #      "inRenewalWindow"=>false,
      #      "dateStart"=>"11/20/14 07:59",
      #      "dateExpire"=>"11/20/15 07:59",
      #      "platform"=>"ios",
      #      "availableDeviceSlots"=>100,
      #      "name"=>"iOS Developer Program"}],
      #   "currentTeamMember"=>
      #    {"personId"=>nil, "firstName"=>nil, "lastName"=>nil, "email"=>nil, "developerStatus"=>nil, "privileges"=>{}, "roles"=>["TEAM_ADMIN"], "teamMemberId"=>"HQR8N4GAAA"},
      #   "name"=>"Company GmbH"},
      #     {...}
      #   ]

      def select_team
        teams = client.teams

        raise "Your account is in no teams" if teams.count == 0

        team_id = (ENV['FASTLANE_TEAM_ID'] || '').strip
        team_name = (ENV['FASTLANE_TEAM_NAME'] || '').strip

        if team_id.length > 0
          # User provided a value, let's see if it's valid
          teams.each_with_index do |team, i|
            # There are 2 different values - one from the login page one from the Dev Team Page
            return team['teamId'] if (team['teamId'].strip == team_id)
            return team['teamId'] if (team['currentTeamMember']['teamMemberId'].to_s.strip == team_id)
          end
          puts "Couldn't find team with ID '#{team_id}'"
        end

        if team_name.length > 0
          # User provided a value, let's see if it's valid
          teams.each_with_index do |team, i|
            return team['teamId'] if (team['name'].strip == team_name)
          end
          puts "Couldn't find team with Name '#{team_name}'"
        end


        return teams[0]['teamId'] if teams.count == 1 # user is just in one team
{'fraction_non_alphanumeric': 0.1611799914493373, 'fraction_numerical': 0.02244548952543822, 'mean_word_length': 2.206991089787526, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2245905', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1537, 'n_words': 322}