Method: Fastlane::Actions::HockeyAction.create_and_update_build

Defined in:
fastlane/lib/fastlane/actions/hockey.rb

.create_and_update_build(api_token, ipa, options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'fastlane/lib/fastlane/actions/hockey.rb', line 64

def self.create_and_update_build(api_token, ipa, options)
  [:public_identifier, :bundle_short_version, :bundle_version].each do |key|
    UI.user_error!("To use the 'create_update' upload mechanism you need to pass the '#{key.to_sym}' option.") unless options[key]
  end
  # https://support.hockeyapp.net/discussions/problems/33355-is-uploadhockeyappnet-available-for-general-use
  # GET requests are cached on CDN, so bypass it
  options[:bypass_cdn] = true
  connection = self.connection(options)

  options.delete(:ipa)
  options.delete(:apk)
  app_id = options.delete(:public_identifier)

  ipaio = Faraday::UploadIO.new(ipa, 'application/octet-stream') if ipa && File.exist?(ipa)
  dsym = options.delete(:dsym)

  if dsym
    dsym_io = Faraday::UploadIO.new(dsym, 'application/octet-stream') if dsym && File.exist?(dsym)
  end

  # https://support.hockeyapp.net/discussions/problems/83559
  # Should not set status to "2" (downloadable) until after the app is uploaded, so allow the caller
  # to specify a different status for the `create` step
  update_status = options[:status]
  options[:status] = options[:create_status]

  response = connection.get do |req|
    req.url("/api/2/apps/#{app_id}/app_versions/new")
    req.headers['X-HockeyAppToken'] = api_token
    req.body = options
  end

  case response.status
  when 200...300
    app_version_id = response.body['id']
    UI.message("successfully created version with id #{app_version_id}")
  else
    UI.user_error!("Error trying to create app version:  #{response.status} - #{response.body}")
  end

  options[:ipa] = ipaio

  if dsym
    options[:dsym] = dsym_io
  end

  options[:status] = update_status

  connection.put do |req|
    req.options.timeout = options.delete(:timeout)
    req.url("/api/2/apps/#{app_id}/app_versions/#{app_version_id}")
    req.headers['X-HockeyAppToken'] = api_token
    req.body = options
  end
end