Class: BotBuilder

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bot_builder.rb

Instance Method Summary collapse

Instance Method Details

#create_bot(short_name, long_name, branch, scm_url, project_path, scheme_name, devices = []) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bot_builder.rb', line 26

def create_bot(short_name, long_name, branch, scm_url, project_path, scheme_name, devices = [])
  device_guids = find_guids_for_devices(devices)
  if (device_guids.count != devices.count)
    puts "Some of the following devices could not be found on the server: #{devices}"
    exit 1
  end

  scm_guid = find_guid_for_scm_url(scm_url)
  if (scm_guid.nil? || scm_guid.empty?)
    puts "Could not find repository on the server #{scm_url}"
    exit 1
  end

  # Create the bot
  buildSchemeKey = (project_path =~ /xcworkspace/) ? :buildWorkspacePath : :buildProjectPath

  service_requests = [
      service_request('createBotWithProperties:', [
          {
              shortName: short_name,
              longName: long_name,
              extendedAttributes: {
                  scmInfo: {
                      "/" => {
                          scmBranch: branch,
                      }
                  },
                  scmInfoGUIDMap: {
                      "/" => scm_guid
                  },
                  buildSchemeKey => project_path,
                  buildSchemeName: scheme_name,
                  pollForSCMChanges: false,
                  buildOnTrigger: false,
                  buildFromClean: true,
                  integratePerformsAnalyze: true,
                  integratePerformsTest: true,
                  integratePerformsArchive: false,
                  deviceSpecification: "specificDevices",
                  deviceInfo: device_guids
              },
              notifyCommitterOnSuccess: false,
              notifyCommitterOnFailure: false,
              type: "com.apple.entity.Bot"
          }


      ])
  ]
  bot_info = batch_service_request(service_requests)
  bot_guid = bot_info['responses'][0]['response']['guid']
  puts "BOT Created #{bot_guid} #{short_name}"

  # Start the bot
  start_bot bot_guid

  bot_guid
end

#delete_bot(guid) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bot_builder.rb', line 14

def delete_bot(guid)
  success = false
  service_requests = [ service_request('deleteBotWithGUID:', [guid]) ]
  delete_info = batch_service_request(service_requests)
  if (delete_info['responses'][0]['responseStatus'] == 'succeeded')
    puts "BOT Deleted #{guid}"
    success = true
  else
    puts "Error deleting BOT #{guid}"
  end
end

#devicesObject



122
123
124
125
126
127
# File 'lib/bot_builder.rb', line 122

def devices
  device_info = get_device_info
  device_info.each do |device|
    puts device_string_for_device(device)
  end
end

#start_bot(bot_guid) ⇒ Object



85
86
87
88
89
# File 'lib/bot_builder.rb', line 85

def start_bot(bot_guid)
  service_requests = [ service_request('startBotRunForBotGUID:', [bot_guid]) ]
  bot_start_info = batch_service_request(service_requests)
  puts "BOT Started #{bot_guid}"
end

#statusObject



116
117
118
119
120
# File 'lib/bot_builder.rb', line 116

def status
  status_of_all_bots.values.each do |bot|
    puts "#{bot.status_url} #{bot.latest_run_status} #{bot.latest_run_sub_status}"
  end
end

#status_of_all_botsObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/bot_builder.rb', line 91

def status_of_all_bots
  # After immediately creating: latest_run_status "" run_sub_status ""
  # While running: latest_run_status "running" run_sub_status ""
  # After completion: latest_run_status "completed" run_sub_status "build-failed|build-errors|test-failures|warnings|analysis-issues|succeeded"
  service_requests = [ service_request('query:', [
      {
          fields: ['guid','tinyID','latestRunStatus','latestRunSubStatus'],
          entityTypes: ["com.apple.entity.Bot"]
      }
  ], 'SearchService') ]
  status_info = batch_service_request(service_requests)
  results =  status_info['responses'][0]['response']['results']
  statuses = {}
  results.each do |result|
    bot = OpenStruct.new result['entity']
    bot.status_url = "http://#{BotConfig.instance.xcode_server_hostname}/xcode/bots/#{bot.tinyID}"
    bot.latest_run_status = (bot.latestRunStatus.nil? || bot.latestRunStatus.empty?) ? :unknown : bot.latestRunStatus.to_sym
    bot.latest_run_sub_status = (bot.latestRunSubStatus.nil? || bot.latestRunSubStatus.empty?) ? :unknown : bot.latestRunSubStatus.to_sym
    bot.short_name = bot.tinyID
    bot.short_name_without_version = bot.short_name.sub(/_v\d*$/, '_v')
    statuses[bot.short_name_without_version] = bot
  end
  statuses
end