Class: Fastlane::Helper::BitbucketCloudHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb

Class Method Summary collapse

Class Method Details

.check_result(options) ⇒ Object

Raises:

  • (StandardError)


48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb', line 48

def self.check_result(options)
  result = options[:result]
  return unless result[:status] != options[:status]

  error_message = "Plugin Bitbucket finished with error code #{result[:status]} #{result[:reason_phrase]}"
  raise StandardError, error_message
end

.formatted_context_result(response) ⇒ Object



36
37
38
# File 'lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb', line 36

def self.formatted_context_result(response)
  "Status code: #{response[:status]}, reason: #{response[:reason_phrase]}"
end

.formatted_result(response) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb', line 27

def self.formatted_result(response)
  {
    status: response[:status],
    reason_phrase: response[:reason_phrase],
    body: response.body || '',
    json: parse_json(response.body) || {}
  }
end

.headers(options) ⇒ Object



21
22
23
24
25
# File 'lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb', line 21

def self.headers(options)
  api_token = Base64.strict_encode64("#{options[:username]}:#{options[:password]}")

  { 'Content-Type': 'application/json', Authorization: "Basic #{api_token}" }
end

.parse_json(value) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb', line 40

def self.parse_json(value)
  require 'json'

  JSON.parse(value)
rescue JSON::ParserError
  nil
end

.url(options) ⇒ Object

class methods that you define here become available in your action as ‘Helper::BitbucketCloudHelper.your_method`



13
14
15
16
17
18
19
# File 'lib/fastlane/plugin/bitbucket_cloud/helper/bitbucket_cloud_helper.rb', line 13

def self.url(options)
  company_host_name = options[:company_host_name]
  repository_name = options[:repository_name]
  api = options[:api]

  "https://api.bitbucket.org/2.0/repositories/#{company_host_name}/#{repository_name}/#{api}"
end